aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/models/users/user-role.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-10-27 16:55:03 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-10-27 16:55:03 +0200
commit954605a804da399317ca62afa2fb9244afa11ebf (patch)
treede6ee69280bfb928bc01c29430e13d5b820e921a /shared/models/users/user-role.ts
parente02573ad67626210ed279bad321ee139094921a1 (diff)
downloadPeerTube-954605a804da399317ca62afa2fb9244afa11ebf.tar.gz
PeerTube-954605a804da399317ca62afa2fb9244afa11ebf.tar.zst
PeerTube-954605a804da399317ca62afa2fb9244afa11ebf.zip
Support roles with rights and add moderator role
Diffstat (limited to 'shared/models/users/user-role.ts')
-rw-r--r--shared/models/users/user-role.ts36
1 files changed, 36 insertions, 0 deletions
diff --git a/shared/models/users/user-role.ts b/shared/models/users/user-role.ts
new file mode 100644
index 000000000..cc32c768d
--- /dev/null
+++ b/shared/models/users/user-role.ts
@@ -0,0 +1,36 @@
1import { UserRight } from './user-right.enum'
2
3// Keep the order
4export enum UserRole {
5 ADMINISTRATOR = 0,
6 MODERATOR = 1,
7 USER = 2
8}
9
10export const USER_ROLE_LABELS = {
11 [UserRole.USER]: 'User',
12 [UserRole.MODERATOR]: 'Moderator',
13 [UserRole.ADMINISTRATOR]: 'Administrator'
14}
15
16// TODO: use UserRole for key once https://github.com/Microsoft/TypeScript/issues/13042 is fixed
17const userRoleRights: { [ id: number ]: UserRight[] } = {
18 [UserRole.ADMINISTRATOR]: [
19 UserRight.ALL
20 ],
21
22 [UserRole.MODERATOR]: [
23 UserRight.MANAGE_VIDEO_BLACKLIST,
24 UserRight.MANAGE_VIDEO_ABUSES,
25 UserRight.REMOVE_ANY_VIDEO,
26 UserRight.REMOVE_ANY_VIDEO_CHANNEL
27 ],
28
29 [UserRole.USER]: []
30}
31
32export function hasUserRight (userRole: UserRole, userRight: UserRight) {
33 const userRights = userRoleRights[userRole]
34
35 return userRights.indexOf(UserRight.ALL) !== -1 || userRights.indexOf(userRight) !== -1
36}