aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/models/users/user-role.ts
diff options
context:
space:
mode:
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}