]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/models/users/user-role.ts
Add ability to delete comments
[github/Chocobozzz/PeerTube.git] / shared / models / users / user-role.ts
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 UserRight.REMOVE_ANY_VIDEO_COMMENT
28 ],
29
30 [UserRole.USER]: []
31 }
32
33 export function hasUserRight (userRole: UserRole, userRight: UserRight) {
34 const userRights = userRoleRights[userRole]
35
36 return userRights.indexOf(UserRight.ALL) !== -1 || userRights.indexOf(userRight) !== -1
37 }