]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/account/user.ts
Add internal privacy mode
[github/Chocobozzz/PeerTube.git] / server / models / account / user.ts
index 38c6d474aa2e6916ce7170bcf28a58512a214666..522ea33109189b4a43ffd21f105217b775b78722 100644 (file)
@@ -19,7 +19,7 @@ import {
   Table,
   UpdatedAt
 } from 'sequelize-typescript'
-import { hasUserRight, USER_ROLE_LABELS, UserRight } from '../../../shared'
+import { hasUserRight, USER_ROLE_LABELS, UserRight, VideoPrivacy } from '../../../shared'
 import { User, UserRole } from '../../../shared/models/users'
 import {
   isNoInstanceConfigWarningModal,
@@ -63,7 +63,7 @@ import {
   MUserFormattable,
   MUserId,
   MUserNotifSettingChannelDefault,
-  MUserWithNotificationSetting
+  MUserWithNotificationSetting, MVideoFullLight
 } from '@server/typings/models'
 
 enum ScopeNames {
@@ -575,6 +575,20 @@ export class UserModel extends Model<UserModel> {
                     .then(u => u.map(u => u.username))
   }
 
+  canGetVideo (video: MVideoFullLight) {
+    if (video.privacy === VideoPrivacy.INTERNAL) return true
+
+    if (video.privacy === VideoPrivacy.PRIVATE) {
+      return video.VideoChannel && video.VideoChannel.Account.userId === this.id
+    }
+
+    if (video.isBlacklisted()) {
+      return this.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST)
+    }
+
+    return false
+  }
+
   hasRight (right: UserRight) {
     return hasUserRight(this.role, right)
   }