-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't show user management in app switcher if user has not role 'admi…
…n' (#7197) Don't show user management in app switcher if user has not role 'admin'
- Loading branch information
Jan
authored
Jun 30, 2022
1 parent
af2fe70
commit be987b1
Showing
11 changed files
with
178 additions
and
8 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
changelog/unreleased/bugfix-space-and-user-management-permissions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Bugfix: Create space and access user management permission | ||
|
||
We've fixed a bug, where users with insufficient permissions could access the user management and were able to see | ||
the "New Space" button in the space overview. | ||
|
||
https://github.com/owncloud/web/pull/7197 | ||
https://github.com/owncloud/web/issues/7181 | ||
https://github.com/owncloud/web/issues/7079 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import index from '../../src/index' | ||
|
||
describe('navItems', () => { | ||
describe('function "enabled"', () => { | ||
it('should be true if permissions are sufficient', () => { | ||
window.Vue = {} | ||
window.Vue.$permissionManager = { | ||
hasUserManagement: () => true | ||
} | ||
expect(index.navItems[0].enabled()).toBeTruthy() | ||
expect(index.navItems[1].enabled()).toBeTruthy() | ||
}) | ||
it('should be false if permissions are insufficient', () => { | ||
window.Vue = {} | ||
window.Vue.$permissionManager = { | ||
hasUserManagement: () => false | ||
} | ||
expect(index.navItems[0].enabled()).toBeFalsy() | ||
expect(index.navItems[1].enabled()).toBeFalsy() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './client' | ||
export * from './permissionManager' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Store } from 'vuex' | ||
interface Role { | ||
name: 'admin' | 'spaceadmin' | 'user' | 'guest' | ||
} | ||
interface User { | ||
role: Role | ||
} | ||
|
||
export class PermissionManager { | ||
private readonly store: Store<any> | ||
|
||
constructor(store: Store<any>) { | ||
this.store = store | ||
} | ||
|
||
public hasUserManagement() { | ||
return this.user.role.name === 'admin' | ||
} | ||
|
||
public hasSpaceManagement() { | ||
return ['admin', 'spaceadmin'].includes(this.user.role.name) | ||
} | ||
|
||
get user(): User { | ||
return this.store.getters.user | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
packages/web-pkg/tests/unit/services/permissionManager.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { PermissionManager } from '../../../src/services' | ||
|
||
beforeEach(jest.resetAllMocks) | ||
|
||
describe('permissionManager', () => { | ||
describe('method "hasUserManagement"', () => { | ||
it('should be true if user has sufficient rights', () => { | ||
const permissionManager = new PermissionManager({ | ||
getters: { user: { role: { name: 'admin' } } } | ||
} as any) | ||
expect(permissionManager.hasUserManagement()).toBeTruthy() | ||
}) | ||
it('should be false if user has insufficient rights', () => { | ||
const permissionManager = new PermissionManager({ | ||
getters: { user: { role: { name: 'user' } } } | ||
} as any) | ||
expect(permissionManager.hasUserManagement()).toBeFalsy() | ||
}) | ||
}) | ||
describe('method "hasSpaceManagement"', () => { | ||
it('should be true if user has sufficient rights', () => { | ||
const permissionManager = new PermissionManager({ | ||
getters: { user: { role: { name: 'admin' } } } | ||
} as any) | ||
expect(permissionManager.hasSpaceManagement()).toBeTruthy() | ||
}) | ||
it('should be false if user has insufficient rights', () => { | ||
const permissionManager = new PermissionManager({ | ||
getters: { user: { role: { name: 'user' } } } | ||
} as any) | ||
expect(permissionManager.hasSpaceManagement()).toBeFalsy() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters