1
0
Fork 0

Add internal privacy mode

This commit is contained in:
Chocobozzz 2019-12-12 15:47:47 +01:00
parent 91fa7960f4
commit 22a73cb879
No known key found for this signature in database
GPG key ID: 583A612D890159BE
19 changed files with 217 additions and 88 deletions

View file

@ -59,7 +59,7 @@ export class VideoDownloadComponent {
return return
} }
const suffix = this.video.privacy.id === VideoPrivacy.PRIVATE const suffix = this.video.privacy.id === VideoPrivacy.PRIVATE || this.video.privacy.id === VideoPrivacy.INTERNAL
? '?access_token=' + this.auth.getAccessToken() ? '?access_token=' + this.auth.getAccessToken()
: '' : ''

View file

@ -332,18 +332,26 @@ export class VideoService implements VideosProvider {
} }
explainedPrivacyLabels (privacies: VideoConstant<VideoPrivacy>[]) { explainedPrivacyLabels (privacies: VideoConstant<VideoPrivacy>[]) {
const newPrivacies = privacies.slice() const base = [
{
id: VideoPrivacy.PRIVATE,
label: this.i18n('Only I can see this video')
},
{
id: VideoPrivacy.UNLISTED,
label: this.i18n('Only people with the private link can see this video')
},
{
id: VideoPrivacy.PUBLIC,
label: this.i18n('Anyone can see this video')
},
{
id: VideoPrivacy.INTERNAL,
label: this.i18n('Only users of this instance can see this video')
}
]
const privatePrivacy = newPrivacies.find(p => p.id === VideoPrivacy.PRIVATE) return base.filter(o => !!privacies.find(p => p.id === o.id))
if (privatePrivacy) privatePrivacy.label = this.i18n('Only I can see this video')
const unlistedPrivacy = newPrivacies.find(p => p.id === VideoPrivacy.UNLISTED)
if (unlistedPrivacy) unlistedPrivacy.label = this.i18n('Only people with the private link can see this video')
const publicPrivacy = newPrivacies.find(p => p.id === VideoPrivacy.PUBLIC)
if (publicPrivacy) publicPrivacy.label = this.i18n('Anyone can see this video')
return privacies
} }
private setVideoRate (id: number, rateType: UserVideoRateType) { private setVideoRate (id: number, rateType: UserVideoRateType) {

View file

@ -326,9 +326,8 @@ async function updateVideo (req: express.Request, res: express.Response) {
const oldVideoAuditView = new VideoAuditView(videoInstance.toFormattedDetailsJSON()) const oldVideoAuditView = new VideoAuditView(videoInstance.toFormattedDetailsJSON())
const videoInfoToUpdate: VideoUpdate = req.body const videoInfoToUpdate: VideoUpdate = req.body
const wasPrivateVideo = videoInstance.privacy === VideoPrivacy.PRIVATE const wasConfidentialVideo = videoInstance.isConfidential()
const wasNotPrivateVideo = videoInstance.privacy !== VideoPrivacy.PRIVATE const hadPrivacyForFederation = videoInstance.hasPrivacyForFederation()
const wasUnlistedVideo = videoInstance.privacy === VideoPrivacy.UNLISTED
// Process thumbnail or create it from the video // Process thumbnail or create it from the video
const thumbnailModel = req.files && req.files['thumbnailfile'] 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) videoInstance.originallyPublishedAt = new Date(videoInfoToUpdate.originallyPublishedAt)
} }
let isNewVideo = false
if (videoInfoToUpdate.privacy !== undefined) { if (videoInfoToUpdate.privacy !== undefined) {
isNewVideo = videoInstance.isNewVideo(videoInfoToUpdate.privacy)
const newPrivacy = parseInt(videoInfoToUpdate.privacy.toString(), 10) const newPrivacy = parseInt(videoInfoToUpdate.privacy.toString(), 10)
videoInstance.privacy = newPrivacy videoInstance.setPrivacy(newPrivacy)
// The video was private, and is not anymore -> publish it // Unfederate the video if the new privacy is not compatible with federation
if (wasPrivateVideo === true && newPrivacy !== VideoPrivacy.PRIVATE) { if (hadPrivacyForFederation && !videoInstance.hasPrivacyForFederation()) {
videoInstance.publishedAt = new Date()
}
// The video was not private, but now it is -> we need to unfederate it
if (wasNotPrivateVideo === true && newPrivacy === VideoPrivacy.PRIVATE) {
await VideoModel.sendDelete(videoInstance, { transaction: t }) 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 }) await videoInstanceUpdated.$set('VideoChannel', res.locals.videoChannel, { transaction: t })
videoInstanceUpdated.VideoChannel = res.locals.videoChannel 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? // Schedule an update in the future?
@ -414,7 +411,6 @@ async function updateVideo (req: express.Request, res: express.Response) {
transaction: t transaction: t
}) })
const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE
await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t) await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t)
auditLogger.update( auditLogger.update(
@ -427,7 +423,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
return videoInstanceUpdated return videoInstanceUpdated
}) })
if (wasUnlistedVideo || wasPrivateVideo) { if (wasConfidentialVideo) {
Notifier.Instance.notifyOnNewVideoIfNeeded(videoInstanceUpdated) Notifier.Instance.notifyOnNewVideoIfNeeded(videoInstanceUpdated)
} }

