-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't show user management in app switcher if user has not role 'admin' #7197
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
19b87a0
Don't show user management in app switcher if user has not role 'admin'
7ee2c9b
Add permissionManager
8c31983
Add permission check for create new space action
3d4bb55
Add changelog item
5789448
Switch to DI
d3a124e
Add permissionManager test
f3d208a
React on review
d9b26ec
Add tests
13e048d
Add tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to do both. Either set it on
prototype
or use reactiveset
. They both have the same result, so one is sufficient.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that.
If I only use set(vue, '$permissionManager', permissionManager), the permissionManager is accessible in /home/jan/working/web/packages/web-app-user-management/src/index.js but not in
/home/jan/working/web/packages/web-app-files/src/views/spaces/Projects.vue
and vice versa, I have no clue why this is the case :x