From 22a73cb879a5cc775d4bec3d72fa9c9cf52e5175 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 12 Dec 2019 15:47:47 +0100 Subject: Add internal privacy mode --- server/models/account/user.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'server/models/account/user.ts') diff --git a/server/models/account/user.ts b/server/models/account/user.ts index 38c6d474a..522ea3310 100644 --- a/server/models/account/user.ts +++ b/server/models/account/user.ts @@ -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 { .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) } -- cgit v1.2.3