-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hide admin page link for non-admin users
- Loading branch information
Showing
9 changed files
with
50 additions
and
32 deletions.
There are no files selected for viewing
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
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,10 @@ | ||
/** | ||
* Return true if `user` is an admin, otherwise return false. | ||
* | ||
* "Admin" meaning either a super admin, or admin of any organization. | ||
*/ | ||
function isAdmin(user) { | ||
return Boolean(user && (user.superAdmin || user.admin?.length > 0)); | ||
} | ||
|
||
export default isAdmin; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import isAdmin from '../../../src/util/user'; | ||
|
||
describe('Test admin check', () => { | ||
test('unconfigured user is not an admin', () => { | ||
expect(isAdmin({})).toBe(false); | ||
}); | ||
test('super admin is an admin', () => { | ||
expect(isAdmin({ superAdmin: true })).toBe(true); | ||
}); | ||
test('non-super admin is not an admin', () => { | ||
expect(isAdmin({ superAdmin: false })).toBe(false); | ||
}); | ||
test('falsy admin is not an admin', () => { | ||
expect(isAdmin({ admin: false })).toBe(false); | ||
}); | ||
test('empty admin is not an admin', () => { | ||
expect(isAdmin({ admin: [] })).toBe(false); | ||
}); | ||
test('admin of something is an admin', () => { | ||
expect(isAdmin({ admin: ['foo-corp'] })).toBe(true); | ||
}); | ||
test('admin of several things is an admin', () => { | ||
expect(isAdmin({ admin: ['foo-corp', 'bar-corp'] })).toBe(true); | ||
}); | ||
}); |