2017-10-27 16:55:03 +02:00
|
|
|
import { UserRight } from './user-right.enum'
|
|
|
|
|
|
|
|
// Keep the order
|
|
|
|
export enum UserRole {
|
|
|
|
ADMINISTRATOR = 0,
|
|
|
|
MODERATOR = 1,
|
|
|
|
USER = 2
|
|
|
|
}
|
|
|
|
|
2020-01-30 11:53:38 +01:00
|
|
|
export const USER_ROLE_LABELS: { [ id in UserRole ]: string } = {
|
2017-10-27 16:55:03 +02:00
|
|
|
[UserRole.USER]: 'User',
|
|
|
|
[UserRole.MODERATOR]: 'Moderator',
|
|
|
|
[UserRole.ADMINISTRATOR]: 'Administrator'
|
|
|
|
}
|
|
|
|
|
2020-01-30 11:53:38 +01:00
|
|
|
const userRoleRights: { [ id in UserRole ]: UserRight[] } = {
|
2017-10-27 16:55:03 +02:00
|
|
|
[UserRole.ADMINISTRATOR]: [
|
|
|
|
UserRight.ALL
|
|
|
|
],
|
|
|
|
|
|
|
|
[UserRole.MODERATOR]: [
|
|
|
|
UserRight.MANAGE_VIDEO_BLACKLIST,
|
|
|
|
UserRight.MANAGE_VIDEO_ABUSES,
|
|
|
|
UserRight.REMOVE_ANY_VIDEO,
|
2018-01-04 11:19:16 +01:00
|
|
|
UserRight.REMOVE_ANY_VIDEO_CHANNEL,
|
2019-02-26 10:55:40 +01:00
|
|
|
UserRight.REMOVE_ANY_VIDEO_PLAYLIST,
|
2018-02-22 09:03:45 +01:00
|
|
|
UserRight.REMOVE_ANY_VIDEO_COMMENT,
|
2018-10-10 11:46:50 +02:00
|
|
|
UserRight.UPDATE_ANY_VIDEO,
|
2018-10-15 13:03:04 +02:00
|
|
|
UserRight.SEE_ALL_VIDEOS,
|
|
|
|
UserRight.MANAGE_ACCOUNTS_BLOCKLIST,
|
2019-01-04 08:56:20 +01:00
|
|
|
UserRight.MANAGE_SERVERS_BLOCKLIST,
|
|
|
|
UserRight.MANAGE_USERS
|
2017-10-27 16:55:03 +02:00
|
|
|
],
|
|
|
|
|
|
|
|
[UserRole.USER]: []
|
|
|
|
}
|
|
|
|
|
|
|
|
export function hasUserRight (userRole: UserRole, userRight: UserRight) {
|
|
|
|
const userRights = userRoleRights[userRole]
|
|
|
|
|
2020-02-28 16:03:39 +01:00
|
|
|
return userRights.includes(UserRight.ALL) || userRights.includes(userRight)
|
2017-10-27 16:55:03 +02:00
|
|
|
}
|