mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
remove isAdmin from guards, simplify logic
This commit is contained in:
parent
fdf40a6ec7
commit
d82a994eeb
@ -26,7 +26,6 @@ export const searchUsers = gql`
|
||||
hasElopage
|
||||
emailConfirmationSend
|
||||
deletedAt
|
||||
# isAdmin
|
||||
roles
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,10 +13,8 @@ const addNavigationGuards = (router, store, apollo, i18n) => {
|
||||
})
|
||||
.then((result) => {
|
||||
const moderator = result.data.verifyLogin
|
||||
if (moderator.roles.includes('ADMIN', 0) || moderator.roles.includes('MODERATOR', 0)) {
|
||||
if (moderator.roles?.length) {
|
||||
i18n.locale = moderator.language
|
||||
moderator.isAdmin = moderator.roles.includes('ADMIN', 0)
|
||||
moderator.isModerator = moderator.roles.includes('MODERATOR', 0)
|
||||
store.commit('moderator', moderator)
|
||||
next({ path: '/' })
|
||||
} else {
|
||||
@ -37,7 +35,7 @@ const addNavigationGuards = (router, store, apollo, i18n) => {
|
||||
!CONFIG.DEBUG_DISABLE_AUTH && // we did not disabled the auth module for debug purposes
|
||||
(!store.state.token || // we do not have a token
|
||||
!store.state.moderator || // no moderator set in store
|
||||
!(store.state.moderator.isAdmin || store.state.moderator.isModerator)) && // user is no admin
|
||||
!store.state.moderator.roles.length) && // user is no admin
|
||||
to.path !== '/not-found' && // we are not on `not-found`
|
||||
to.path !== '/logout' // we are not on `logout`
|
||||
) {
|
||||
|
||||
@ -54,8 +54,6 @@ describe('navigation guards', () => {
|
||||
it('commits the moderator to the store', () => {
|
||||
expect(storeCommitMock).toBeCalledWith('moderator', {
|
||||
roles: ['ADMIN'],
|
||||
isAdmin: true,
|
||||
isModerator: false,
|
||||
language: 'de',
|
||||
})
|
||||
})
|
||||
@ -90,8 +88,6 @@ describe('navigation guards', () => {
|
||||
it('commits the moderator to the store', () => {
|
||||
expect(storeCommitMock).toBeCalledWith('moderator', {
|
||||
roles: ['MODERATOR'],
|
||||
isAdmin: false,
|
||||
isModerator: true,
|
||||
language: 'de',
|
||||
})
|
||||
})
|
||||
@ -103,6 +99,7 @@ describe('navigation guards', () => {
|
||||
|
||||
describe('with valid token and no roles', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks()
|
||||
apolloQueryMock.mockResolvedValue({
|
||||
data: {
|
||||
verifyLogin: {
|
||||
@ -119,7 +116,7 @@ describe('navigation guards', () => {
|
||||
})
|
||||
|
||||
it('does not commit the moderator to the store', () => {
|
||||
expect(storeCommitMock).not.toBeCalledWith('moderator', { isAdmin: false })
|
||||
expect(storeCommitMock).not.toBeCalledWith('moderator')
|
||||
})
|
||||
|
||||
it('redirects to /not-found', async () => {
|
||||
@ -178,14 +175,14 @@ describe('navigation guards', () => {
|
||||
|
||||
it('does not redirect with token in store and as admin', () => {
|
||||
store.state.token = 'valid token'
|
||||
store.state.moderator = { isAdmin: true }
|
||||
store.state.moderator = { roles: ['ADMIN'] }
|
||||
navGuard({ path: '/' }, {}, next)
|
||||
expect(next).toBeCalledWith()
|
||||
})
|
||||
|
||||
it('does not redirect with token in store and as moderator', () => {
|
||||
store.state.token = 'valid token'
|
||||
store.state.moderator = { isModerator: true }
|
||||
store.state.moderator = { roles: ['MODERATOR'] }
|
||||
navGuard({ path: '/' }, {}, next)
|
||||
expect(next).toBeCalledWith()
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user