forked from AkkomaGang/admin-fe
Use tag names from TagPolicy, fixes #134
This commit is contained in:
parent
e8e43c236d
commit
e0bfc95a00
8 changed files with 68 additions and 68 deletions
|
@ -12,7 +12,7 @@ export async function fetchStatus(id, authHost, token) {
|
|||
id: '9n1bySks25olxWrku0',
|
||||
avatar: 'http://localhost:4000/images/avi.png',
|
||||
nickname: 'dolin',
|
||||
tags: ['strip_media', 'sandbox', 'disable_any_subscription', 'force_nsfw'],
|
||||
tags: ['mrf_tag:media-strip', 'mrf_tag:sandbox', 'mrf_tag:disable-any-subscription', 'mrf_tag:media-force-nsfw'],
|
||||
url: 'http://localhost:4000/users/dolin'
|
||||
},
|
||||
content: 'pizza makes everything better',
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
export let users = [
|
||||
{ active: true, deactivated: false, id: '2', nickname: 'allis', local: true, external: false, roles: { admin: true, moderator: false }, tags: [] },
|
||||
{ active: true, deactivated: false, id: '10', nickname: 'bob', local: false, external: true, roles: { admin: false, moderator: false }, tags: ['sandbox'] },
|
||||
{ active: false, deactivated: true, id: 'abc', nickname: 'john', local: true, external: false, roles: { admin: false, moderator: false }, tags: ['strip_media'] }
|
||||
{ active: true, deactivated: false, id: '10', nickname: 'bob', local: false, external: true, roles: { admin: false, moderator: false }, tags: ['mrf_tag:sandbox'] },
|
||||
{ active: false, deactivated: true, id: 'abc', nickname: 'john', local: true, external: false, roles: { admin: false, moderator: false }, tags: ['mrf_tag:media-strip'] }
|
||||
]
|
||||
|
||||
const userProfile = { avatar: 'avatar.jpg', nickname: 'allis', id: '2', tags: [], roles: { admin: true, moderator: false }, local: true, external: false }
|
||||
|
|
|
@ -16,42 +16,42 @@
|
|||
</el-dropdown-item>
|
||||
<el-dropdown-item
|
||||
:divided="true"
|
||||
:class="{ 'active-tag': tags.includes('force_nsfw') }"
|
||||
@click.native="toggleTag(account, 'force_nsfw')">
|
||||
:class="{ 'active-tag': tags.includes('mrf_tag:media-force-nsfw') }"
|
||||
@click.native="toggleTag(account, 'mrf_tag:media-force-nsfw')">
|
||||
{{ $t('users.forceNsfw') }}
|
||||
<i v-if="tags.includes('force_nsfw')" class="el-icon-check"/>
|
||||
<i v-if="tags.includes('mrf_tag:media-force-nsfw')" class="el-icon-check"/>
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item
|
||||
:class="{ 'active-tag': tags.includes('strip_media') }"
|
||||
@click.native="toggleTag(account, 'strip_media')">
|
||||
:class="{ 'active-tag': tags.includes('mrf_tag:media-strip') }"
|
||||
@click.native="toggleTag(account, 'mrf_tag:media-strip')">
|
||||
{{ $t('users.stripMedia') }}
|
||||
<i v-if="tags.includes('strip_media')" class="el-icon-check"/>
|
||||
<i v-if="tags.includes('mrf_tag:media-strip')" class="el-icon-check"/>
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item
|
||||
:class="{ 'active-tag': tags.includes('force_unlisted') }"
|
||||
@click.native="toggleTag(account, 'force_unlisted')">
|
||||
:class="{ 'active-tag': tags.includes('mrf_tag:force-unlisted') }"
|
||||
@click.native="toggleTag(account, 'mrf_tag:force-unlisted')">
|
||||
{{ $t('users.forceUnlisted') }}
|
||||
<i v-if="tags.includes('force_unlisted')" class="el-icon-check"/>
|
||||
<i v-if="tags.includes('mrf_tag:force-unlisted')" class="el-icon-check"/>
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item
|
||||
:class="{ 'active-tag': tags.includes('sandbox') }"
|
||||
@click.native="toggleTag(account, 'sandbox')">
|
||||
:class="{ 'active-tag': tags.includes('mrf_tag:sandbox') }"
|
||||
@click.native="toggleTag(account, 'mrf_tag:sandbox')">
|
||||
{{ $t('users.sandbox') }}
|
||||
<i v-if="tags.includes('sandbox')" class="el-icon-check"/>
|
||||
<i v-if="tags.includes('mrf_tag:sandbox')" class="el-icon-check"/>
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item
|
||||
v-if="account.local"
|
||||
:class="{ 'active-tag': tags.includes('disable_remote_subscription') }"
|
||||
@click.native="toggleTag(account, 'disable_remote_subscription')">
|
||||
:class="{ 'active-tag': tags.includes('mrf_tag:disable-remote-subscription') }"
|
||||
@click.native="toggleTag(account, 'mrf_tag:disable-remote-subscription')">
|
||||
{{ $t('users.disableRemoteSubscription') }}
|
||||
<i v-if="tags.includes('disable_remote_subscription')" class="el-icon-check"/>
|
||||
<i v-if="tags.includes('mrf_tag:disable-remote-subscription')" class="el-icon-check"/>
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item
|
||||
v-if="account.local"
|
||||
:class="{ 'active-tag': tags.includes('disable_any_subscription') }"
|
||||
@click.native="toggleTag(account, 'disable_any_subscription')">
|
||||
:class="{ 'active-tag': tags.includes('mrf_tag:disable-any-subscription') }"
|
||||
@click.native="toggleTag(account, 'mrf_tag:disable-any-subscription')">
|
||||
{{ $t('users.disableAnySubscription') }}
|
||||
<i v-if="tags.includes('disable_any_subscription')" class="el-icon-check"/>
|
||||
<i v-if="tags.includes('mrf_tag:disable-any-subscription')" class="el-icon-check"/>
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</el-dropdown>
|
||||
|
|
|
@ -50,42 +50,42 @@
|
|||
</el-dropdown-item>
|
||||
<el-dropdown-item
|
||||
:divided="showAdminAction(user)"
|
||||
:class="{ 'active-tag': user.tags.includes('force_nsfw') }"
|
||||
@click.native="toggleTag(user, 'force_nsfw')">
|
||||
:class="{ 'active-tag': user.tags.includes('mrf_tag:media-force-nsfw') }"
|
||||
@click.native="toggleTag(user, 'mrf_tag:media-force-nsfw')">
|
||||
{{ $t('users.forceNsfw') }}
|
||||
<i v-if="user.tags.includes('force_nsfw')" class="el-icon-check"/>
|
||||
<i v-if="user.tags.includes('mrf_tag:media-force-nsfw')" class="el-icon-check"/>
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item
|
||||
:class="{ 'active-tag': user.tags.includes('strip_media') }"
|
||||
@click.native="toggleTag(user, 'strip_media')">
|
||||
:class="{ 'active-tag': user.tags.includes('mrf_tag:media-strip') }"
|
||||
@click.native="toggleTag(user, 'mrf_tag:media-strip')">
|
||||
{{ $t('users.stripMedia') }}
|
||||
<i v-if="user.tags.includes('strip_media')" class="el-icon-check"/>
|
||||
<i v-if="user.tags.includes('mrf_tag:media-strip')" class="el-icon-check"/>
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item
|
||||
:class="{ 'active-tag': user.tags.includes('force_unlisted') }"
|
||||
@click.native="toggleTag(user, 'force_unlisted')">
|
||||
:class="{ 'active-tag': user.tags.includes('mrf_tag:force-unlisted') }"
|
||||
@click.native="toggleTag(user, 'mrf_tag:force-unlisted')">
|
||||
{{ $t('users.forceUnlisted') }}
|
||||
<i v-if="user.tags.includes('force_unlisted')" class="el-icon-check"/>
|
||||
<i v-if="user.tags.includes('mrf_tag:force-unlisted')" class="el-icon-check"/>
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item
|
||||
:class="{ 'active-tag': user.tags.includes('sandbox') }"
|
||||
@click.native="toggleTag(user, 'sandbox')">
|
||||
:class="{ 'active-tag': user.tags.includes('mrf_tag:sandbox') }"
|
||||
@click.native="toggleTag(user, 'mrf_tag:sandbox')">
|
||||
{{ $t('users.sandbox') }}
|
||||
<i v-if="user.tags.includes('sandbox')" class="el-icon-check"/>
|
||||
<i v-if="user.tags.includes('mrf_tag:sandbox')" class="el-icon-check"/>
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item
|
||||
v-if="user.local"
|
||||
:class="{ 'active-tag': user.tags.includes('disable_remote_subscription') }"
|
||||
@click.native="toggleTag(user, 'disable_remote_subscription')">
|
||||
:class="{ 'active-tag': user.tags.includes('mrf_tag:disable-remote-subscription') }"
|
||||
@click.native="toggleTag(user, 'mrf_tag:disable-remote-subscription')">
|
||||
{{ $t('users.disableRemoteSubscription') }}
|
||||
<i v-if="user.tags.includes('disable_remote_subscription')" class="el-icon-check"/>
|
||||
<i v-if="user.tags.includes('mrf_tag:disable-remote-subscription')" class="el-icon-check"/>
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item
|
||||
v-if="user.local"
|
||||
:class="{ 'active-tag': user.tags.includes('disable_any_subscription') }"
|
||||
@click.native="toggleTag(user, 'disable_any_subscription')">
|
||||
:class="{ 'active-tag': user.tags.includes('mrf_tag:disable-any-subscription') }"
|
||||
@click.native="toggleTag(user, 'mrf_tag:disable-any-subscription')">
|
||||
{{ $t('users.disableAnySubscription') }}
|
||||
<i v-if="user.tags.includes('disable_any_subscription')" class="el-icon-check"/>
|
||||
<i v-if="user.tags.includes('mrf_tag:disable-any-subscription')" class="el-icon-check"/>
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item
|
||||
v-if="user.local"
|
||||
|
|
|
@ -56,10 +56,10 @@
|
|||
<div class="tag-container">
|
||||
<span class="tag-text">{{ $t('users.forceNsfw') }}</span>
|
||||
<el-button-group class="tag-button-group">
|
||||
<el-button size="mini" @click.native="addTagForMultipleUsers('force_nsfw')">
|
||||
<el-button size="mini" @click.native="addTagForMultipleUsers('mrf_tag:media-force-nsfw')">
|
||||
{{ $t('users.apply') }}
|
||||
</el-button>
|
||||
<el-button size="mini" @click.native="removeTagFromMultipleUsers('force_nsfw')">
|
||||
<el-button size="mini" @click.native="removeTagFromMultipleUsers('mrf_tag:media-force-nsfw')">
|
||||
{{ $t('users.remove') }}
|
||||
</el-button>
|
||||
</el-button-group>
|
||||
|
@ -69,10 +69,10 @@
|
|||
<div class="tag-container">
|
||||
<span class="tag-text">{{ $t('users.stripMedia') }}</span>
|
||||
<el-button-group class="tag-button-group">
|
||||
<el-button size="mini" @click.native="addTagForMultipleUsers('strip_media')">
|
||||
<el-button size="mini" @click.native="addTagForMultipleUsers('mrf_tag:media-strip')">
|
||||
{{ $t('users.apply') }}
|
||||
</el-button>
|
||||
<el-button size="mini" @click.native="removeTagFromMultipleUsers('strip_media')">
|
||||
<el-button size="mini" @click.native="removeTagFromMultipleUsers('mrf_tag:media-strip')">
|
||||
{{ $t('users.remove') }}
|
||||
</el-button>
|
||||
</el-button-group>
|
||||
|
@ -82,10 +82,10 @@
|
|||
<div class="tag-container">
|
||||
<span class="tag-text">{{ $t('users.forceUnlisted') }}</span>
|
||||
<el-button-group class="tag-button-group">
|
||||
<el-button size="mini" @click.native="addTagForMultipleUsers('force_unlisted')">
|
||||
<el-button size="mini" @click.native="addTagForMultipleUsers('mrf_tag:force-unlisted')">
|
||||
{{ $t('users.apply') }}
|
||||
</el-button>
|
||||
<el-button size="mini" @click.native="removeTagFromMultipleUsers('force_unlisted')">
|
||||
<el-button size="mini" @click.native="removeTagFromMultipleUsers('mrf_tag:force-unlisted')">
|
||||
{{ $t('users.remove') }}
|
||||
</el-button>
|
||||
</el-button-group>
|
||||
|
@ -95,10 +95,10 @@
|
|||
<div class="tag-container">
|
||||
<span class="tag-text">{{ $t('users.sandbox') }}</span>
|
||||
<el-button-group class="tag-button-group">
|
||||
<el-button size="mini" @click.native="addTagForMultipleUsers('sandbox')">
|
||||
<el-button size="mini" @click.native="addTagForMultipleUsers('mrf_tag:sandbox')">
|
||||
{{ $t('users.apply') }}
|
||||
</el-button>
|
||||
<el-button size="mini" @click.native="removeTagFromMultipleUsers('sandbox')">
|
||||
<el-button size="mini" @click.native="removeTagFromMultipleUsers('mrf_tag:sandbox')">
|
||||
{{ $t('users.remove') }}
|
||||
</el-button>
|
||||
</el-button-group>
|
||||
|
@ -108,10 +108,10 @@
|
|||
<div class="tag-container">
|
||||
<span class="tag-text">{{ $t('users.disableRemoteSubscriptionForMultiple') }}</span>
|
||||
<el-button-group class="tag-button-group">
|
||||
<el-button size="mini" @click.native="addTagForMultipleUsers('disable_remote_subscription')">
|
||||
<el-button size="mini" @click.native="addTagForMultipleUsers('mrf_tag:disable-remote-subscription')">
|
||||
{{ $t('users.apply') }}
|
||||
</el-button>
|
||||
<el-button size="mini" @click.native="removeTagFromMultipleUsers('disable_remote_subscription')">
|
||||
<el-button size="mini" @click.native="removeTagFromMultipleUsers('mrf_tag:disable-remote-subscription')">
|
||||
{{ $t('users.remove') }}
|
||||
</el-button>
|
||||
</el-button-group>
|
||||
|
@ -121,10 +121,10 @@
|
|||
<div class="tag-container">
|
||||
<span class="tag-text">{{ $t('users.disableAnySubscriptionForMultiple') }}</span>
|
||||
<el-button-group class="tag-button-group">
|
||||
<el-button size="mini" @click.native="addTagForMultipleUsers('disable_any_subscription')">
|
||||
<el-button size="mini" @click.native="addTagForMultipleUsers('mrf_tag:disable-any-subscription')">
|
||||
{{ $t('users.apply') }}
|
||||
</el-button>
|
||||
<el-button size="mini" @click.native="removeTagFromMultipleUsers('disable_any_subscription')">
|
||||
<el-button size="mini" @click.native="removeTagFromMultipleUsers('mrf_tag:disable-any-subscription')">
|
||||
{{ $t('users.remove') }}
|
||||
</el-button>
|
||||
</el-button-group>
|
||||
|
@ -198,7 +198,7 @@ export default {
|
|||
},
|
||||
addTag: (tag) => () => {
|
||||
const filtered = this.selectedUsers.filter(user =>
|
||||
tag === 'disable_remote_subscription' || tag === 'disable_any_subscription'
|
||||
tag === 'mrf_tag:disable-remote-subscription' || tag === 'mrf_tag:disable-any-subscription'
|
||||
? this.isLocalUser(user) && !user.tags.includes(tag)
|
||||
: user.nickname && !user.tags.includes(tag))
|
||||
const addTagFn = async(users) => await this.$store.dispatch('AddTag', { users, tag })
|
||||
|
@ -206,7 +206,7 @@ export default {
|
|||
},
|
||||
removeTag: (tag) => async() => {
|
||||
const filtered = this.selectedUsers.filter(user =>
|
||||
tag === 'disable_remote_subscription' || tag === 'disable_any_subscription'
|
||||
tag === 'mrf_tag:disable-remote-subscription' || tag === 'mrf_tag:disable-any-subscription'
|
||||
? this.isLocalUser(user) && user.tags.includes(tag)
|
||||
: user.nickname && user.tags.includes(tag))
|
||||
const removeTagFn = async(users) => await this.$store.dispatch('RemoveTag', { users, tag })
|
||||
|
|
|
@ -169,12 +169,12 @@ export default {
|
|||
},
|
||||
humanizeTag(tag) {
|
||||
const mapTags = {
|
||||
'force_nsfw': 'Force NSFW',
|
||||
'strip_media': 'Strip Media',
|
||||
'force_unlisted': 'Force Unlisted',
|
||||
'sandbox': 'Sandbox',
|
||||
'disable_remote_subscription': 'Disable remote subscription',
|
||||
'disable_any_subscription': 'Disable any subscription'
|
||||
'mrf_tag:media-force-nsfw': 'Force NSFW',
|
||||
'mrf_tag:media-strip': 'Strip Media',
|
||||
'mrf_tag:force-unlisted': 'Force Unlisted',
|
||||
'mrf_tag:sandbox': 'Sandbox',
|
||||
'mrf_tag:disable-remote-subscription': 'Disable remote subscription',
|
||||
'mrf_tag:disable-any-subscription': 'Disable any subscription'
|
||||
}
|
||||
return mapTags[tag]
|
||||
},
|
||||
|
|
|
@ -159,7 +159,7 @@ describe('Users actions', () => {
|
|||
expect(store.state.users.fetchedUsers[1].deactivated).toBe(false)
|
||||
|
||||
wrapper.find(htmlElement(2, 2)).trigger('click')
|
||||
store.dispatch('DeleteUsers', { users: [{ active: true, deactivated: false, id: '10', nickname: 'bob', local: false, external: true, roles: { admin: false, moderator: false }, tags: ['sandbox'] }] })
|
||||
store.dispatch('DeleteUsers', { users: [{ active: true, deactivated: false, id: '10', nickname: 'bob', local: false, external: true, roles: { admin: false, moderator: false }, tags: ['mrf_tag:sandbox'] }] })
|
||||
|
||||
await flushPromises()
|
||||
expect(store.state.users.fetchedUsers[1].deactivated).toBe(true)
|
||||
|
|
|
@ -249,22 +249,22 @@ describe('Apply users actions to multiple users', () => {
|
|||
|
||||
wrapper.find(`.el-dropdown-menu__item:nth-child(11) button:nth-child(1)`).trigger('click')
|
||||
expect(wrapper.vm.addTagForMultipleUsers).toHaveBeenCalled()
|
||||
expect(wrapper.vm.addTagForMultipleUsers).toHaveBeenCalledWith('force_nsfw')
|
||||
expect(wrapper.vm.addTagForMultipleUsers).toHaveBeenCalledWith('mrf_tag:media-force-nsfw')
|
||||
|
||||
wrapper.find(`.el-dropdown-menu__item:nth-child(13) button:nth-child(1)`).trigger('click')
|
||||
expect(wrapper.vm.addTagForMultipleUsers).toHaveBeenCalled()
|
||||
expect(wrapper.vm.addTagForMultipleUsers).toHaveBeenCalledWith('force_unlisted')
|
||||
expect(wrapper.vm.addTagForMultipleUsers).toHaveBeenCalledWith('mrf_tag:force-unlisted')
|
||||
|
||||
wrapper.find(`.el-dropdown-menu__item:nth-child(15 ) button:nth-child(1)`).trigger('click')
|
||||
expect(wrapper.vm.addTagForMultipleUsers).toHaveBeenCalled()
|
||||
expect(wrapper.vm.addTagForMultipleUsers).toHaveBeenCalledWith('disable_remote_subscription')
|
||||
expect(wrapper.vm.addTagForMultipleUsers).toHaveBeenCalledWith('mrf_tag:disable-remote-subscription')
|
||||
|
||||
const addTag = wrapper.vm.mappers().addTag
|
||||
const user1 = store.state.users.fetchedUsers[0]
|
||||
const user2 = store.state.users.fetchedUsers[1]
|
||||
expect(user1.tags.length).toBe(0)
|
||||
expect(user2.tags.length).toBe(1)
|
||||
addTag('strip_media')()
|
||||
addTag('mrf_tag:media-strip')()
|
||||
|
||||
const updatedUser1 = store.state.users.fetchedUsers[0]
|
||||
const updatedUser2 = store.state.users.fetchedUsers[1]
|
||||
|
@ -289,22 +289,22 @@ describe('Apply users actions to multiple users', () => {
|
|||
|
||||
wrapper.find(`.el-dropdown-menu__item:nth-child(12) button:nth-child(2)`).trigger('click')
|
||||
expect(wrapper.vm.removeTagFromMultipleUsers).toHaveBeenCalled()
|
||||
expect(wrapper.vm.removeTagFromMultipleUsers).toHaveBeenCalledWith('strip_media')
|
||||
expect(wrapper.vm.removeTagFromMultipleUsers).toHaveBeenCalledWith('mrf_tag:media-strip')
|
||||
|
||||
wrapper.find(`.el-dropdown-menu__item:nth-child(14) button:nth-child(2)`).trigger('click')
|
||||
expect(wrapper.vm.removeTagFromMultipleUsers).toHaveBeenCalled()
|
||||
expect(wrapper.vm.removeTagFromMultipleUsers).toHaveBeenCalledWith('sandbox')
|
||||
expect(wrapper.vm.removeTagFromMultipleUsers).toHaveBeenCalledWith('mrf_tag:sandbox')
|
||||
|
||||
wrapper.find(`.el-dropdown-menu__item:nth-child(16) button:nth-child(2)`).trigger('click')
|
||||
expect(wrapper.vm.removeTagFromMultipleUsers).toHaveBeenCalled()
|
||||
expect(wrapper.vm.removeTagFromMultipleUsers).toHaveBeenCalledWith('disable_any_subscription')
|
||||
expect(wrapper.vm.removeTagFromMultipleUsers).toHaveBeenCalledWith('mrf_tag:disable-any-subscription')
|
||||
|
||||
const removeTag = wrapper.vm.mappers().removeTag
|
||||
const user1 = store.state.users.fetchedUsers[1]
|
||||
const user2 = store.state.users.fetchedUsers[2]
|
||||
expect(user1.tags.length).toBe(1)
|
||||
expect(user2.tags.length).toBe(1)
|
||||
removeTag('strip_media')()
|
||||
removeTag('mrf_tag:media-strip')()
|
||||
|
||||
const updatedUser1 = store.state.users.fetchedUsers[1]
|
||||
const updatedUser2 = store.state.users.fetchedUsers[2]
|
||||
|
|
Loading…
Reference in a new issue