2017-10-27 09:55:03 -05:00
|
|
|
import { UserRight } from './user-right.enum'
|
|
|
|
|
|
|
|
// Keep the order
|
|
|
|
export enum UserRole {
|
|
|
|
ADMINISTRATOR = 0,
|
|
|
|
MODERATOR = 1,
|
|
|
|
USER = 2
|
|
|
|
}
|
|
|
|
|
2018-02-01 04:08:10 -06:00
|
|
|
// TODO: use UserRole for key once https://github.com/Microsoft/TypeScript/issues/13042 is fixed
|
|
|
|
export const USER_ROLE_LABELS: { [ id: number ]: string } = {
|
2017-10-27 09:55:03 -05:00
|
|
|
[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 04:19:16 -06:00
|
|
|
UserRight.REMOVE_ANY_VIDEO_CHANNEL,
|
2019-02-26 03:55:40 -06:00
|
|
|
UserRight.REMOVE_ANY_VIDEO_PLAYLIST,
|
2018-02-22 02:03:45 -06:00
|
|
|
UserRight.REMOVE_ANY_VIDEO_COMMENT,
|
2018-10-10 04:46:50 -05:00
|
|
|
UserRight.UPDATE_ANY_VIDEO,
|
2018-10-15 06:03:04 -05:00
|
|
|
UserRight.SEE_ALL_VIDEOS,
|
|
|
|
UserRight.MANAGE_ACCOUNTS_BLOCKLIST,
|
2019-01-04 01:56:20 -06:00
|
|
|
UserRight.MANAGE_SERVERS_BLOCKLIST,
|
|
|
|
UserRight.MANAGE_USERS
|
2017-10-27 09:55:03 -05:00
|
|
|
],
|
|
|
|
|
|
|
|
[UserRole.USER]: []
|
|
|
|
}
|
|
|
|
|
|
|
|
export function hasUserRight (userRole: UserRole, userRight: UserRight) {
|
|
|
|
const userRights = userRoleRights[userRole]
|
|
|
|
|
|
|
|
return userRights.indexOf(UserRight.ALL) !== -1 || userRights.indexOf(userRight) !== -1
|
|
|
|
}
|