aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/account/user.ts18
-rw-r--r--server/models/video/schedule-video-update.ts2
-rw-r--r--server/models/video/video.ts55
3 files changed, 68 insertions, 7 deletions
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 {
19 Table, 19 Table,
20 UpdatedAt 20 UpdatedAt
21} from 'sequelize-typescript' 21} from 'sequelize-typescript'
22import { hasUserRight, USER_ROLE_LABELS, UserRight } from '../../../shared' 22import { hasUserRight, USER_ROLE_LABELS, UserRight, VideoPrivacy } from '../../../shared'
23import { User, UserRole } from '../../../shared/models/users' 23import { User, UserRole } from '../../../shared/models/users'
24import { 24import {
25 isNoInstanceConfigWarningModal, 25 isNoInstanceConfigWarningModal,
@@ -63,7 +63,7 @@ import {
63 MUserFormattable, 63 MUserFormattable,
64 MUserId, 64 MUserId,
65 MUserNotifSettingChannelDefault, 65 MUserNotifSettingChannelDefault,
66 MUserWithNotificationSetting 66 MUserWithNotificationSetting, MVideoFullLight
67} from '@server/typings/models' 67} from '@server/typings/models'
68 68
69enum ScopeNames { 69enum ScopeNames {
@@ -575,6 +575,20 @@ export class UserModel extends Model<UserModel> {
575 .then(u => u.map(u => u.username)) 575 .then(u => u.map(u => u.username))
576 } 576 }
577 577
578 canGetVideo (video: MVideoFullLight) {
579 if (video.privacy === VideoPrivacy.INTERNAL) return true
580
581 if (video.privacy === VideoPrivacy.PRIVATE) {
582 return video.VideoChannel && video.VideoChannel.Account.userId === this.id
583 }
584
585 if (video.isBlacklisted()) {
586 return this.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST)
587 }
588
589 return false
590 }
591
578 hasRight (right: UserRight) { 592 hasRight (right: UserRight) {
579 return hasUserRight(this.role, right) 593 return hasUserRight(this.role, right)
580 } 594 }
diff --git a/server/models/video/schedule-video-update.ts b/server/models/video/schedule-video-update.ts
index eefc10f14..00b7f5524 100644
--- a/server/models/video/schedule-video-update.ts
+++ b/server/models/video/schedule-video-update.ts
@@ -26,7 +26,7 @@ export class ScheduleVideoUpdateModel extends Model<ScheduleVideoUpdateModel> {
26 @AllowNull(true) 26 @AllowNull(true)
27 @Default(null) 27 @Default(null)
28 @Column 28 @Column
29 privacy: VideoPrivacy.PUBLIC | VideoPrivacy.UNLISTED 29 privacy: VideoPrivacy.PUBLIC | VideoPrivacy.UNLISTED | VideoPrivacy.INTERNAL
30 30
31 @CreatedAt 31 @CreatedAt
32 createdAt: Date 32 createdAt: Date
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index af6fae0b6..7e18af497 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -348,9 +348,8 @@ export type AvailableForListIDsOptions = {
348 348
349 // Only list public/published videos 349 // Only list public/published videos
350 if (!options.filter || options.filter !== 'all-local') { 350 if (!options.filter || options.filter !== 'all-local') {
351 const privacyWhere = { 351
352 // Always list public videos 352 const publishWhere = {
353 privacy: VideoPrivacy.PUBLIC,
354 // Always list published videos, or videos that are being transcoded but on which we don't want to wait for transcoding 353 // Always list published videos, or videos that are being transcoded but on which we don't want to wait for transcoding
355 [ Op.or ]: [ 354 [ Op.or ]: [
356 { 355 {
@@ -364,8 +363,26 @@ export type AvailableForListIDsOptions = {
364 } 363 }
365 ] 364 ]
366 } 365 }
366 whereAnd.push(publishWhere)
367 367
368 whereAnd.push(privacyWhere) 368 // List internal videos if the user is logged in
369 if (options.user) {
370 const privacyWhere = {
371 [Op.or]: [
372 {
373 privacy: VideoPrivacy.INTERNAL
374 },
375 {
376 privacy: VideoPrivacy.PUBLIC
377 }
378 ]
379 }
380
381 whereAnd.push(privacyWhere)
382 } else { // Or only public videos
383 const privacyWhere = { privacy: VideoPrivacy.PUBLIC }
384 whereAnd.push(privacyWhere)
385 }
369 } 386 }
370 387
371 if (options.videoPlaylistId) { 388 if (options.videoPlaylistId) {
@@ -1773,6 +1790,10 @@ export class VideoModel extends Model<VideoModel> {
1773 } 1790 }
1774 } 1791 }
1775 1792
1793 private static isPrivacyForFederation (privacy: VideoPrivacy) {
1794 return privacy === VideoPrivacy.PUBLIC || privacy === VideoPrivacy.UNLISTED
1795 }
1796
1776 static getCategoryLabel (id: number) { 1797 static getCategoryLabel (id: number) {
1777 return VIDEO_CATEGORIES[ id ] || 'Misc' 1798 return VIDEO_CATEGORIES[ id ] || 'Misc'
1778 } 1799 }
@@ -1980,12 +2001,38 @@ export class VideoModel extends Model<VideoModel> {
1980 return isOutdated(this, ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL) 2001 return isOutdated(this, ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL)
1981 } 2002 }
1982 2003
2004 hasPrivacyForFederation () {
2005 return VideoModel.isPrivacyForFederation(this.privacy)
2006 }
2007
2008 isNewVideo (newPrivacy: VideoPrivacy) {
2009 return this.hasPrivacyForFederation() === false && VideoModel.isPrivacyForFederation(newPrivacy) === true
2010 }
2011
1983 setAsRefreshed () { 2012 setAsRefreshed () {
1984 this.changed('updatedAt', true) 2013 this.changed('updatedAt', true)
1985 2014
1986 return this.save() 2015 return this.save()
1987 } 2016 }
1988 2017
2018 requiresAuth () {
2019 return this.privacy === VideoPrivacy.PRIVATE || this.privacy === VideoPrivacy.INTERNAL || !!this.VideoBlacklist
2020 }
2021
2022 setPrivacy (newPrivacy: VideoPrivacy) {
2023 if (this.privacy === VideoPrivacy.PRIVATE && newPrivacy !== VideoPrivacy.PRIVATE) {
2024 this.publishedAt = new Date()
2025 }
2026
2027 this.privacy = newPrivacy
2028 }
2029
2030 isConfidential () {
2031 return this.privacy === VideoPrivacy.PRIVATE ||
2032 this.privacy === VideoPrivacy.UNLISTED ||
2033 this.privacy === VideoPrivacy.INTERNAL
2034 }
2035
1989 async publishIfNeededAndSave (t: Transaction) { 2036 async publishIfNeededAndSave (t: Transaction) {
1990 if (this.state !== VideoState.PUBLISHED) { 2037 if (this.state !== VideoState.PUBLISHED) {
1991 this.state = VideoState.PUBLISHED 2038 this.state = VideoState.PUBLISHED