]>
Commit | Line | Data |
---|---|---|
954605a8 C |
1 | import { UserRight } from './user-right.enum' |
2 | ||
3 | // Keep the order | |
4 | export enum UserRole { | |
5 | ADMINISTRATOR = 0, | |
6 | MODERATOR = 1, | |
7 | USER = 2 | |
8 | } | |
9 | ||
10 | export 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 | |
17 | const 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 | ||
32 | export function hasUserRight (userRole: UserRole, userRight: UserRight) { | |
33 | const userRights = userRoleRights[userRole] | |
34 | ||
35 | return userRights.indexOf(UserRight.ALL) !== -1 || userRights.indexOf(userRight) !== -1 | |
36 | } |