diff options
author | Chocobozzz <me@florianbigard.com> | 2019-12-12 15:47:47 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-12-12 16:51:59 +0100 |
commit | 22a73cb879a5cc775d4bec3d72fa9c9cf52e5175 (patch) | |
tree | 4c8d2d4f6fce8a520420ec83722fefc6d57b7a83 /server/models/video | |
parent | 91fa7960f42cff3481465bece3389007fbc278d3 (diff) | |
download | PeerTube-22a73cb879a5cc775d4bec3d72fa9c9cf52e5175.tar.gz PeerTube-22a73cb879a5cc775d4bec3d72fa9c9cf52e5175.tar.zst PeerTube-22a73cb879a5cc775d4bec3d72fa9c9cf52e5175.zip |
Add internal privacy mode
Diffstat (limited to 'server/models/video')
-rw-r--r-- | server/models/video/schedule-video-update.ts | 2 | ||||
-rw-r--r-- | server/models/video/video.ts | 55 |
2 files changed, 52 insertions, 5 deletions
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 |