]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/models/users/user-role.ts
Add ability to list all local videos
[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 // TODO: use UserRole for key once https://github.com/Microsoft/TypeScript/issues/13042 is fixed
11 export const USER_ROLE_LABELS: { [ id: number ]: string } = {
12 [UserRole.USER]: 'User',
13 [UserRole.MODERATOR]: 'Moderator',
14 [UserRole.ADMINISTRATOR]: 'Administrator'
15 }
16
17 // TODO: use UserRole for key once https://github.com/Microsoft/TypeScript/issues/13042 is fixed
18 const userRoleRights: { [ id: number ]: UserRight[] } = {
19 [UserRole.ADMINISTRATOR]: [
20 UserRight.ALL
21 ],
22
23 [UserRole.MODERATOR]: [
24 UserRight.MANAGE_VIDEO_BLACKLIST,
25 UserRight.MANAGE_VIDEO_ABUSES,
26 UserRight.REMOVE_ANY_VIDEO,
27 UserRight.REMOVE_ANY_VIDEO_CHANNEL,
28 UserRight.REMOVE_ANY_VIDEO_COMMENT,
29 UserRight.UPDATE_ANY_VIDEO,
30 UserRight.SEE_ALL_VIDEOS
31 ],
32
33 [UserRole.USER]: []
34 }
35
36 export function hasUserRight (userRole: UserRole, userRight: UserRight) {
37 const userRights = userRoleRights[userRole]
38
39 return userRights.indexOf(UserRight.ALL) !== -1 || userRights.indexOf(userRight) !== -1
40 }