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/controllers/api/videos/index.ts | 24 ++++++++++-------------- server/controllers/api/videos/ownership.ts | 4 ++-- 2 files changed, 12 insertions(+), 16 deletions(-) (limited to 'server/controllers/api') diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 337795541..35f0b3152 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -326,9 +326,8 @@ async function updateVideo (req: express.Request, res: express.Response) { const oldVideoAuditView = new VideoAuditView(videoInstance.toFormattedDetailsJSON()) const videoInfoToUpdate: VideoUpdate = req.body - const wasPrivateVideo = videoInstance.privacy === VideoPrivacy.PRIVATE - const wasNotPrivateVideo = videoInstance.privacy !== VideoPrivacy.PRIVATE - const wasUnlistedVideo = videoInstance.privacy === VideoPrivacy.UNLISTED + const wasConfidentialVideo = videoInstance.isConfidential() + const hadPrivacyForFederation = videoInstance.hasPrivacyForFederation() // Process thumbnail or create it from the video const thumbnailModel = req.files && req.files['thumbnailfile'] @@ -359,17 +358,15 @@ async function updateVideo (req: express.Request, res: express.Response) { videoInstance.originallyPublishedAt = new Date(videoInfoToUpdate.originallyPublishedAt) } + let isNewVideo = false if (videoInfoToUpdate.privacy !== undefined) { - const newPrivacy = parseInt(videoInfoToUpdate.privacy.toString(), 10) - videoInstance.privacy = newPrivacy + isNewVideo = videoInstance.isNewVideo(videoInfoToUpdate.privacy) - // The video was private, and is not anymore -> publish it - if (wasPrivateVideo === true && newPrivacy !== VideoPrivacy.PRIVATE) { - videoInstance.publishedAt = new Date() - } + const newPrivacy = parseInt(videoInfoToUpdate.privacy.toString(), 10) + videoInstance.setPrivacy(newPrivacy) - // The video was not private, but now it is -> we need to unfederate it - if (wasNotPrivateVideo === true && newPrivacy === VideoPrivacy.PRIVATE) { + // Unfederate the video if the new privacy is not compatible with federation + if (hadPrivacyForFederation && !videoInstance.hasPrivacyForFederation()) { await VideoModel.sendDelete(videoInstance, { transaction: t }) } } @@ -392,7 +389,7 @@ async function updateVideo (req: express.Request, res: express.Response) { await videoInstanceUpdated.$set('VideoChannel', res.locals.videoChannel, { transaction: t }) videoInstanceUpdated.VideoChannel = res.locals.videoChannel - if (wasPrivateVideo === false) await changeVideoChannelShare(videoInstanceUpdated, oldVideoChannel, t) + if (hadPrivacyForFederation === true) await changeVideoChannelShare(videoInstanceUpdated, oldVideoChannel, t) } // Schedule an update in the future? @@ -414,7 +411,6 @@ async function updateVideo (req: express.Request, res: express.Response) { transaction: t }) - const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t) auditLogger.update( @@ -427,7 +423,7 @@ async function updateVideo (req: express.Request, res: express.Response) { return videoInstanceUpdated }) - if (wasUnlistedVideo || wasPrivateVideo) { + if (wasConfidentialVideo) { Notifier.Instance.notifyOnNewVideoIfNeeded(videoInstanceUpdated) } diff --git a/server/controllers/api/videos/ownership.ts b/server/controllers/api/videos/ownership.ts index abb34082e..41d7cdc43 100644 --- a/server/controllers/api/videos/ownership.ts +++ b/server/controllers/api/videos/ownership.ts @@ -12,7 +12,7 @@ import { videosTerminateChangeOwnershipValidator } from '../../../middlewares' import { VideoChangeOwnershipModel } from '../../../models/video/video-change-ownership' -import { VideoChangeOwnershipStatus, VideoPrivacy, VideoState } from '../../../../shared/models/videos' +import { VideoChangeOwnershipStatus, VideoState } from '../../../../shared/models/videos' import { VideoChannelModel } from '../../../models/video/video-channel' import { getFormattedObjects } from '../../../helpers/utils' import { changeVideoChannelShare } from '../../../lib/activitypub' @@ -111,7 +111,7 @@ async function acceptOwnership (req: express.Request, res: express.Response) { const targetVideoUpdated = await targetVideo.save({ transaction: t }) as MVideoFullLight targetVideoUpdated.VideoChannel = channel - if (targetVideoUpdated.privacy !== VideoPrivacy.PRIVATE && targetVideoUpdated.state === VideoState.PUBLISHED) { + if (targetVideoUpdated.hasPrivacyForFederation() && targetVideoUpdated.state === VideoState.PUBLISHED) { await changeVideoChannelShare(targetVideoUpdated, oldVideoChannel, t) await sendUpdateVideo(targetVideoUpdated, t, oldVideoChannel.Account.Actor) } -- cgit v1.2.3