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/lib/activitypub/send/send-create.ts | 2 +- server/lib/activitypub/send/send-update.ts | 2 +- server/lib/activitypub/share.ts | 5 ++--- server/lib/activitypub/videos.ts | 2 +- server/lib/client-html.ts | 2 +- server/lib/schedulers/update-videos-scheduler.ts | 10 ++++------ 6 files changed, 10 insertions(+), 13 deletions(-) (limited to 'server/lib') diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts index edbc14a73..1709d8348 100644 --- a/server/lib/activitypub/send/send-create.ts +++ b/server/lib/activitypub/send/send-create.ts @@ -18,7 +18,7 @@ import { } from '../../../typings/models' async function sendCreateVideo (video: MVideoAP, t: Transaction) { - if (video.privacy === VideoPrivacy.PRIVATE) return undefined + if (!video.hasPrivacyForFederation()) return undefined logger.info('Creating job to send video creation of %s.', video.url) diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.ts index 44e0e1161..cb14b8dbf 100644 --- a/server/lib/activitypub/send/send-update.ts +++ b/server/lib/activitypub/send/send-update.ts @@ -25,7 +25,7 @@ import { async function sendUpdateVideo (videoArg: MVideoAPWithoutCaption, t: Transaction, overrodeByActor?: MActor) { const video = videoArg as MVideoAP - if (video.privacy === VideoPrivacy.PRIVATE) return undefined + if (!video.hasPrivacyForFederation()) return undefined logger.info('Creating job to update video %s.', video.url) diff --git a/server/lib/activitypub/share.ts b/server/lib/activitypub/share.ts index fdca9bed7..e847c4b7d 100644 --- a/server/lib/activitypub/share.ts +++ b/server/lib/activitypub/share.ts @@ -1,5 +1,4 @@ import { Transaction } from 'sequelize' -import { VideoPrivacy } from '../../../shared/models/videos' import { getServerActor } from '../../helpers/utils' import { VideoShareModel } from '../../models/video/video-share' import { sendUndoAnnounce, sendVideoAnnounce } from './send' @@ -10,10 +9,10 @@ import { getOrCreateActorAndServerAndModel } from './actor' import { logger } from '../../helpers/logger' import { CRAWL_REQUEST_CONCURRENCY } from '../../initializers/constants' import { checkUrlsSameHost, getAPId } from '../../helpers/activitypub' -import { MChannelActor, MChannelActorLight, MVideo, MVideoAccountLight, MVideoId } from '../../typings/models/video' +import { MChannelActorLight, MVideo, MVideoAccountLight, MVideoId } from '../../typings/models/video' async function shareVideoByServerAndChannel (video: MVideoAccountLight, t: Transaction) { - if (video.privacy === VideoPrivacy.PRIVATE) return undefined + if (!video.hasPrivacyForFederation()) return undefined return Promise.all([ shareByServer(video, t), diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index d80173e03..2fb1f8d49 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts @@ -79,7 +79,7 @@ async function federateVideoIfNeeded (videoArg: MVideoAPWithoutCaption, isNewVid // Check this is not a blacklisted video, or unfederated blacklisted video (video.isBlacklisted() === false || (isNewVideo === false && video.VideoBlacklist.unfederated === false)) && // Check the video is public/unlisted and published - video.privacy !== VideoPrivacy.PRIVATE && video.state === VideoState.PUBLISHED + video.hasPrivacyForFederation() && video.state === VideoState.PUBLISHED ) { // Fetch more attributes that we will need to serialize in AP object if (isArray(video.VideoCaptions) === false) { diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts index a1f4ae858..42a30f84f 100644 --- a/server/lib/client-html.ts +++ b/server/lib/client-html.ts @@ -46,7 +46,7 @@ export class ClientHtml { ]) // Let Angular application handle errors - if (!video || video.privacy === VideoPrivacy.PRIVATE || video.VideoBlacklist) { + if (!video || video.privacy === VideoPrivacy.PRIVATE || video.privacy === VideoPrivacy.INTERNAL || video.VideoBlacklist) { return ClientHtml.getIndexHTML(req, res) } diff --git a/server/lib/schedulers/update-videos-scheduler.ts b/server/lib/schedulers/update-videos-scheduler.ts index 293bba91f..350a335d3 100644 --- a/server/lib/schedulers/update-videos-scheduler.ts +++ b/server/lib/schedulers/update-videos-scheduler.ts @@ -35,16 +35,14 @@ export class UpdateVideosScheduler extends AbstractScheduler { logger.info('Executing scheduled video update on %s.', video.uuid) if (schedule.privacy) { - const oldPrivacy = video.privacy - const isNewVideo = oldPrivacy === VideoPrivacy.PRIVATE - - video.privacy = schedule.privacy - if (isNewVideo === true) video.publishedAt = new Date() + const wasConfidentialVideo = video.isConfidential() + const isNewVideo = video.isNewVideo(schedule.privacy) + video.setPrivacy(schedule.privacy) await video.save({ transaction: t }) await federateVideoIfNeeded(video, isNewVideo, t) - if (oldPrivacy === VideoPrivacy.UNLISTED || oldPrivacy === VideoPrivacy.PRIVATE) { + if (wasConfidentialVideo) { const videoToPublish: MVideoFullLight = Object.assign(video, { ScheduleVideoUpdate: schedule, UserVideoHistories: [] }) publishedVideos.push(videoToPublish) } -- cgit v1.2.3