Replace checking if acccount is valid with checking if property exists

This commit is contained in:
Angelina Filippova 2020-06-06 22:16:25 +03:00
parent e67fc33600
commit 789fa36e1a
6 changed files with 96 additions and 80 deletions

View file

@ -6,12 +6,15 @@
<div class="status-account-container">
<div class="status-account">
<el-checkbox v-if="showCheckbox" class="status-checkbox" @change="handleStatusSelection(account)"/>
<img v-if="isValid(account)" :src="account.avatar" class="status-avatar-img">
<a v-if="isValid(account)" :href="account.url" target="_blank" class="account">
<h3 class="status-account-name">{{ account.nickname }}</h3>
<img v-if="propertyExists(account, 'avatar')" :src="account.avatar" class="status-avatar-img">
<a v-if="propertyExists(account, 'url', 'nickname')" :href="account.url" target="_blank" class="account">
<span class="status-account-name">{{ account.nickname }}</span>
</a>
<span v-else class="deactivated">
<h3 class="status-account-name">({{ $t('users.invalidNickname') }})</h3>
<span v-else>
<span v-if="propertyExists(account, 'nickname')" class="status-account-name">
{{ account.nickname }}
</span>
<span v-else class="status-account-name deactivated">({{ $t('users.invalidNickname') }})</span>
</span>
</div>
</div>
@ -202,8 +205,8 @@ export default {
})
})
},
isValid(account) {
return account.nickname && account.id
handleStatusSelection(account) {
this.$emit('status-selection', account)
},
optionPercent(poll, pollOption) {
const allVotes = poll.options.reduce((acc, option) => (acc + option.votes_count), 0)
@ -215,8 +218,11 @@ export default {
parseTimestamp(timestamp) {
return moment(timestamp).format('YYYY-MM-DD HH:mm')
},
handleStatusSelection(account) {
this.$emit('status-selection', account)
propertyExists(account, property, _secondProperty) {
if (_secondProperty) {
return account[property] && account[_secondProperty]
}
return account[property]
}
}
}
@ -232,7 +238,7 @@ export default {
}
.deactivated {
color: gray;
line-height: 32px;
line-height: 28px;
vertical-align: middle;
}
.image {
@ -257,7 +263,9 @@ export default {
.status-account-name {
display: inline-block;
margin: 0;
height: 22px;
height: 28px;
font-size: 15px;
font-weight: 500;
}
.status-body {
display: flex;

View file

@ -239,7 +239,7 @@ export default {
confirmAccount: 'Confirm account',
confirmAccounts: 'Confirm accounts',
resendConfirmation: 'Resend confirmation email',
invalidUser: 'This account is invalid and can\'t be modified',
invalidAccount: 'This account has invalid nickname and can\'t be modified',
invalidNickname: 'invalid nickname'
},
statuses: {

View file

@ -10,9 +10,9 @@
<el-card class="report">
<div class="report-header-container">
<div class="title-container">
<h3 v-if="isValid(report.account)" class="report-title">{{ $t('reports.reportOn') }} {{ report.account.nickname }}</h3>
<h3 v-if="propertyExists(report.account, 'nickname')" class="report-title">{{ $t('reports.reportOn') }} {{ report.account.nickname }}</h3>
<h3 v-else class="report-title">{{ $t('reports.report') }}</h3>
<h5 class="id">{{ $t('reports.id') }}: {{ report.id }}</h5>
<h5 v-if="propertyExists(report.account, 'id')" class="id">{{ $t('reports.id') }}: {{ report.id }}</h5>
</div>
<div>
<el-tag :type="getStateType(report.state)" size="large" class="report-tag">{{ capitalizeFirstLetter(report.state) }}</el-tag>
@ -24,26 +24,26 @@
<el-dropdown-item v-if="report.state !== 'closed'" @click.native="changeReportState('closed', report.id)">{{ $t('reports.close') }}</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
<moderate-user-dropdown v-if="isValid(report.account)" :account="report.account"/>
<moderate-user-dropdown v-if="propertyExists(report.account, 'nickname')" :account="report.account"/>
</div>
</div>
<div>
<el-divider class="divider"/>
<span class="report-row-key">{{ $t('reports.account') }}:</span>
<span v-if="isValid(report.account)">
<img
:src="report.account.avatar"
alt="avatar"
class="avatar-img">
<a v-if="isValid(report.account)" :href="report.account.url" target="_blank" class="account">
<span>{{ report.account.nickname }}</span>
</a>
<span v-else>
<img
v-if="propertyExists(report.account, 'avatar')"
:src="report.account.avatar"
alt="avatar"
class="avatar-img">
<a v-if="propertyExists(report.account, 'url', 'nickname')" :href="report.account.url" target="_blank" class="account">
<span class="report-account-name">{{ report.account.nickname }}</span>
</a>
<span v-else>
<span v-if="propertyExists(report.account, 'nickname')" class="report-account-name">
{{ report.account.nickname }}
<span class="deactivated"> (deactivated)</span>
</span>
<span v-else class="report-account-name deactivated">({{ $t('users.invalidNickname') }})</span>
</span>
<span v-else class="deactivated">({{ $t('reports.notFound') }})</span>
</div>
<div v-if="report.content && report.content.length > 0">
<el-divider class="divider"/>
@ -54,16 +54,20 @@
<div :style="showStatuses(report.statuses) ? '' : 'margin-bottom:15px'">
<el-divider class="divider"/>
<span class="report-row-key">{{ $t('reports.actor') }}:</span>
<span v-if="isValid(report.actor)">
<img
:src="report.actor.avatar"
alt="avatar"
class="avatar-img">
<a :href="report.actor.url" target="_blank" class="account">
<span>{{ report.actor.nickname }}</span>
</a>
<img
v-if="propertyExists(report.actor, 'avatar')"
:src="report.actor.avatar"
alt="avatar"
class="avatar-img">
<a v-if="propertyExists(report.actor, 'url', 'nickname')" :href="report.actor.url" target="_blank" class="account">
<span class="report-account-name">{{ report.actor.nickname }}</span>
</a>
<span v-else>
<span v-if="propertyExists(report.actor, 'nickname')" class="report-account-name">
{{ report.actor.nickname }}
</span>
<span v-else class="report-account-name deactivated">({{ $t('users.invalidNickname') }})</span>
</span>
<span v-else class="deactivated">({{ $t('reports.notFound') }})</span>
</div>
<div v-if="showStatuses(report.statuses)" class="statuses">
<el-collapse>
@ -171,12 +175,15 @@ export default {
handlePageChange(page) {
this.$store.dispatch('FetchReports', page)
},
isValid(account) {
return account.nickname && account.id
},
parseTimestamp(timestamp) {
return moment(timestamp).format('L HH:mm')
},
propertyExists(account, property, _secondProperty) {
if (_secondProperty) {
return account[property] && account[_secondProperty]
}
return account[property]
},
showStatuses(statuses = []) {
return statuses.length > 0
}
@ -262,6 +269,10 @@ export default {
font-style: italic;
color: gray;
}
.report-account-name {
font-size: 15px;
font-weight: 500;
}
.report-row-key {
font-size: 14px;
font-weight: 500;

View file

@ -165,33 +165,33 @@ export default {
}
return {
grantRight: (right) => () => {
const filterUsersFn = user => this.isValid(user) && user.local && !user.roles[right] && this.$store.state.user.id !== user.id
const filterUsersFn = user => this.isLocalUser(user) && !user.roles[right] && this.$store.state.user.id !== user.id
const addRightFn = async(users) => await this.$store.dispatch('AddRight', { users, right })
const filtered = this.selectedUsers.filter(filterUsersFn)
applyAction(filtered, addRightFn)
},
revokeRight: (right) => () => {
const filterUsersFn = user => this.isValid(user) && user.local && user.roles[right] && this.$store.state.user.id !== user.id
const filterUsersFn = user => this.isLocalUser(user) && user.roles[right] && this.$store.state.user.id !== user.id
const deleteRightFn = async(users) => await this.$store.dispatch('DeleteRight', { users, right })
const filtered = this.selectedUsers.filter(filterUsersFn)
applyAction(filtered, deleteRightFn)
},
activate: () => {
const filtered = this.selectedUsers.filter(user => this.isValid(user) && user.deactivated && this.$store.state.user.id !== user.id)
const filtered = this.selectedUsers.filter(user => user.nickname && user.deactivated && this.$store.state.user.id !== user.id)
const activateUsersFn = async(users) => await this.$store.dispatch('ActivateUsers', { users })
applyAction(filtered, activateUsersFn)
},
deactivate: () => {
const filtered = this.selectedUsers.filter(user => this.isValid(user) && !user.deactivated && this.$store.state.user.id !== user.id)
const filtered = this.selectedUsers.filter(user => user.nickname && !user.deactivated && this.$store.state.user.id !== user.id)
const deactivateUsersFn = async(users) => await this.$store.dispatch('DeactivateUsers', { users })
applyAction(filtered, deactivateUsersFn)
},
remove: () => {
const filtered = this.selectedUsers.filter(user => this.isValid(user) && this.$store.state.user.id !== user.id)
const filtered = this.selectedUsers.filter(user => user.nickname && this.$store.state.user.id !== user.id)
const deleteAccountFn = async(users) => await this.$store.dispatch('DeleteUsers', { users })
applyAction(filtered, deleteAccountFn)
@ -199,42 +199,42 @@ export default {
addTag: (tag) => () => {
const filtered = this.selectedUsers.filter(user =>
tag === 'disable_remote_subscription' || tag === 'disable_any_subscription'
? this.isValid(user) && user.local && !user.tags.includes(tag)
: this.isValid(user) && !user.tags.includes(tag))
? this.isLocalUser(user) && !user.tags.includes(tag)
: user.nickname && !user.tags.includes(tag))
const addTagFn = async(users) => await this.$store.dispatch('AddTag', { users, tag })
applyAction(filtered, addTagFn)
},
removeTag: (tag) => async() => {
const filtered = this.selectedUsers.filter(user =>
tag === 'disable_remote_subscription' || tag === 'disable_any_subscription'
? this.isValid(user) && user.local && user.tags.includes(tag)
: this.isValid(user) && user.tags.includes(tag))
? this.isLocalUser(user) && user.tags.includes(tag)
: user.nickname && user.tags.includes(tag))
const removeTagFn = async(users) => await this.$store.dispatch('RemoveTag', { users, tag })
applyAction(filtered, removeTagFn)
},
requirePasswordReset: () => {
const filtered = this.selectedUsers.filter(user => this.isValid(user) && user.local)
const filtered = this.selectedUsers.filter(user => this.isLocalUser(user))
const requirePasswordResetFn = async(users) => await this.$store.dispatch('RequirePasswordReset', users)
applyAction(filtered, requirePasswordResetFn)
},
confirmAccounts: () => {
const filtered = this.selectedUsers.filter(user => this.isValid(user) && user.local && user.confirmation_pending)
const filtered = this.selectedUsers.filter(user => this.isLocalUser(user) && user.confirmation_pending)
const confirmAccountFn = async(users) => await this.$store.dispatch('ConfirmUsersEmail', { users })
applyAction(filtered, confirmAccountFn)
},
resendConfirmation: () => {
const filtered = this.selectedUsers.filter(user => this.isValid(user) && user.local && user.confirmation_pending)
const filtered = this.selectedUsers.filter(user => this.isLocalUser(user) && user.confirmation_pending)
const resendConfirmationFn = async(users) => await this.$store.dispatch('ResendConfirmationEmail', users)
applyAction(filtered, resendConfirmationFn)
}
}
},
isValid(user) {
return user.nickname && user.id
isLocalUser(user) {
return user.nickname && user.local
},
grantRightToMultipleUsers(right) {
const { grantRight } = this.mappers()

View file

@ -76,11 +76,14 @@
<el-table-column :label="$t('users.actions')" fixed="right">
<template slot-scope="scope">
<moderation-dropdown
v-if="isValid(scope.row)"
v-if="propertyExists(scope.row, 'nickname')"
:user="scope.row"
:page="'users'"
@open-reset-token-dialog="openResetPasswordDialog"/>
<span v-else class="invalid-user">{{ $t('users.invalidUser') }}</span>
<el-button v-else type="text" disabled>
{{ $t('users.moderation') }}
<i v-if="isDesktop" class="el-icon-arrow-down el-icon--right"/>
</el-button>
</template>
</el-table-column>
</el-table>
@ -217,12 +220,12 @@ export default {
handleSelectionChange(value) {
this.$data.selectedUsers = value
},
isValid(user) {
return user.nickname && user.id
},
openResetPasswordDialog() {
this.resetPasswordDialogOpen = true
},
propertyExists(account, property) {
return account[property]
},
showDeactivatedButton(id) {
return this.$store.state.user.id !== id
}
@ -262,7 +265,7 @@ export default {
.create-account > .el-icon-plus {
margin-right: 5px;
}
.invalid-user {
.invalid-account {
color: gray;
}
.users-header-container {

View file

@ -2,13 +2,13 @@
<main v-if="!userProfileLoading">
<header v-if="isDesktop || isTablet" class="user-page-header">
<div class="avatar-name-container">
<el-avatar :src="user.avatar" size="large" />
<h1 v-if="isValid(user)">{{ user.nickname }}</h1>
<el-avatar v-if="propertyExists(user, 'avatar')" :src="user.avatar" size="large" />
<h1 v-if="propertyExists(user, 'nickname')">{{ user.nickname }}</h1>
<h1 v-else class="invalid">({{ $t('users.invalidNickname') }})</h1>
</div>
<div class="left-header-container">
<moderation-dropdown
v-if="isValid(user)"
v-if="propertyExists(user, 'nickname')"
:user="user"
:page="'userPage'"
@open-reset-token-dialog="openResetPasswordDialog"/>
@ -18,14 +18,14 @@
<div v-if="isMobile" class="user-page-header-container">
<header class="user-page-header">
<div class="avatar-name-container">
<el-avatar :src="user.avatar" size="large" />
<h1 v-if="isValid(user)">{{ user.nickname }}</h1>
<el-avatar v-if="propertyExists(user, 'avatar')" :src="user.avatar" size="large" />
<h1 v-if="propertyExists(user, 'nickname')">{{ user.nickname }}</h1>
<h1 v-else class="invalid">({{ $t('users.invalidNickname') }})</h1>
</div>
<reboot-button/>
</header>
<moderation-dropdown
v-if="isValid(user)"
v-if="propertyExists(user, 'nickname')"
:user="user"
:page="'userPage'"
@open-reset-token-dialog="openResetPasswordDialog"/>
@ -46,17 +46,11 @@
<div class="user-profile-container">
<el-card class="user-profile-card">
<div class="el-table el-table--fit el-table--enable-row-hover el-table--enable-row-transition el-table--medium">
<el-tag v-if="!isValid(user)" type="info" class="invalid-user-tag">
{{ $t('users.invalidUser') }}
<el-tag v-if="!propertyExists(user, 'nickname')" type="info" class="invalid-user-tag">
{{ $t('users.invalidAccount') }}
</el-tag>
<table class="user-profile-table">
<tbody>
<tr class="el-table__row">
<td>{{ $t('userProfile.nickname') }}</td>
<td>
{{ user.nickname }}
</td>
</tr>
<tr class="el-table__row">
<td class="name-col">ID</td>
<td class="value-col">
@ -66,8 +60,8 @@
<tr class="el-table__row">
<td>{{ $t('userProfile.tags') }}</td>
<td>
<el-tag v-for="tag in user.tags" :key="tag" class="user-profile-tag">{{ tag }}</el-tag>
<span v-if="user.tags.length === 0"></span>
<span v-if="user.tags.length === 0 || !propertyExists(user, 'tags')"></span>
<el-tag v-for="tag in user.tags" v-else :key="tag" class="user-profile-tag">{{ tag }}</el-tag>
</td>
</tr>
<tr class="el-table__row">
@ -79,7 +73,7 @@
<el-tag v-if="user.roles.moderator" class="user-profile-tag">
{{ $t('users.moderator') }}
</el-tag>
<span v-if="!user.roles.moderator && !user.roles.admin"></span>
<span v-if="!propertyExists(user, 'roles') || (!user.roles.moderator && !user.roles.admin)"></span>
</td>
</tr>
<tr class="el-table__row">
@ -99,11 +93,11 @@
</tbody>
</table>
</div>
<el-button v-if="isValid(user)" icon="el-icon-lock" class="security-setting-button" @click="securitySettingsModalVisible = true">
<el-button v-if="propertyExists(user, 'nickname')" icon="el-icon-lock" class="security-setting-button" @click="securitySettingsModalVisible = true">
{{ $t('userProfile.securitySettings.securitySettings') }}
</el-button>
<SecuritySettingsModal
v-if="isValid(user)"
v-if="propertyExists(user, 'nickname')"
:user="user"
:visible="securitySettingsModalVisible"
@close="securitySettingsModalVisible = false" />
@ -185,14 +179,14 @@ export default {
this.resetPasswordDialogOpen = false
this.$store.dispatch('RemovePasswordToken')
},
isValid(user) {
return user.nickname && user.id
},
onTogglePrivate() {
this.$store.dispatch('FetchUserProfile', { userId: this.$route.params.id, godmode: this.showPrivate })
},
openResetPasswordDialog() {
this.resetPasswordDialogOpen = true
},
propertyExists(account, property) {
return account[property]
}
}
}