permissions.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import config from "config";
  2. import { UserRole } from "./schemas/user";
  3. const user = {};
  4. const dj = {
  5. "stations.autofill": true,
  6. "stations.blacklist": true,
  7. "stations.index": true,
  8. "stations.playback.toggle": true,
  9. "stations.queue.remove": true,
  10. "stations.queue.reposition": true,
  11. "stations.queue.reset": true,
  12. "stations.request": true,
  13. "stations.skip": true,
  14. "stations.view": true,
  15. "stations.view.manage": true
  16. };
  17. const owner = {
  18. ...dj,
  19. "stations.djs.add": true,
  20. "stations.djs.remove": true,
  21. "stations.remove": true,
  22. "stations.update": true
  23. };
  24. const moderator = {
  25. ...owner,
  26. "admin.view": true,
  27. "admin.view.import": true,
  28. "admin.view.news": true,
  29. "admin.view.playlists": true,
  30. "admin.view.punishments": true,
  31. "admin.view.reports": true,
  32. "admin.view.songs": true,
  33. "admin.view.stations": true,
  34. "admin.view.users": true,
  35. "admin.view.youtubeVideos": true,
  36. "apis.searchDiscogs": !!config.get("apis.discogs.enabled"),
  37. "news.create": true,
  38. "news.update": true,
  39. "playlists.create.admin": true,
  40. "playlists.get": true,
  41. "playlists.update.displayName": true,
  42. "playlists.update.privacy": true,
  43. "playlists.songs.add": true,
  44. "playlists.songs.remove": true,
  45. "playlists.songs.reposition": true,
  46. "playlists.view.others": true,
  47. "punishments.banIP": true,
  48. "punishments.get": true,
  49. "reports.get": true,
  50. "reports.update": true,
  51. "songs.create": true,
  52. "songs.get": true,
  53. "songs.update": true,
  54. "songs.verify": true,
  55. "stations.create.official": true,
  56. "stations.index": false,
  57. "stations.index.other": true,
  58. "stations.remove": false,
  59. "users.get": true,
  60. "users.ban": true,
  61. "users.requestPasswordReset": !!config.get("mail.enabled"),
  62. "users.resendVerifyEmail": !!config.get("mail.enabled"),
  63. "users.update": true,
  64. "youtube.requestSetAdmin": true,
  65. ...(config.get("experimental.soundcloud")
  66. ? {
  67. "admin.view.soundcloudTracks": true,
  68. "admin.view.soundcloud": true,
  69. "soundcloud.getArtist": true
  70. }
  71. : {}),
  72. ...(config.get("experimental.spotify")
  73. ? {
  74. "admin.view.spotify": true,
  75. "spotify.getTracksFromMediaSources": true,
  76. "spotify.getAlbumsFromIds": true,
  77. "spotify.getArtistsFromIds": true,
  78. "spotify.getAlternativeArtistSourcesForArtists": true,
  79. "spotify.getAlternativeAlbumSourcesForAlbums": true,
  80. "spotify.getAlternativeMediaSourcesForTracks": true,
  81. "admin.view.youtubeChannels": true,
  82. "youtube.getChannel": true
  83. }
  84. : {})
  85. };
  86. const admin = {
  87. ...moderator,
  88. "admin.view.dataRequests": true,
  89. "admin.view.statistics": true,
  90. "admin.view.youtube": true,
  91. "dataRequests.resolve": true,
  92. "media.recalculateAllRatings": true,
  93. "media.removeImportJobs": true,
  94. "news.remove": true,
  95. "playlists.clearAndRefill": true,
  96. "playlists.clearAndRefillAll": true,
  97. "playlists.createMissing": true,
  98. "playlists.deleteOrphaned": true,
  99. "playlists.removeAdmin": true,
  100. "playlists.requestOrphanedPlaylistSongs": true,
  101. "punishments.deactivate": true,
  102. "reports.remove": true,
  103. "songs.remove": true,
  104. "songs.updateAll": true,
  105. "stations.clearEveryStationQueue": true,
  106. "stations.remove": true,
  107. "users.remove": true,
  108. "users.remove.sessions": true,
  109. "users.update.restricted": true,
  110. "utils.getModules": true,
  111. "youtube.getApiRequest": true,
  112. "youtube.getMissingVideos": true,
  113. "youtube.resetStoredApiRequests": true,
  114. "youtube.removeStoredApiRequest": true,
  115. "youtube.removeVideos": true,
  116. "youtube.updateVideosV1ToV2": true,
  117. ...(config.get("experimental.soundcloud")
  118. ? {
  119. "soundcloud.fetchNewApiKey": true,
  120. "soundcloud.testApiKey": true
  121. }
  122. : {}),
  123. ...(config.get("experimental.spotify")
  124. ? {
  125. "youtube.getMissingChannels": true
  126. }
  127. : {})
  128. };
  129. const permissions: Record<
  130. UserRole | "owner" | "dj",
  131. Record<string, boolean>
  132. > = { user, dj, owner, moderator, admin };
  133. export default permissions;