aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-06-06 16:44:02 +0200
committerChocobozzz <me@florianbigard.com>2019-06-06 16:44:02 +0200
commit46a6db245f50249246325090eeaffd165453a396 (patch)
tree7cb829b19c56433270d23f0ac81bed0691293c3e
parent60919831276e9c9e9900258bec82b6c31e9e5dd3 (diff)
downloadPeerTube-46a6db245f50249246325090eeaffd165453a396.tar.gz
PeerTube-46a6db245f50249246325090eeaffd165453a396.tar.zst
PeerTube-46a6db245f50249246325090eeaffd165453a396.zip
Add ability to set to private a public/unlisted video
-rw-r--r--server/controllers/api/videos/index.ts13
-rw-r--r--server/middlewares/validators/videos/videos.ts8
-rw-r--r--server/tests/api/videos/video-privacy.ts26
3 files changed, 34 insertions, 13 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 99900ca4a..5ebd8fbc4 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -199,11 +199,10 @@ async function addVideo (req: express.Request, res: express.Response) {
199 const video = new VideoModel(videoData) 199 const video = new VideoModel(videoData)
200 video.url = getVideoActivityPubUrl(video) // We use the UUID, so set the URL after building the object 200 video.url = getVideoActivityPubUrl(video) // We use the UUID, so set the URL after building the object
201 201
202 const videoFileData = { 202 const videoFile = new VideoFileModel({
203 extname: extname(videoPhysicalFile.filename), 203 extname: extname(videoPhysicalFile.filename),
204 size: videoPhysicalFile.size 204 size: videoPhysicalFile.size
205 } 205 })
206 const videoFile = new VideoFileModel(videoFileData)
207 206
208 if (videoFile.isAudio()) { 207 if (videoFile.isAudio()) {
209 videoFile.resolution = DEFAULT_AUDIO_RESOLUTION 208 videoFile.resolution = DEFAULT_AUDIO_RESOLUTION
@@ -321,7 +320,9 @@ async function updateVideo (req: express.Request, res: express.Response) {
321 const videoFieldsSave = videoInstance.toJSON() 320 const videoFieldsSave = videoInstance.toJSON()
322 const oldVideoAuditView = new VideoAuditView(videoInstance.toFormattedDetailsJSON()) 321 const oldVideoAuditView = new VideoAuditView(videoInstance.toFormattedDetailsJSON())
323 const videoInfoToUpdate: VideoUpdate = req.body 322 const videoInfoToUpdate: VideoUpdate = req.body
323
324 const wasPrivateVideo = videoInstance.privacy === VideoPrivacy.PRIVATE 324 const wasPrivateVideo = videoInstance.privacy === VideoPrivacy.PRIVATE
325 const wasNotPrivateVideo = videoInstance.privacy !== VideoPrivacy.PRIVATE
325 const wasUnlistedVideo = videoInstance.privacy === VideoPrivacy.UNLISTED 326 const wasUnlistedVideo = videoInstance.privacy === VideoPrivacy.UNLISTED
326 327
327 // Process thumbnail or create it from the video 328 // Process thumbnail or create it from the video
@@ -357,9 +358,15 @@ async function updateVideo (req: express.Request, res: express.Response) {
357 const newPrivacy = parseInt(videoInfoToUpdate.privacy.toString(), 10) 358 const newPrivacy = parseInt(videoInfoToUpdate.privacy.toString(), 10)
358 videoInstance.privacy = newPrivacy 359 videoInstance.privacy = newPrivacy
359 360
361 // The video was private, and is not anymore -> publish it
360 if (wasPrivateVideo === true && newPrivacy !== VideoPrivacy.PRIVATE) { 362 if (wasPrivateVideo === true && newPrivacy !== VideoPrivacy.PRIVATE) {
361 videoInstance.publishedAt = new Date() 363 videoInstance.publishedAt = new Date()
362 } 364 }
365
366 // The video was not private, but now it is -> we need to unfederate it
367 if (wasNotPrivateVideo === true && newPrivacy === VideoPrivacy.PRIVATE) {
368 await VideoModel.sendDelete(videoInstance, { transaction: t })
369 }
363 } 370 }
364 371
365 const videoInstanceUpdated = await videoInstance.save(sequelizeOptions) 372 const videoInstanceUpdated = await videoInstance.save(sequelizeOptions)
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts
index 2b01f108d..b1c05ab2d 100644
--- a/server/middlewares/validators/videos/videos.ts
+++ b/server/middlewares/validators/videos/videos.ts
@@ -111,18 +111,10 @@ const videosUpdateValidator = getCommonVideoEditAttributes().concat([
111 if (areErrorsInScheduleUpdate(req, res)) return cleanUpReqFiles(req) 111 if (areErrorsInScheduleUpdate(req, res)) return cleanUpReqFiles(req)
112 if (!await doesVideoExist(req.params.id, res)) return cleanUpReqFiles(req) 112 if (!await doesVideoExist(req.params.id, res)) return cleanUpReqFiles(req)
113 113
114 const video = res.locals.video
115
116 // Check if the user who did the request is able to update the video 114 // Check if the user who did the request is able to update the video
117 const user = res.locals.oauth.token.User 115 const user = res.locals.oauth.token.User
118 if (!checkUserCanManageVideo(user, res.locals.video, UserRight.UPDATE_ANY_VIDEO, res)) return cleanUpReqFiles(req) 116 if (!checkUserCanManageVideo(user, res.locals.video, UserRight.UPDATE_ANY_VIDEO, res)) return cleanUpReqFiles(req)
119 117
120 if (video.privacy !== VideoPrivacy.PRIVATE && req.body.privacy === VideoPrivacy.PRIVATE) {
121 cleanUpReqFiles(req)
122 return res.status(409)
123 .json({ error: 'Cannot set "private" a video that was not private.' })
124 }
125
126 if (req.body.channelId && !await doesVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req) 118 if (req.body.channelId && !await doesVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req)
127 119
128 return next() 120 return next()
diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts
index ef1cf0f07..40b539106 100644
--- a/server/tests/api/videos/video-privacy.ts
+++ b/server/tests/api/videos/video-privacy.ts
@@ -6,8 +6,7 @@ import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enu
6import { 6import {
7 cleanupTests, 7 cleanupTests,
8 flushAndRunMultipleServers, 8 flushAndRunMultipleServers,
9 getVideosList, 9 getVideosList, getVideosListWithToken,
10 killallServers,
11 ServerInfo, 10 ServerInfo,
12 setAccessTokensToServers, 11 setAccessTokensToServers,
13 uploadVideo 12 uploadVideo
@@ -153,6 +152,29 @@ describe('Test video privacy', function () {
153 } 152 }
154 }) 153 })
155 154
155 it('Should set this new video as private', async function () {
156 this.timeout(10000)
157
158 await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, { privacy: VideoPrivacy.PRIVATE })
159
160 await waitJobs(servers)
161
162 for (const server of servers) {
163 const res = await getVideosList(server.url)
164
165 expect(res.body.total).to.equal(0)
166 expect(res.body.data).to.have.lengthOf(0)
167 }
168
169 {
170 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5)
171
172 expect(res.body.total).to.equal(1)
173 expect(res.body.data).to.have.lengthOf(1)
174 expect(res.body.data[0].name).to.equal('super video public')
175 }
176 })
177
156 after(async function () { 178 after(async function () {
157 await cleanupTests(servers) 179 await cleanupTests(servers)
158 }) 180 })