admin-fe/src/views/users/index.vue

426 lines
14 KiB
Vue
Raw Normal View History

2019-02-22 18:06:48 +00:00
<template>
<div class="users-container">
2019-05-05 21:51:52 +00:00
<h1>
{{ $t('users.users') }}
<span class="user-count">({{ normalizedUsersCount }})</span>
</h1>
2019-06-11 15:13:48 +00:00
<div class="filter-container">
2019-03-29 14:25:53 +00:00
<users-filter/>
2019-05-21 19:24:48 +00:00
<el-input :placeholder="$t('users.search')" v-model="search" class="search" @input="handleDebounceSearchInput"/>
2019-03-06 19:44:37 +00:00
</div>
2019-06-11 15:13:48 +00:00
<div class="actions-container">
2019-09-23 19:00:28 +00:00
<el-button class="actions-button create-account" @click="createAccountDialogOpen = true">
2019-06-11 15:13:48 +00:00
<span>
2019-09-23 19:00:28 +00:00
<i class="el-icon-plus"/>
2019-06-11 15:13:48 +00:00
{{ $t('users.createAccount') }}
</span>
</el-button>
<multiple-users-menu
:selected-users="selectedUsers"
@apply-action="clearSelection"/>
</div>
<new-account-dialog
2019-09-23 19:00:28 +00:00
:dialog-form-visible="createAccountDialogOpen"
2019-06-11 15:13:48 +00:00
@createNewAccount="createNewAccount"
2019-09-23 19:00:28 +00:00
@closeWindow="createAccountDialogOpen = false"/>
<el-table
v-loading="loading"
ref="usersTable"
:data="users"
row-key="id"
style="width: 100%"
@selection-change="handleSelectionChange">
<el-table-column
v-if="isDesktop"
type="selection"
reserve-selection
width="44"
align="center"/>
2019-03-22 21:27:31 +00:00
<el-table-column :min-width="width" :label="$t('users.id')" prop="id" />
<el-table-column :label="$t('users.name')" prop="nickname">
2019-03-22 21:18:57 +00:00
<template slot-scope="scope">
<router-link :to="{ name: 'UsersShow', params: { id: scope.row.id }}">{{ scope.row.nickname }}</router-link>
2019-03-22 21:18:57 +00:00
<el-tag v-if="isDesktop" type="info" size="mini">
2019-03-22 21:27:31 +00:00
<span>{{ scope.row.local ? $t('users.local') : $t('users.external') }}</span>
2019-03-22 21:18:57 +00:00
</el-tag>
</template>
</el-table-column>
2019-03-22 21:27:31 +00:00
<el-table-column :min-width="width" :label="$t('users.status')">
2019-02-26 19:50:25 +00:00
<template slot-scope="scope">
2019-03-06 19:52:18 +00:00
<el-tag :type="scope.row.deactivated ? 'danger' : 'success'">
2019-03-22 21:27:31 +00:00
<span v-if="isDesktop">{{ scope.row.deactivated ? $t('users.deactivated') : $t('users.active') }}</span>
2019-03-06 19:52:18 +00:00
<i v-else :class="activationIcon(scope.row.deactivated)"/>
</el-tag>
2019-03-22 21:18:57 +00:00
<el-tag v-if="scope.row.roles.admin">
2019-03-22 21:27:31 +00:00
<span>{{ isDesktop ? $t('users.admin') : getFirstLetter($t('users.admin')) }}</span>
2019-03-22 21:18:57 +00:00
</el-tag>
<el-tag v-if="scope.row.roles.moderator">
2019-03-22 21:27:31 +00:00
<span>{{ isDesktop ? $t('users.moderator') : getFirstLetter($t('users.moderator')) }}</span>
2019-03-22 21:18:57 +00:00
</el-tag>
2019-02-26 19:50:25 +00:00
</template>
</el-table-column>
2019-03-22 21:27:31 +00:00
<el-table-column :label="$t('users.actions')" fixed="right">
2019-02-26 19:50:25 +00:00
<template slot-scope="scope">
2019-05-06 15:49:03 +00:00
<el-dropdown size="small" trigger="click">
2019-03-22 21:18:57 +00:00
<span class="el-dropdown-link">
2019-03-22 21:27:31 +00:00
{{ $t('users.moderation') }}
2019-03-22 21:18:57 +00:00
<i v-if="isDesktop" class="el-icon-arrow-down el-icon--right"/>
</span>
<el-dropdown-menu slot="dropdown">
2019-03-29 14:25:53 +00:00
<el-dropdown-item
v-if="showAdminAction(scope.row)"
@click.native="toggleUserRight(scope.row, 'admin')">
2019-03-22 21:27:31 +00:00
{{ scope.row.roles.admin ? $t('users.revokeAdmin') : $t('users.grantAdmin') }}
2019-03-22 21:18:57 +00:00
</el-dropdown-item>
2019-03-29 14:25:53 +00:00
<el-dropdown-item
v-if="showAdminAction(scope.row)"
@click.native="toggleUserRight(scope.row, 'moderator')">
2019-03-22 21:27:31 +00:00
{{ scope.row.roles.moderator ? $t('users.revokeModerator') : $t('users.grantModerator') }}
2019-03-22 21:18:57 +00:00
</el-dropdown-item>
2019-03-29 14:25:53 +00:00
<el-dropdown-item
v-if="showDeactivatedButton(scope.row.id)"
:divided="showAdminAction(scope.row)"
@click.native="handleDeactivation(scope.row)">
2019-03-22 21:27:31 +00:00
{{ scope.row.deactivated ? $t('users.activateAccount') : $t('users.deactivateAccount') }}
2019-03-22 21:18:57 +00:00
</el-dropdown-item>
2019-03-29 14:25:53 +00:00
<el-dropdown-item
v-if="showDeactivatedButton(scope.row.id)"
@click.native="handleDeletion(scope.row)">
2019-03-22 21:27:31 +00:00
{{ $t('users.deleteAccount') }}
2019-03-22 21:18:57 +00:00
</el-dropdown-item>
2019-03-29 14:25:53 +00:00
<el-dropdown-item
:divided="showAdminAction(scope.row)"
:class="{ 'active-tag': scope.row.tags.includes('force_nsfw') }"
@click.native="toggleTag(scope.row, 'force_nsfw')">
2019-03-22 21:27:31 +00:00
{{ $t('users.forceNsfw') }}
2019-03-29 14:25:53 +00:00
<i v-if="scope.row.tags.includes('force_nsfw')" class="el-icon-check"/>
2019-03-22 21:18:57 +00:00
</el-dropdown-item>
2019-03-29 14:25:53 +00:00
<el-dropdown-item
:class="{ 'active-tag': scope.row.tags.includes('strip_media') }"
@click.native="toggleTag(scope.row, 'strip_media')">
2019-03-22 21:27:31 +00:00
{{ $t('users.stripMedia') }}
2019-03-29 14:25:53 +00:00
<i v-if="scope.row.tags.includes('strip_media')" class="el-icon-check"/>
2019-03-22 21:18:57 +00:00
</el-dropdown-item>
2019-03-29 14:25:53 +00:00
<el-dropdown-item
:class="{ 'active-tag': scope.row.tags.includes('force_unlisted') }"
@click.native="toggleTag(scope.row, 'force_unlisted')">
2019-03-22 21:27:31 +00:00
{{ $t('users.forceUnlisted') }}
2019-03-29 14:25:53 +00:00
<i v-if="scope.row.tags.includes('force_unlisted')" class="el-icon-check"/>
2019-03-22 21:18:57 +00:00
</el-dropdown-item>
2019-03-29 14:25:53 +00:00
<el-dropdown-item
:class="{ 'active-tag': scope.row.tags.includes('sandbox') }"
@click.native="toggleTag(scope.row, 'sandbox')">
2019-03-22 21:27:31 +00:00
{{ $t('users.sandbox') }}
2019-03-29 14:25:53 +00:00
<i v-if="scope.row.tags.includes('sandbox')" class="el-icon-check"/>
2019-03-22 21:18:57 +00:00
</el-dropdown-item>
2019-03-29 14:25:53 +00:00
<el-dropdown-item
v-if="scope.row.local"
:class="{ 'active-tag': scope.row.tags.includes('disable_remote_subscription') }"
@click.native="toggleTag(scope.row, 'disable_remote_subscription')">
2019-03-22 21:27:31 +00:00
{{ $t('users.disableRemoteSubscription') }}
2019-03-29 14:25:53 +00:00
<i v-if="scope.row.tags.includes('disable_remote_subscription')" class="el-icon-check"/>
2019-03-22 21:18:57 +00:00
</el-dropdown-item>
2019-03-29 14:25:53 +00:00
<el-dropdown-item
v-if="scope.row.local"
:class="{ 'active-tag': scope.row.tags.includes('disable_any_subscription') }"
@click.native="toggleTag(scope.row, 'disable_any_subscription')">
2019-03-22 21:27:31 +00:00
{{ $t('users.disableAnySubscription') }}
2019-03-29 14:25:53 +00:00
<i v-if="scope.row.tags.includes('disable_any_subscription')" class="el-icon-check"/>
2019-03-22 21:18:57 +00:00
</el-dropdown-item>
2019-09-23 19:00:28 +00:00
<el-dropdown-item
v-if="scope.row.local"
divided
@click.native="getPasswordResetToken(scope.row.nickname)">
{{ $t('users.getPasswordResetToken') }}
</el-dropdown-item>
<el-dropdown-item
v-if="scope.row.local"
@click.native="requirePasswordReset(scope.row.nickname)">
{{ $t('users.requirePasswordReset') }}
</el-dropdown-item>
2019-03-22 21:18:57 +00:00
</el-dropdown-menu>
</el-dropdown>
2019-02-24 22:31:05 +00:00
</template>
</el-table-column>
</el-table>
2019-09-23 19:00:28 +00:00
<el-dialog
v-loading="loading"
:visible.sync="resetPasswordDialogOpen"
:title="$t('users.passwordResetTokenCreated')"
custom-class="password-reset-token-dialog"
@close="closeResetPasswordDialog">
<div>
<p class="password-reset-token">Password reset token was generated: {{ passwordResetToken }}</p>
<p>You can also use this link to reset password:
<a :href="passwordResetLink" target="_blank" class="reset-password-link">{{ passwordResetLink }}</a>
</p>
</div>
</el-dialog>
<div v-if="users.length === 0" class="no-users-message">
<p>There are no users to display</p>
</div>
2019-02-27 22:13:20 +00:00
<div v-if="!loading" class="pagination">
<el-pagination
:total="usersCount"
2019-03-03 20:46:14 +00:00
:current-page="currentPage"
:page-size="pageSize"
2019-02-27 22:13:20 +00:00
background
layout="prev, pager, next"
2019-03-01 17:32:03 +00:00
@current-change="handlePageChange"
/>
2019-02-27 22:13:20 +00:00
</div>
2019-02-22 18:06:48 +00:00
</div>
</template>
<script>
2019-03-01 17:32:03 +00:00
import debounce from 'lodash.debounce'
2019-05-05 21:51:52 +00:00
import numeral from 'numeral'
2019-03-29 14:25:53 +00:00
import UsersFilter from './components/UsersFilter'
2019-06-11 15:13:48 +00:00
import MultipleUsersMenu from './components/MultipleUsersMenu'
import NewAccountDialog from './components/NewAccountDialog'
2019-02-23 21:40:26 +00:00
2019-02-22 18:06:48 +00:00
export default {
name: 'Users',
2019-03-29 14:25:53 +00:00
components: {
UsersFilter,
2019-06-11 15:13:48 +00:00
MultipleUsersMenu,
NewAccountDialog
2019-03-29 14:25:53 +00:00
},
2019-05-21 19:24:48 +00:00
data() {
return {
2019-06-11 15:13:48 +00:00
search: '',
selectedUsers: [],
2019-09-23 19:00:28 +00:00
createAccountDialogOpen: false,
resetPasswordDialogOpen: false
2019-05-21 19:24:48 +00:00
}
},
2019-02-24 22:31:05 +00:00
computed: {
loading() {
return this.$store.state.users.loading
},
2019-05-05 21:51:52 +00:00
normalizedUsersCount() {
return numeral(this.$store.state.users.totalUsersCount).format('0a')
},
2019-02-24 22:31:05 +00:00
users() {
return this.$store.state.users.fetchedUsers
2019-02-27 22:13:20 +00:00
},
usersCount() {
return this.$store.state.users.totalUsersCount
},
pageSize() {
return this.$store.state.users.pageSize
2019-03-03 20:46:14 +00:00
},
2019-09-23 19:00:28 +00:00
passwordResetLink() {
return this.$store.state.users.passwordResetToken.link
},
passwordResetToken() {
return this.$store.state.users.passwordResetToken.token
},
2019-03-03 20:46:14 +00:00
currentPage() {
return this.$store.state.users.currentPage
2019-03-06 19:44:37 +00:00
},
2019-03-06 19:52:18 +00:00
isDesktop() {
return this.$store.state.app.device === 'desktop'
},
isMobile() {
return this.$store.state.app.device === 'mobile'
},
width() {
2019-03-22 21:18:57 +00:00
return this.isMobile ? 55 : false
2019-02-22 18:06:48 +00:00
}
2019-02-23 21:40:26 +00:00
},
2019-03-01 17:32:03 +00:00
created() {
this.handleDebounceSearchInput = debounce((query) => {
this.$store.dispatch('SearchUsers', { query, page: 1 })
2019-03-01 17:32:03 +00:00
}, 500)
},
2019-02-23 21:40:26 +00:00
mounted: function() {
this.$store.dispatch('FetchUsers', { page: 1 })
2019-02-24 22:31:05 +00:00
},
methods: {
activationIcon(status) {
return status ? 'el-icon-error' : 'el-icon-success'
},
clearSelection() {
this.$refs.usersTable.clearSelection()
},
2019-09-23 19:00:28 +00:00
async createNewAccount(accountData) {
try {
await this.$store.dispatch('CreateNewAccount', accountData)
} catch (_e) {
return
} finally {
this.createAccountDialogOpen = false
}
this.$message({
type: 'success',
message: this.$t('users.accountCreated')
})
2019-06-11 15:13:48 +00:00
},
getFirstLetter(str) {
return str.charAt(0).toUpperCase()
},
2019-09-23 19:00:28 +00:00
getPasswordResetToken(nickname) {
this.resetPasswordDialogOpen = true
this.$store.dispatch('GetPasswordResetToken', nickname)
},
requirePasswordReset(nickname) {
const mailerEnabled = this.$store.state.user.nodeInfo.metadata.mailerEnabled
if (!mailerEnabled) {
this.$alert(this.$t('users.mailerMustBeEnabled'), 'Error', { type: 'error' })
return
}
this.$store.dispatch('RequirePasswordReset', { nickname })
},
2019-03-22 21:18:57 +00:00
handleDeactivation({ nickname }) {
2019-02-26 19:50:25 +00:00
this.$store.dispatch('ToggleUserActivation', nickname)
2019-02-27 22:13:20 +00:00
},
handleDeletion(user) {
this.$store.dispatch('DeleteUser', user)
},
2019-02-27 22:13:20 +00:00
handlePageChange(page) {
2019-03-03 20:01:00 +00:00
const searchQuery = this.$store.state.users.searchQuery
if (searchQuery === '') {
this.$store.dispatch('FetchUsers', { page })
2019-03-03 20:01:00 +00:00
} else {
this.$store.dispatch('SearchUsers', { query: searchQuery, page })
2019-03-03 20:01:00 +00:00
}
},
handleSelectionChange(value) {
this.$data.selectedUsers = value
},
2019-09-23 19:00:28 +00:00
closeResetPasswordDialog() {
this.resetPasswordDialogOpen = false
this.$store.dispatch('RemovePasswordToken')
},
2019-03-22 21:18:57 +00:00
showAdminAction({ local, id }) {
return local && this.showDeactivatedButton(id)
},
showDeactivatedButton(id) {
return this.$store.state.user.id !== id
2019-03-22 21:18:57 +00:00
},
toggleTag(user, tag) {
user.tags.includes(tag)
? this.$store.dispatch('RemoveTag', { users: [user], tag })
: this.$store.dispatch('AddTag', { users: [user], tag })
2019-03-22 21:27:31 +00:00
},
toggleUserRight(user, right) {
this.$store.dispatch('ToggleRight', { user, right })
2019-02-24 22:31:05 +00:00
}
2019-02-22 18:06:48 +00:00
}
}
</script>
2019-09-23 19:00:28 +00:00
<style rel='stylesheet/scss' lang='scss'>
2019-06-11 15:13:48 +00:00
.actions-button {
text-align: left;
width: 350px;
padding: 10px;
}
.actions-container {
display: flex;
height: 36px;
justify-content: space-between;
align-items: center;
margin: 0 15px 10px 15px;
}
2019-03-29 14:25:53 +00:00
.active-tag {
color: #409EFF;
font-weight: 700;
.el-icon-check {
color: #409EFF;
float: right;
margin: 7px 0 0 15px;
}
}
2019-05-06 15:49:03 +00:00
.el-dropdown-link:hover {
2019-06-11 15:13:48 +00:00
cursor: pointer;
color: #409EFF;
}
.el-icon-plus {
margin-right: 5px;
}
2019-09-23 19:00:28 +00:00
.password-reset-token {
margin: 0 0 14px 0;
}
.password-reset-token-dialog {
width: 50%
}
.reset-password-link {
text-decoration: underline;
}
2019-02-24 22:31:05 +00:00
.users-container {
h1 {
2019-03-29 14:25:53 +00:00
margin: 22px 0 0 15px;
2019-02-24 22:31:05 +00:00
}
2019-02-27 22:13:20 +00:00
.pagination {
2019-03-03 20:01:00 +00:00
margin: 25px 0;
2019-02-27 22:13:20 +00:00
text-align: center;
}
2019-02-24 22:31:05 +00:00
2019-03-01 17:32:03 +00:00
.search {
2019-03-29 14:25:53 +00:00
width: 350px;
2019-03-01 17:32:03 +00:00
float: right;
}
2019-06-11 15:13:48 +00:00
.filter-container {
2019-03-06 19:44:37 +00:00
display: flex;
2019-03-29 14:25:53 +00:00
height: 36px;
2019-03-06 19:44:37 +00:00
justify-content: space-between;
2019-03-29 14:25:53 +00:00
align-items: center;
2019-05-26 18:39:26 +00:00
margin: 22px 15px 15px 15px
2019-03-06 19:44:37 +00:00
}
2019-05-05 21:51:52 +00:00
.user-count {
color: gray;
font-size: 28px;
2019-03-06 19:44:37 +00:00
}
2019-03-01 17:32:03 +00:00
}
2019-03-06 19:52:18 +00:00
@media
only screen and (max-width: 760px),
(min-device-width: 768px) and (max-device-width: 1024px) {
2019-09-23 19:00:28 +00:00
.password-reset-token-dialog {
width: 85%
}
2019-03-06 19:52:18 +00:00
.users-container {
h1 {
2019-06-15 19:01:10 +00:00
margin: 7px 10px 15px 10px;
2019-03-06 19:52:18 +00:00
}
2019-06-11 15:13:48 +00:00
.actions-container {
display: flex;
flex-direction: column;
margin: 0 10px 7px 10px
}
.create-account {
width: 100%;
}
2019-03-22 21:18:57 +00:00
.el-icon-arrow-down {
font-size: 12px;
}
2019-03-06 19:52:18 +00:00
.search {
2019-03-29 14:25:53 +00:00
width: 100%;
2019-03-06 19:52:18 +00:00
}
2019-06-11 15:13:48 +00:00
.filter-container {
2019-03-06 19:52:18 +00:00
display: flex;
2019-03-29 14:25:53 +00:00
height: 82px;
flex-direction: column;
2019-06-11 15:13:48 +00:00
margin: 0 10px
2019-03-06 19:52:18 +00:00
}
2019-03-22 21:18:57 +00:00
.el-tag {
width: 30px;
display: inline-block;
margin-bottom: 4px;
font-weight: bold;
&.el-tag--success {
padding-left: 8px;
}
&.el-tag--danger {
padding-left: 8px;
}
}
2019-03-06 19:52:18 +00:00
}
}
2019-02-24 22:31:05 +00:00
</style>