user-role.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { UserRight } from './user-right.enum'
  2. // Keep the order
  3. export enum UserRole {
  4. ADMINISTRATOR = 0,
  5. MODERATOR = 1,
  6. USER = 2
  7. }
  8. // TODO: use UserRole for key once https://github.com/Microsoft/TypeScript/issues/13042 is fixed
  9. export const USER_ROLE_LABELS: { [ id: number ]: string } = {
  10. [UserRole.USER]: 'User',
  11. [UserRole.MODERATOR]: 'Moderator',
  12. [UserRole.ADMINISTRATOR]: 'Administrator'
  13. }
  14. // TODO: use UserRole for key once https://github.com/Microsoft/TypeScript/issues/13042 is fixed
  15. const userRoleRights: { [ id: number ]: UserRight[] } = {
  16. [UserRole.ADMINISTRATOR]: [
  17. UserRight.ALL
  18. ],
  19. [UserRole.MODERATOR]: [
  20. UserRight.MANAGE_VIDEO_BLACKLIST,
  21. UserRight.MANAGE_VIDEO_ABUSES,
  22. UserRight.REMOVE_ANY_VIDEO,
  23. UserRight.REMOVE_ANY_VIDEO_CHANNEL,
  24. UserRight.REMOVE_ANY_VIDEO_COMMENT,
  25. UserRight.UPDATE_ANY_VIDEO,
  26. UserRight.SEE_ALL_VIDEOS,
  27. UserRight.MANAGE_ACCOUNTS_BLOCKLIST,
  28. UserRight.MANAGE_SERVERS_BLOCKLIST
  29. ],
  30. [UserRole.USER]: []
  31. }
  32. export function hasUserRight (userRole: UserRole, userRight: UserRight) {
  33. const userRights = userRoleRights[userRole]
  34. return userRights.indexOf(UserRight.ALL) !== -1 || userRights.indexOf(userRight) !== -1
  35. }