mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
do not pass USER role by update role. Simplify logic
This commit is contained in:
parent
d82a994eeb
commit
a1d12c3c68
@ -46,7 +46,7 @@ describe('ChangeUserRoleFormular', () => {
|
||||
propsData = {
|
||||
item: {
|
||||
userId: 1,
|
||||
roles: ['USER'],
|
||||
roles: [],
|
||||
},
|
||||
}
|
||||
wrapper = Wrapper()
|
||||
@ -62,7 +62,7 @@ describe('ChangeUserRoleFormular', () => {
|
||||
propsData = {
|
||||
item: {
|
||||
userId: 0,
|
||||
roles: ['USER'],
|
||||
roles: ['ADMIN'],
|
||||
},
|
||||
}
|
||||
wrapper = Wrapper()
|
||||
@ -89,7 +89,7 @@ describe('ChangeUserRoleFormular', () => {
|
||||
propsData = {
|
||||
item: {
|
||||
userId: 1,
|
||||
roles: ['USER'],
|
||||
roles: [],
|
||||
},
|
||||
}
|
||||
wrapper = Wrapper()
|
||||
@ -121,7 +121,7 @@ describe('ChangeUserRoleFormular', () => {
|
||||
beforeEach(() => {
|
||||
apolloMutateMock.mockResolvedValue({
|
||||
data: {
|
||||
setUserRole: new Date(),
|
||||
setUserRole: 'ADMIN',
|
||||
},
|
||||
})
|
||||
propsData = {
|
||||
@ -135,7 +135,7 @@ describe('ChangeUserRoleFormular', () => {
|
||||
})
|
||||
|
||||
it('has selected option set to "usual user"', () => {
|
||||
expect(wrapper.find('select.role-select').element.value).toBe('user')
|
||||
expect(wrapper.find('select.role-select').element.value).toBe('USER')
|
||||
})
|
||||
|
||||
describe('change select to', () => {
|
||||
@ -188,13 +188,13 @@ describe('ChangeUserRoleFormular', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('emits "updateIsAdmin" with role moderator', () => {
|
||||
expect(wrapper.emitted('updateIsAdmin')).toEqual(
|
||||
it('emits "updateRoles" with role moderator', () => {
|
||||
expect(wrapper.emitted('updateRoles')).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.arrayContaining([
|
||||
{
|
||||
userId: 1,
|
||||
role: 'MODERATOR',
|
||||
roles: ['MODERATOR'],
|
||||
},
|
||||
]),
|
||||
]),
|
||||
@ -259,13 +259,13 @@ describe('ChangeUserRoleFormular', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('emits "updateIsAdmin" with role moderator', () => {
|
||||
expect(wrapper.emitted('updateIsAdmin')).toEqual(
|
||||
it('emits "updateRoles" with role moderator', () => {
|
||||
expect(wrapper.emitted('updateRoles')).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.arrayContaining([
|
||||
{
|
||||
userId: 1,
|
||||
role: 'ADMIN',
|
||||
roles: ['ADMIN'],
|
||||
},
|
||||
]),
|
||||
]),
|
||||
@ -296,6 +296,7 @@ describe('ChangeUserRoleFormular', () => {
|
||||
|
||||
describe('user has role "moderator"', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks()
|
||||
apolloMutateMock.mockResolvedValue({
|
||||
data: {
|
||||
setUserRole: null,
|
||||
@ -311,8 +312,8 @@ describe('ChangeUserRoleFormular', () => {
|
||||
rolesToSelect = wrapper.find('select.role-select').findAll('option')
|
||||
})
|
||||
|
||||
it('has selected option set to "moderator"', () => {
|
||||
expect(wrapper.find('select.role-select').element.value).toBe('moderator')
|
||||
it('has selected option set to "MODERATOR"', () => {
|
||||
expect(wrapper.find('select.role-select').element.value).toBe('MODERATOR')
|
||||
})
|
||||
|
||||
describe('change select to', () => {
|
||||
@ -323,7 +324,6 @@ describe('ChangeUserRoleFormular', () => {
|
||||
|
||||
it('does not call the API', () => {
|
||||
rolesToSelect.at(1).setSelected()
|
||||
// TODO: Fix this
|
||||
expect(apolloMutateMock).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@ -366,13 +366,13 @@ describe('ChangeUserRoleFormular', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('emits "updateIsAdmin"', () => {
|
||||
expect(wrapper.emitted('updateIsAdmin')).toEqual(
|
||||
it('emits "updateRoles"', () => {
|
||||
expect(wrapper.emitted('updateRoles')).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.arrayContaining([
|
||||
{
|
||||
userId: 1,
|
||||
role: 'USER',
|
||||
roles: [],
|
||||
},
|
||||
]),
|
||||
]),
|
||||
@ -437,13 +437,13 @@ describe('ChangeUserRoleFormular', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('emits "updateIsAdmin"', () => {
|
||||
expect(wrapper.emitted('updateIsAdmin')).toEqual(
|
||||
it('emits "updateRoles"', () => {
|
||||
expect(wrapper.emitted('updateRoles')).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.arrayContaining([
|
||||
{
|
||||
userId: 1,
|
||||
role: 'ADMIN',
|
||||
roles: ['ADMIN'],
|
||||
},
|
||||
]),
|
||||
]),
|
||||
@ -490,7 +490,7 @@ describe('ChangeUserRoleFormular', () => {
|
||||
})
|
||||
|
||||
it('has selected option set to "admin"', () => {
|
||||
expect(wrapper.find('select.role-select').element.value).toBe('admin')
|
||||
expect(wrapper.find('select.role-select').element.value).toBe('ADMIN')
|
||||
})
|
||||
|
||||
describe('change select to', () => {
|
||||
@ -544,13 +544,13 @@ describe('ChangeUserRoleFormular', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('emits "updateIsAdmin"', () => {
|
||||
expect(wrapper.emitted('updateIsAdmin')).toEqual(
|
||||
it('emits "updateRoles"', () => {
|
||||
expect(wrapper.emitted('updateRoles')).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.arrayContaining([
|
||||
{
|
||||
userId: 1,
|
||||
role: 'USER',
|
||||
roles: [],
|
||||
},
|
||||
]),
|
||||
]),
|
||||
@ -615,13 +615,13 @@ describe('ChangeUserRoleFormular', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('emits "updateIsAdmin"', () => {
|
||||
expect(wrapper.emitted('updateIsAdmin')).toEqual(
|
||||
it('emits "updateRoles"', () => {
|
||||
expect(wrapper.emitted('updateRoles')).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.arrayContaining([
|
||||
{
|
||||
userId: 1,
|
||||
role: 'MODERATOR',
|
||||
roles: ['MODERATOR'],
|
||||
},
|
||||
]),
|
||||
]),
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
<template>
|
||||
<div class="change-user-role-formular">
|
||||
<div class="shadow p-3 mb-5 bg-white rounded">
|
||||
<div v-if="item.userId === $store.state.moderator.id" class="m-3 mb-4">
|
||||
<div v-if="!$store.state.moderator.roles.includes('ADMIN')" class="m-3 mb-4">
|
||||
{{ roles.find((role) => role.value === currentRole).text }}
|
||||
</div>
|
||||
<div v-else-if="item.userId === $store.state.moderator.id" class="m-3 mb-4">
|
||||
{{ $t('userRole.notChangeYourSelf') }}
|
||||
</div>
|
||||
<div v-else class="m-3">
|
||||
@ -25,9 +28,9 @@
|
||||
import { setUserRole } from '../graphql/setUserRole'
|
||||
|
||||
const rolesValues = {
|
||||
admin: 'admin',
|
||||
moderator: 'moderator',
|
||||
user: 'user',
|
||||
ADMIN: 'ADMIN',
|
||||
MODERATOR: 'MODERATOR',
|
||||
USER: 'USER',
|
||||
}
|
||||
|
||||
export default {
|
||||
@ -40,23 +43,19 @@ export default {
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
// currentRole: this.item.isAdmin ? rolesValues.admin : rolesValues.user,
|
||||
currentRole: this.newFunction(),
|
||||
// roleSelected: this.item.isAdmin ? rolesValues.admin : rolesValues.user,
|
||||
roleSelected: this.newFunction(),
|
||||
currentRole: this.getCurrentRole(),
|
||||
roleSelected: this.getCurrentRole(),
|
||||
roles: [
|
||||
{ value: rolesValues.user, text: this.$t('userRole.selectRoles.user') },
|
||||
{ value: rolesValues.moderator, text: this.$t('userRole.selectRoles.moderator') },
|
||||
{ value: rolesValues.admin, text: this.$t('userRole.selectRoles.admin') },
|
||||
{ value: rolesValues.USER, text: this.$t('userRole.selectRoles.user') },
|
||||
{ value: rolesValues.MODERATOR, text: this.$t('userRole.selectRoles.moderator') },
|
||||
{ value: rolesValues.ADMIN, text: this.$t('userRole.selectRoles.admin') },
|
||||
],
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
newFunction() {
|
||||
let userRole = rolesValues.user
|
||||
if (this.item.roles.includes('ADMIN', 0)) userRole = rolesValues.admin
|
||||
else if (this.item.roles.includes('MODERATOR', 0)) userRole = rolesValues.moderator
|
||||
return userRole
|
||||
getCurrentRole() {
|
||||
if (this.item.roles.length) return rolesValues[this.item.roles[0]]
|
||||
return rolesValues.USER
|
||||
},
|
||||
showModal() {
|
||||
this.$bvModal
|
||||
@ -64,9 +63,9 @@ export default {
|
||||
this.$t('overlay.changeUserRole.question', {
|
||||
username: `${this.item.firstName} ${this.item.lastName}`,
|
||||
newRole:
|
||||
this.roleSelected === rolesValues.admin
|
||||
this.roleSelected === rolesValues.ADMIN
|
||||
? this.$t('userRole.selectRoles.admin')
|
||||
: this.roleSelected === rolesValues.moderator
|
||||
: this.roleSelected === rolesValues.MODERATOR
|
||||
? this.$t('userRole.selectRoles.moderator')
|
||||
: this.$t('userRole.selectRoles.user'),
|
||||
}),
|
||||
@ -93,19 +92,19 @@ export default {
|
||||
return role.value === newRole
|
||||
})
|
||||
const roleText = role.text
|
||||
const roleValue = role.value.toUpperCase()
|
||||
const roleValue = role.value
|
||||
this.$apollo
|
||||
.mutate({
|
||||
mutation: setUserRole,
|
||||
variables: {
|
||||
userId: this.item.userId,
|
||||
role: role.value.toUpperCase(),
|
||||
role: role.value,
|
||||
},
|
||||
})
|
||||
.then((result) => {
|
||||
this.$emit('updateIsAdmin', {
|
||||
this.$emit('updateRoles', {
|
||||
userId: this.item.userId,
|
||||
role: roleValue,
|
||||
roles: roleValue === 'USER' ? [] : [roleValue],
|
||||
})
|
||||
this.toastSuccess(
|
||||
this.$t('userRole.successfullyChangedTo', {
|
||||
|
||||
@ -100,15 +100,14 @@ describe('SearchUserTable', () => {
|
||||
|
||||
describe('isAdmin', () => {
|
||||
beforeEach(async () => {
|
||||
await wrapper.find('div.change-user-role-formular').vm.$emit('updateIsAdmin', {
|
||||
await wrapper.find('div.change-user-role-formular').vm.$emit('updateRoles', {
|
||||
userId: 1,
|
||||
// isAdmin: new Date(),
|
||||
role: 'ADMIN',
|
||||
roles: ['ADMIN'],
|
||||
})
|
||||
})
|
||||
|
||||
it('emits updateIsAdmin', () => {
|
||||
expect(wrapper.emitted('updateIsAdmin')).toEqual([[1, 'ADMIN']])
|
||||
expect(wrapper.emitted('updateRoles')).toEqual([[1, ['ADMIN']]])
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@ -79,7 +79,7 @@
|
||||
<transaction-link-list v-if="!row.item.deletedAt" :userId="row.item.userId" />
|
||||
</b-tab>
|
||||
<b-tab :title="$t('userRole.tabTitle')">
|
||||
<change-user-role-formular :item="row.item" @updateIsAdmin="updateIsAdmin" />
|
||||
<change-user-role-formular :item="row.item" @updateRoles="updateRoles" />
|
||||
</b-tab>
|
||||
<b-tab :title="$t('delete_user')">
|
||||
<deleted-user-formular :item="row.item" @updateDeletedAt="updateDeletedAt" />
|
||||
@ -127,8 +127,8 @@ export default {
|
||||
updateUserData(rowItem, newCreation) {
|
||||
rowItem.creation = newCreation
|
||||
},
|
||||
updateIsAdmin({ userId, role }) {
|
||||
this.$emit('updateIsAdmin', userId, role)
|
||||
updateRoles({ userId, roles }) {
|
||||
this.$emit('updateRoles', userId, roles)
|
||||
},
|
||||
updateDeletedAt({ userId, deletedAt }) {
|
||||
this.$emit('updateDeletedAt', userId, deletedAt)
|
||||
|
||||
@ -28,8 +28,6 @@ const mocks = {
|
||||
moderator: {
|
||||
firstName: 'Peter',
|
||||
lastName: 'Lustig',
|
||||
isAdmin: true,
|
||||
isModerator: false,
|
||||
roles: ['ADMIN'],
|
||||
id: 263,
|
||||
language: 'de',
|
||||
|
||||
@ -35,7 +35,7 @@ const apolloQueryMock = jest.fn().mockResolvedValue({
|
||||
lastName: 'Blümchen',
|
||||
email: 'benjamin@bluemchen.de',
|
||||
creation: [1000, 1000, 1000],
|
||||
roles: ['USER'],
|
||||
roles: [],
|
||||
emailChecked: true,
|
||||
deletedAt: new Date(),
|
||||
},
|
||||
@ -45,7 +45,7 @@ const apolloQueryMock = jest.fn().mockResolvedValue({
|
||||
lastName: 'Bloxberg',
|
||||
email: 'bibi@bloxberg.de',
|
||||
creation: [200, 400, 600],
|
||||
roles: ['USER'],
|
||||
roles: [],
|
||||
emailChecked: true,
|
||||
deletedAt: null,
|
||||
},
|
||||
@ -216,7 +216,7 @@ describe('UserSearch', () => {
|
||||
it('updates user role to admin', async () => {
|
||||
await wrapper
|
||||
.findComponent({ name: 'SearchUserTable' })
|
||||
.vm.$emit('updateIsAdmin', userId, 'ADMIN')
|
||||
.vm.$emit('updateRoles', userId, ['ADMIN'])
|
||||
expect(wrapper.vm.searchResult.find((obj) => obj.userId === userId).roles).toEqual([
|
||||
'ADMIN',
|
||||
])
|
||||
@ -227,10 +227,8 @@ describe('UserSearch', () => {
|
||||
it('updates user role to usual user', async () => {
|
||||
await wrapper
|
||||
.findComponent({ name: 'SearchUserTable' })
|
||||
.vm.$emit('updateIsAdmin', userId, 'USER')
|
||||
expect(wrapper.vm.searchResult.find((obj) => obj.userId === userId).roles).toEqual([
|
||||
'USER',
|
||||
])
|
||||
.vm.$emit('updateRoles', userId, [])
|
||||
expect(wrapper.vm.searchResult.find((obj) => obj.userId === userId).roles).toEqual([])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
type="PageUserSearch"
|
||||
:items="searchResult"
|
||||
:fields="fields"
|
||||
@updateIsAdmin="updateIsAdmin"
|
||||
@updateRoles="updateRoles"
|
||||
@updateDeletedAt="updateDeletedAt"
|
||||
/>
|
||||
<b-pagination
|
||||
@ -101,8 +101,8 @@ export default {
|
||||
this.toastError(error.message)
|
||||
})
|
||||
},
|
||||
updateIsAdmin(userId, role) {
|
||||
this.searchResult.find((obj) => obj.userId === userId).roles = [role]
|
||||
updateRoles(userId, roles) {
|
||||
this.searchResult.find((obj) => obj.userId === userId).roles = roles
|
||||
},
|
||||
updateDeletedAt(userId, deletedAt) {
|
||||
this.searchResult.find((obj) => obj.userId === userId).deletedAt = deletedAt
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user