aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-09-04 10:22:10 +0200
committerChocobozzz <me@florianbigard.com>2018-09-04 10:49:53 +0200
commit5cf84858d49f4231cc4efec5e3132f17f65f6cf6 (patch)
treef1ff23476ff54c32c3fa34db79c11f242855d3b4 /server/controllers/api
parent0b74c74abe5a44e9f564ab6adb5177ab17d28e91 (diff)
downloadPeerTube-5cf84858d49f4231cc4efec5e3132f17f65f6cf6.tar.gz
PeerTube-5cf84858d49f4231cc4efec5e3132f17f65f6cf6.tar.zst
PeerTube-5cf84858d49f4231cc4efec5e3132f17f65f6cf6.zip
Add federation to ownership change
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/users/index.ts2
-rw-r--r--server/controllers/api/videos/ownership.ts33
2 files changed, 25 insertions, 10 deletions
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts
index faba7e208..07edf3727 100644
--- a/server/controllers/api/users/index.ts
+++ b/server/controllers/api/users/index.ts
@@ -229,7 +229,7 @@ function getUser (req: express.Request, res: express.Response, next: express.Nex
229} 229}
230 230
231async function autocompleteUsers (req: express.Request, res: express.Response, next: express.NextFunction) { 231async function autocompleteUsers (req: express.Request, res: express.Response, next: express.NextFunction) {
232 const resultList = await UserModel.autocomplete(req.query.search as string) 232 const resultList = await UserModel.autoComplete(req.query.search as string)
233 233
234 return res.json(resultList) 234 return res.json(resultList)
235} 235}
diff --git a/server/controllers/api/videos/ownership.ts b/server/controllers/api/videos/ownership.ts
index fc42f5fff..d26ed6cfc 100644
--- a/server/controllers/api/videos/ownership.ts
+++ b/server/controllers/api/videos/ownership.ts
@@ -14,9 +14,11 @@ import {
14import { AccountModel } from '../../../models/account/account' 14import { AccountModel } from '../../../models/account/account'
15import { VideoModel } from '../../../models/video/video' 15import { VideoModel } from '../../../models/video/video'
16import { VideoChangeOwnershipModel } from '../../../models/video/video-change-ownership' 16import { VideoChangeOwnershipModel } from '../../../models/video/video-change-ownership'
17import { VideoChangeOwnershipStatus } from '../../../../shared/models/videos' 17import { VideoChangeOwnershipStatus, VideoPrivacy, VideoState } from '../../../../shared/models/videos'
18import { VideoChannelModel } from '../../../models/video/video-channel' 18import { VideoChannelModel } from '../../../models/video/video-channel'
19import { getFormattedObjects } from '../../../helpers/utils' 19import { getFormattedObjects } from '../../../helpers/utils'
20import { changeVideoChannelShare } from '../../../lib/activitypub'
21import { sendUpdateVideo } from '../../../lib/activitypub/send'
20 22
21const ownershipVideoRouter = express.Router() 23const ownershipVideoRouter = express.Router()
22 24
@@ -59,8 +61,8 @@ async function giveVideoOwnership (req: express.Request, res: express.Response)
59 const initiatorAccount = res.locals.oauth.token.User.Account as AccountModel 61 const initiatorAccount = res.locals.oauth.token.User.Account as AccountModel
60 const nextOwner = res.locals.nextOwner as AccountModel 62 const nextOwner = res.locals.nextOwner as AccountModel
61 63
62 await sequelizeTypescript.transaction(async t => { 64 await sequelizeTypescript.transaction(t => {
63 await VideoChangeOwnershipModel.findOrCreate({ 65 return VideoChangeOwnershipModel.findOrCreate({
64 where: { 66 where: {
65 initiatorAccountId: initiatorAccount.id, 67 initiatorAccountId: initiatorAccount.id,
66 nextOwnerAccountId: nextOwner.id, 68 nextOwnerAccountId: nextOwner.id,
@@ -72,11 +74,14 @@ async function giveVideoOwnership (req: express.Request, res: express.Response)
72 nextOwnerAccountId: nextOwner.id, 74 nextOwnerAccountId: nextOwner.id,
73 videoId: videoInstance.id, 75 videoId: videoInstance.id,
74 status: VideoChangeOwnershipStatus.WAITING 76 status: VideoChangeOwnershipStatus.WAITING
75 } 77 },
78 transaction: t
76 }) 79 })
77 logger.info('Ownership change for video %s created.', videoInstance.name) 80
78 return res.type('json').status(204).end()
79 }) 81 })
82
83 logger.info('Ownership change for video %s created.', videoInstance.name)
84 return res.type('json').status(204).end()
80} 85}
81 86
82async function listVideoOwnership (req: express.Request, res: express.Response) { 87async function listVideoOwnership (req: express.Request, res: express.Response) {
@@ -97,11 +102,19 @@ async function acceptOwnership (req: express.Request, res: express.Response) {
97 const targetVideo = videoChangeOwnership.Video 102 const targetVideo = videoChangeOwnership.Video
98 const channel = res.locals.videoChannel as VideoChannelModel 103 const channel = res.locals.videoChannel as VideoChannelModel
99 104
105 const oldVideoChannel = await VideoChannelModel.loadByIdAndPopulateAccount(targetVideo.channelId)
106
100 targetVideo.set('channelId', channel.id) 107 targetVideo.set('channelId', channel.id)
108 const targetVideoUpdated = await targetVideo.save({ transaction: t })
109 targetVideoUpdated.VideoChannel = channel
110
111 if (targetVideoUpdated.privacy !== VideoPrivacy.PRIVATE && targetVideoUpdated.state === VideoState.PUBLISHED) {
112 await changeVideoChannelShare(targetVideoUpdated, oldVideoChannel, t)
113 await sendUpdateVideo(targetVideoUpdated, t, oldVideoChannel.Account.Actor)
114 }
101 115
102 await targetVideo.save()
103 videoChangeOwnership.set('status', VideoChangeOwnershipStatus.ACCEPTED) 116 videoChangeOwnership.set('status', VideoChangeOwnershipStatus.ACCEPTED)
104 await videoChangeOwnership.save() 117 await videoChangeOwnership.save({ transaction: t })
105 118
106 return res.sendStatus(204) 119 return res.sendStatus(204)
107 }) 120 })
@@ -110,8 +123,10 @@ async function acceptOwnership (req: express.Request, res: express.Response) {
110async function refuseOwnership (req: express.Request, res: express.Response) { 123async function refuseOwnership (req: express.Request, res: express.Response) {
111 return sequelizeTypescript.transaction(async t => { 124 return sequelizeTypescript.transaction(async t => {
112 const videoChangeOwnership = res.locals.videoChangeOwnership as VideoChangeOwnershipModel 125 const videoChangeOwnership = res.locals.videoChangeOwnership as VideoChangeOwnershipModel
126
113 videoChangeOwnership.set('status', VideoChangeOwnershipStatus.REFUSED) 127 videoChangeOwnership.set('status', VideoChangeOwnershipStatus.REFUSED)
114 await videoChangeOwnership.save() 128 await videoChangeOwnership.save({ transaction: t })
129
115 return res.sendStatus(204) 130 return res.sendStatus(204)
116 }) 131 })
117} 132}