View file

@ -12,7 +12,7 @@ import {
videosTerminateChangeOwnershipValidator videosTerminateChangeOwnershipValidator
} from '../../../middlewares' } from '../../../middlewares'
import { VideoChangeOwnershipModel } from '../../../models/video/video-change-ownership' 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 { VideoChannelModel } from '../../../models/video/video-channel'
import { getFormattedObjects } from '../../../helpers/utils' import { getFormattedObjects } from '../../../helpers/utils'
import { changeVideoChannelShare } from '../../../lib/activitypub' 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 const targetVideoUpdated = await targetVideo.save({ transaction: t }) as MVideoFullLight
targetVideoUpdated.VideoChannel = channel 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 changeVideoChannelShare(targetVideoUpdated, oldVideoChannel, t)
await sendUpdateVideo(targetVideoUpdated, t, oldVideoChannel.Account.Actor) await sendUpdateVideo(targetVideoUpdated, t, oldVideoChannel.Account.Actor)
} }

View file

@ -102,7 +102,7 @@ function isVideoPrivacyValid (value: number) {
} }
function isScheduleVideoUpdatePrivacyValid (value: number) { function isScheduleVideoUpdatePrivacyValid (value: number) {
return value === VideoPrivacy.UNLISTED || value === VideoPrivacy.PUBLIC return value === VideoPrivacy.UNLISTED || value === VideoPrivacy.PUBLIC || value === VideoPrivacy.INTERNAL
} }
function isVideoOriginallyPublishedAtValid (value: string | null) { function isVideoOriginallyPublishedAtValid (value: string | null) {

View file

@ -353,7 +353,8 @@ let VIDEO_LANGUAGES: { [id: string]: string } = {}
const VIDEO_PRIVACIES = { const VIDEO_PRIVACIES = {
[ VideoPrivacy.PUBLIC ]: 'Public', [ VideoPrivacy.PUBLIC ]: 'Public',
[ VideoPrivacy.UNLISTED ]: 'Unlisted', [ VideoPrivacy.UNLISTED ]: 'Unlisted',
[ VideoPrivacy.PRIVATE ]: 'Private' [ VideoPrivacy.PRIVATE ]: 'Private',
[ VideoPrivacy.INTERNAL ]: 'Internal'
} }
const VIDEO_STATES = { const VIDEO_STATES = {

View file

@ -18,7 +18,7 @@ import {
} from '../../../typings/models' } from '../../../typings/models'
async function sendCreateVideo (video: MVideoAP, t: Transaction) { 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) logger.info('Creating job to send video creation of %s.', video.url)

View file

@ -25,7 +25,7 @@ import {
async function sendUpdateVideo (videoArg: MVideoAPWithoutCaption, t: Transaction, overrodeByActor?: MActor) { async function sendUpdateVideo (videoArg: MVideoAPWithoutCaption, t: Transaction, overrodeByActor?: MActor) {
const video = videoArg as MVideoAP 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) logger.info('Creating job to update video %s.', video.url)

View file

@ -1,5 +1,4 @@
import { Transaction } from 'sequelize' import { Transaction } from 'sequelize'
import { VideoPrivacy } from '../../../shared/models/videos'
import { getServerActor } from '../../helpers/utils' import { getServerActor } from '../../helpers/utils'
import { VideoShareModel } from '../../models/video/video-share' import { VideoShareModel } from '../../models/video/video-share'
import { sendUndoAnnounce, sendVideoAnnounce } from './send' import { sendUndoAnnounce, sendVideoAnnounce } from './send'
@ -10,10 +9,10 @@ import { getOrCreateActorAndServerAndModel } from './actor'
import { logger } from '../../helpers/logger' import { logger } from '../../helpers/logger'
import { CRAWL_REQUEST_CONCURRENCY } from '../../initializers/constants' import { CRAWL_REQUEST_CONCURRENCY } from '../../initializers/constants'
import { checkUrlsSameHost, getAPId } from '../../helpers/activitypub' 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) { async function shareVideoByServerAndChannel (video: MVideoAccountLight, t: Transaction) {
if (video.privacy === VideoPrivacy.PRIVATE) return undefined if (!video.hasPrivacyForFederation()) return undefined
return Promise.all([ return Promise.all([
shareByServer(video, t), shareByServer(video, t),

View file

@ -79,7 +79,7 @@ async function federateVideoIfNeeded (videoArg: MVideoAPWithoutCaption, isNewVid
// Check this is not a blacklisted video, or unfederated blacklisted video // Check this is not a blacklisted video, or unfederated blacklisted video
(video.isBlacklisted() === false || (isNewVideo === false && video.VideoBlacklist.unfederated === false)) && (video.isBlacklisted() === false || (isNewVideo === false && video.VideoBlacklist.unfederated === false)) &&
// Check the video is public/unlisted and published // 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 // Fetch more attributes that we will need to serialize in AP object
if (isArray(video.VideoCaptions) === false) { if (isArray(video.VideoCaptions) === false) {

View file

@ -46,7 +46,7 @@ export class ClientHtml {
]) ])
// Let Angular application handle errors // 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) return ClientHtml.getIndexHTML(req, res)
} }

View file

@ -35,16 +35,14 @@ export class UpdateVideosScheduler extends AbstractScheduler {
logger.info('Executing scheduled video update on %s.', video.uuid) logger.info('Executing scheduled video update on %s.', video.uuid)
if (schedule.privacy) { if (schedule.privacy) {
const oldPrivacy = video.privacy const wasConfidentialVideo = video.isConfidential()
const isNewVideo = oldPrivacy === VideoPrivacy.PRIVATE const isNewVideo = video.isNewVideo(schedule.privacy)
video.privacy = schedule.privacy
if (isNewVideo === true) video.publishedAt = new Date()
video.setPrivacy(schedule.privacy)
await video.save({ transaction: t }) await video.save({ transaction: t })
await federateVideoIfNeeded(video, isNewVideo, t) await federateVideoIfNeeded(video, isNewVideo, t)
if (oldPrivacy === VideoPrivacy.UNLISTED || oldPrivacy === VideoPrivacy.PRIVATE) { if (wasConfidentialVideo) {
const videoToPublish: MVideoFullLight = Object.assign(video, { ScheduleVideoUpdate: schedule, UserVideoHistories: [] }) const videoToPublish: MVideoFullLight = Object.assign(video, { ScheduleVideoUpdate: schedule, UserVideoHistories: [] })
publishedVideos.push(videoToPublish) publishedVideos.push(videoToPublish)
} }

View file

@ -161,18 +161,15 @@ const videosCustomGetValidator = (fetchType: 'all' | 'only-video' | 'only-video-
const videoAll = video as MVideoFullLight const videoAll = video as MVideoFullLight
// Video private or blacklisted // Video private or blacklisted
if (video.privacy === VideoPrivacy.PRIVATE || videoAll.VideoBlacklist) { if (videoAll.requiresAuth()) {
await authenticatePromiseIfNeeded(req, res, authenticateInQuery) await authenticatePromiseIfNeeded(req, res, authenticateInQuery)
const user = res.locals.oauth ? res.locals.oauth.token.User : null const user = res.locals.oauth ? res.locals.oauth.token.User : null
// Only the owner or a user that have blacklist rights can see the video // Only the owner or a user that have blacklist rights can see the video
if ( if (!user || !user.canGetVideo(videoAll)) {
!user ||
(videoAll.VideoChannel && videoAll.VideoChannel.Account.userId !== user.id && !user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST))
) {
return res.status(403) return res.status(403)
.json({ error: 'Cannot get this private or blacklisted video.' }) .json({ error: 'Cannot get this private/internal or blacklisted video.' })
} }
return next() return next()

View file

@ -19,7 +19,7 @@ import {
Table, Table,
UpdatedAt UpdatedAt
} from 'sequelize-typescript' } 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 { User, UserRole } from '../../../shared/models/users'
import { import {
isNoInstanceConfigWarningModal, isNoInstanceConfigWarningModal,
@ -63,7 +63,7 @@ import {
MUserFormattable, MUserFormattable,
MUserId, MUserId,
MUserNotifSettingChannelDefault, MUserNotifSettingChannelDefault,
MUserWithNotificationSetting MUserWithNotificationSetting, MVideoFullLight
} from '@server/typings/models' } from '@server/typings/models'
enum ScopeNames { enum ScopeNames {
@ -575,6 +575,20 @@ export class UserModel extends Model<UserModel> {
.then(u => u.map(u => u.username)) .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) { hasRight (right: UserRight) {
return hasUserRight(this.role, right) return hasUserRight(this.role, right)
} }

View file

@ -26,7 +26,7 @@ export class ScheduleVideoUpdateModel extends Model<ScheduleVideoUpdateModel> {
@AllowNull(true) @AllowNull(true)
@Default(null) @Default(null)
@Column @Column
privacy: VideoPrivacy.PUBLIC | VideoPrivacy.UNLISTED privacy: VideoPrivacy.PUBLIC | VideoPrivacy.UNLISTED | VideoPrivacy.INTERNAL
@CreatedAt @CreatedAt
createdAt: Date createdAt: Date

View file

@ -348,9 +348,8 @@ export type AvailableForListIDsOptions = {
// Only list public/published videos // Only list public/published videos
if (!options.filter || options.filter !== 'all-local') { if (!options.filter || options.filter !== 'all-local') {
const privacyWhere = {
// Always list public videos const publishWhere = {
privacy: VideoPrivacy.PUBLIC,
// Always list published videos, or videos that are being transcoded but on which we don't want to wait for transcoding // Always list published videos, or videos that are being transcoded but on which we don't want to wait for transcoding
[ Op.or ]: [ [ Op.or ]: [
{ {
@ -364,8 +363,26 @@ export type AvailableForListIDsOptions = {
} }
] ]
} }
whereAnd.push(publishWhere)
whereAnd.push(privacyWhere) // List internal videos if the user is logged in
if (options.user) {
const privacyWhere = {
[Op.or]: [
{
privacy: VideoPrivacy.INTERNAL
},
{
privacy: VideoPrivacy.PUBLIC
}
]
}
whereAnd.push(privacyWhere)
} else { // Or only public videos
const privacyWhere = { privacy: VideoPrivacy.PUBLIC }
whereAnd.push(privacyWhere)
}
} }
if (options.videoPlaylistId) { if (options.videoPlaylistId) {
@ -1773,6 +1790,10 @@ export class VideoModel extends Model<VideoModel> {
} }
} }
private static isPrivacyForFederation (privacy: VideoPrivacy) {
return privacy === VideoPrivacy.PUBLIC || privacy === VideoPrivacy.UNLISTED
}
static getCategoryLabel (id: number) { static getCategoryLabel (id: number) {
return VIDEO_CATEGORIES[ id ] || 'Misc' return VIDEO_CATEGORIES[ id ] || 'Misc'
} }
@ -1980,12 +2001,38 @@ export class VideoModel extends Model<VideoModel> {
return isOutdated(this, ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL) return isOutdated(this, ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL)
} }
hasPrivacyForFederation () {
return VideoModel.isPrivacyForFederation(this.privacy)
}
isNewVideo (newPrivacy: VideoPrivacy) {
return this.hasPrivacyForFederation() === false && VideoModel.isPrivacyForFederation(newPrivacy) === true
}
setAsRefreshed () { setAsRefreshed () {
this.changed('updatedAt', true) this.changed('updatedAt', true)
return this.save() return this.save()
} }
requiresAuth () {
return this.privacy === VideoPrivacy.PRIVATE || this.privacy === VideoPrivacy.INTERNAL || !!this.VideoBlacklist
}
setPrivacy (newPrivacy: VideoPrivacy) {
if (this.privacy === VideoPrivacy.PRIVATE && newPrivacy !== VideoPrivacy.PRIVATE) {
this.publishedAt = new Date()
}
this.privacy = newPrivacy
}
isConfidential () {
return this.privacy === VideoPrivacy.PRIVATE ||
this.privacy === VideoPrivacy.UNLISTED ||
this.privacy === VideoPrivacy.INTERNAL
}
async publishIfNeededAndSave (t: Transaction) { async publishIfNeededAndSave (t: Transaction) {
if (this.state !== VideoState.PUBLISHED) { if (this.state !== VideoState.PUBLISHED) {
this.state = VideoState.PUBLISHED this.state = VideoState.PUBLISHED

View file

@ -16,14 +16,22 @@ import { userLogin } from '../../../../shared/extra-utils/users/login'
import { createUser } from '../../../../shared/extra-utils/users/users' import { createUser } from '../../../../shared/extra-utils/users/users'
import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../../../shared/extra-utils/videos/videos' import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../../../shared/extra-utils/videos/videos'
import { waitJobs } from '../../../../shared/extra-utils/server/jobs' import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
import { Video } from '@shared/models'
const expect = chai.expect const expect = chai.expect
describe('Test video privacy', function () { describe('Test video privacy', function () {
let servers: ServerInfo[] = [] let servers: ServerInfo[] = []
let anotherUserToken: string
let privateVideoId: number let privateVideoId: number
let privateVideoUUID: string let privateVideoUUID: string
let internalVideoId: number
let internalVideoUUID: string
let unlistedVideoUUID: string let unlistedVideoUUID: string
let now: number let now: number
before(async function () { before(async function () {
@ -39,39 +47,63 @@ describe('Test video privacy', function () {
await doubleFollow(servers[0], servers[1]) await doubleFollow(servers[0], servers[1])
}) })
it('Should upload a private video on server 1', async function () { it('Should upload a private and internal videos on server 1', async function () {
this.timeout(10000) this.timeout(10000)
const attributes = { for (const privacy of [ VideoPrivacy.PRIVATE, VideoPrivacy.INTERNAL ]) {
privacy: VideoPrivacy.PRIVATE const attributes = { privacy }
await uploadVideo(servers[0].url, servers[0].accessToken, attributes)
} }
await uploadVideo(servers[0].url, servers[0].accessToken, attributes)
await waitJobs(servers) await waitJobs(servers)
}) })
it('Should not have this private video on server 2', async function () { it('Should not have these private and internal videos on server 2', async function () {
const res = await getVideosList(servers[1].url) const res = await getVideosList(servers[1].url)
expect(res.body.total).to.equal(0) expect(res.body.total).to.equal(0)
expect(res.body.data).to.have.lengthOf(0) expect(res.body.data).to.have.lengthOf(0)
}) })
it('Should list my (private) videos', async function () { it('Should not list the private and internal videos for an unauthenticated user on server 1', async function () {
const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 1) const res = await getVideosList(servers[0].url)
expect(res.body.total).to.equal(0)
expect(res.body.data).to.have.lengthOf(0)
})
it('Should not list the private video and list the internal video for an authenticated user on server 1', async function () {
const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)
expect(res.body.total).to.equal(1) expect(res.body.total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1) expect(res.body.data).to.have.lengthOf(1)
privateVideoId = res.body.data[0].id expect(res.body.data[0].privacy.id).to.equal(VideoPrivacy.INTERNAL)
privateVideoUUID = res.body.data[0].uuid
}) })
it('Should not be able to watch this video with non authenticated user', async function () { it('Should list my (private and internal) videos', async function () {
const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 10)
expect(res.body.total).to.equal(2)
expect(res.body.data).to.have.lengthOf(2)
const videos: Video[] = res.body.data
const privateVideo = videos.find(v => v.privacy.id === VideoPrivacy.PRIVATE)
privateVideoId = privateVideo.id
privateVideoUUID = privateVideo.uuid
const internalVideo = videos.find(v => v.privacy.id === VideoPrivacy.INTERNAL)
internalVideoId = internalVideo.id
internalVideoUUID = internalVideo.uuid
})
it('Should not be able to watch the private/internal video with non authenticated user', async function () {
await getVideo(servers[0].url, privateVideoUUID, 401) await getVideo(servers[0].url, privateVideoUUID, 401)
await getVideo(servers[0].url, internalVideoUUID, 401)
}) })
it('Should not be able to watch this private video with another user', async function () { it('Should not be able to watch the private video with another user', async function () {
this.timeout(10000) this.timeout(10000)
const user = { const user = {
@ -80,12 +112,16 @@ describe('Test video privacy', function () {
} }
await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password }) await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password })
const token = await userLogin(servers[0], user) anotherUserToken = await userLogin(servers[0], user)
await getVideoWithToken(servers[0].url, token, privateVideoUUID, 403) await getVideoWithToken(servers[0].url, anotherUserToken, privateVideoUUID, 403)
}) })
it('Should be able to watch this video with the correct user', async function () { it('Should be able to watch the internal video with another user', async function () {
await getVideoWithToken(servers[0].url, servers[0].accessToken, privateVideoUUID) await getVideoWithToken(servers[0].url, anotherUserToken, internalVideoUUID, 200)
})
it('Should be able to watch the private video with the correct user', async function () {
await getVideoWithToken(servers[0].url, servers[0].accessToken, privateVideoUUID, 200)
}) })
it('Should upload an unlisted video on server 2', async function () { it('Should upload an unlisted video on server 2', async function () {
@ -127,16 +163,27 @@ describe('Test video privacy', function () {
} }
}) })
it('Should update the private video to public on server 1', async function () { it('Should update the private and internal videos to public on server 1', async function () {
this.timeout(10000) this.timeout(10000)
const attribute = { now = Date.now()
name: 'super video public',
privacy: VideoPrivacy.PUBLIC {
const attribute = {
name: 'private video becomes public',
privacy: VideoPrivacy.PUBLIC
}
await updateVideo(servers[ 0 ].url, servers[ 0 ].accessToken, privateVideoId, attribute)
} }
now = Date.now() {
await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, attribute) const attribute = {
name: 'internal video becomes public',
privacy: VideoPrivacy.PUBLIC
}
await updateVideo(servers[ 0 ].url, servers[ 0 ].accessToken, internalVideoId, attribute)
}
await waitJobs(servers) await waitJobs(servers)
}) })
@ -144,18 +191,30 @@ describe('Test video privacy', function () {
it('Should have this new public video listed on server 1 and 2', async function () { it('Should have this new public video listed on server 1 and 2', async function () {
for (const server of servers) { for (const server of servers) {
const res = await getVideosList(server.url) const res = await getVideosList(server.url)
expect(res.body.total).to.equal(2)
expect(res.body.data).to.have.lengthOf(2)
expect(res.body.total).to.equal(1) const videos: Video[] = res.body.data
expect(res.body.data).to.have.lengthOf(1) const privateVideo = videos.find(v => v.name === 'private video becomes public')
expect(res.body.data[0].name).to.equal('super video public') const internalVideo = videos.find(v => v.name === 'internal video becomes public')
expect(new Date(res.body.data[0].publishedAt).getTime()).to.be.at.least(now)
expect(privateVideo).to.not.be.undefined
expect(internalVideo).to.not.be.undefined
expect(new Date(privateVideo.publishedAt).getTime()).to.be.at.least(now)
// We don't change the publish date of internal videos
expect(new Date(internalVideo.publishedAt).getTime()).to.be.below(now)
expect(privateVideo.privacy.id).to.equal(VideoPrivacy.PUBLIC)
expect(internalVideo.privacy.id).to.equal(VideoPrivacy.PUBLIC)
} }
}) })
it('Should set this new video as private', async function () { it('Should set these videos as private and internal', async function () {
this.timeout(10000) this.timeout(10000)
await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, { privacy: VideoPrivacy.PRIVATE }) await updateVideo(servers[0].url, servers[0].accessToken, internalVideoId, { privacy: VideoPrivacy.PRIVATE })
await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, { privacy: VideoPrivacy.INTERNAL })
await waitJobs(servers) await waitJobs(servers)
@ -168,10 +227,19 @@ describe('Test video privacy', function () {
{ {
const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5) const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5)
const videos = res.body.data
expect(res.body.total).to.equal(1) expect(res.body.total).to.equal(2)
expect(res.body.data).to.have.lengthOf(1) expect(videos).to.have.lengthOf(2)
expect(res.body.data[0].name).to.equal('super video public')
const privateVideo = videos.find(v => v.name === 'private video becomes public')
const internalVideo = videos.find(v => v.name === 'internal video becomes public')
expect(privateVideo).to.not.be.undefined
expect(internalVideo).to.not.be.undefined
expect(privateVideo.privacy.id).to.equal(VideoPrivacy.INTERNAL)
expect(internalVideo.privacy.id).to.equal(VideoPrivacy.PRIVATE)
} }
}) })

View file

@ -1,5 +1,6 @@
export enum VideoPrivacy { export enum VideoPrivacy {
PUBLIC = 1, PUBLIC = 1,
UNLISTED = 2, UNLISTED = 2,
PRIVATE = 3 PRIVATE = 3,
INTERNAL = 4
} }

View file

@ -2,5 +2,5 @@ import { VideoPrivacy } from './video-privacy.enum'
export interface VideoScheduleUpdate { export interface VideoScheduleUpdate {
updateAt: Date | string updateAt: Date | string
privacy?: VideoPrivacy.PUBLIC | VideoPrivacy.UNLISTED // Cannot schedule an update to PRIVATE privacy?: VideoPrivacy.PUBLIC | VideoPrivacy.UNLISTED | VideoPrivacy.INTERNAL // Cannot schedule an update to PRIVATE
} }