user-role.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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_PLAYLIST,
  25. UserRight.REMOVE_ANY_VIDEO_COMMENT,
  26. UserRight.UPDATE_ANY_VIDEO,
  27. UserRight.SEE_ALL_VIDEOS,
  28. UserRight.MANAGE_ACCOUNTS_BLOCKLIST,
  29. UserRight.MANAGE_SERVERS_BLOCKLIST,
  30. UserRight.MANAGE_USERS
  31. ],
  32. [UserRole.USER]: []
  33. }
  34. export function hasUserRight (userRole: UserRole, userRight: UserRight) {
  35. const userRights = userRoleRights[userRole]
  36. return userRights.indexOf(UserRight.ALL) !== -1 || userRights.indexOf(userRight) !== -1
  37. }