1
0
Fork 0
peertube/shared/models/users/user-role.ts

40 lines
1.1 KiB
TypeScript
Raw Normal View History

import { UserRight } from './user-right.enum'
// Keep the order
export enum UserRole {
ADMINISTRATOR = 0,
MODERATOR = 1,
USER = 2
}
2018-02-01 05:08:10 -05:00
// TODO: use UserRole for key once https://github.com/Microsoft/TypeScript/issues/13042 is fixed
export const USER_ROLE_LABELS: { [ id: number ]: string } = {
[UserRole.USER]: 'User',
[UserRole.MODERATOR]: 'Moderator',
[UserRole.ADMINISTRATOR]: 'Administrator'
}
// TODO: use UserRole for key once https://github.com/Microsoft/TypeScript/issues/13042 is fixed
const userRoleRights: { [ id: number ]: UserRight[] } = {
[UserRole.ADMINISTRATOR]: [
UserRight.ALL
],
[UserRole.MODERATOR]: [
UserRight.MANAGE_VIDEO_BLACKLIST,
UserRight.MANAGE_VIDEO_ABUSES,
UserRight.REMOVE_ANY_VIDEO,
2018-01-04 05:19:16 -05:00
UserRight.REMOVE_ANY_VIDEO_CHANNEL,
UserRight.REMOVE_ANY_VIDEO_COMMENT,
UserRight.UPDATE_ANY_VIDEO
],
[UserRole.USER]: []
}
export function hasUserRight (userRole: UserRole, userRight: UserRight) {
const userRights = userRoleRights[userRole]
return userRights.indexOf(UserRight.ALL) !== -1 || userRights.indexOf(userRight) !== -1
}