PeerTube/shared/models/users/user-role.ts

43 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
}
export const USER_ROLE_LABELS: { [ id in UserRole ]: string } = {
[UserRole.USER]: 'User',
[UserRole.MODERATOR]: 'Moderator',
[UserRole.ADMINISTRATOR]: 'Administrator'
}
const userRoleRights: { [ id in UserRole ]: UserRight[] } = {
[UserRole.ADMINISTRATOR]: [
UserRight.ALL
],
[UserRole.MODERATOR]: [
UserRight.MANAGE_VIDEO_BLACKLIST,
2020-07-01 09:05:30 -05:00
UserRight.MANAGE_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,
UserRight.REMOVE_ANY_VIDEO_COMMENT,
UserRight.UPDATE_ANY_VIDEO,
UserRight.SEE_ALL_VIDEOS,
UserRight.MANAGE_ACCOUNTS_BLOCKLIST,
UserRight.MANAGE_SERVERS_BLOCKLIST,
UserRight.MANAGE_USERS
],
[UserRole.USER]: []
}
export function hasUserRight (userRole: UserRole, userRight: UserRight) {
const userRights = userRoleRights[userRole]
2020-02-28 09:03:39 -06:00
return userRights.includes(UserRight.ALL) || userRights.includes(userRight)
}