aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/ownership.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-04-24 09:44:36 +0200
committerChocobozzz <me@florianbigard.com>2019-04-24 16:26:21 +0200
commitb876eaf11a1ed9683664d94767ca684ba5b77753 (patch)
treef226897dcccae2648532095954f57c2058ed1834 /server/controllers/api/videos/ownership.ts
parentdc8527376482293c87fc6f30027d626f58a1197b (diff)
downloadPeerTube-b876eaf11a1ed9683664d94767ca684ba5b77753.tar.gz
PeerTube-b876eaf11a1ed9683664d94767ca684ba5b77753.tar.zst
PeerTube-b876eaf11a1ed9683664d94767ca684ba5b77753.zip
Fix ownership changes
Diffstat (limited to 'server/controllers/api/videos/ownership.ts')
-rw-r--r--server/controllers/api/videos/ownership.ts12
1 files changed, 8 insertions, 4 deletions
diff --git a/server/controllers/api/videos/ownership.ts b/server/controllers/api/videos/ownership.ts
index bc247c4ee..5272c1385 100644
--- a/server/controllers/api/videos/ownership.ts
+++ b/server/controllers/api/videos/ownership.ts
@@ -17,6 +17,7 @@ import { VideoChannelModel } from '../../../models/video/video-channel'
17import { getFormattedObjects } from '../../../helpers/utils' 17import { getFormattedObjects } from '../../../helpers/utils'
18import { changeVideoChannelShare } from '../../../lib/activitypub' 18import { changeVideoChannelShare } from '../../../lib/activitypub'
19import { sendUpdateVideo } from '../../../lib/activitypub/send' 19import { sendUpdateVideo } from '../../../lib/activitypub/send'
20import { VideoModel } from '../../../models/video/video'
20 21
21const ownershipVideoRouter = express.Router() 22const ownershipVideoRouter = express.Router()
22 23
@@ -97,12 +98,15 @@ async function listVideoOwnership (req: express.Request, res: express.Response)
97async function acceptOwnership (req: express.Request, res: express.Response) { 98async function acceptOwnership (req: express.Request, res: express.Response) {
98 return sequelizeTypescript.transaction(async t => { 99 return sequelizeTypescript.transaction(async t => {
99 const videoChangeOwnership = res.locals.videoChangeOwnership 100 const videoChangeOwnership = res.locals.videoChangeOwnership
100 const targetVideo = videoChangeOwnership.Video
101 const channel = res.locals.videoChannel 101 const channel = res.locals.videoChannel
102 102
103 // We need more attributes for federation
104 const targetVideo = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoChangeOwnership.Video.id)
105
103 const oldVideoChannel = await VideoChannelModel.loadByIdAndPopulateAccount(targetVideo.channelId) 106 const oldVideoChannel = await VideoChannelModel.loadByIdAndPopulateAccount(targetVideo.channelId)
104 107
105 targetVideo.set('channelId', channel.id) 108 targetVideo.channelId = channel.id
109
106 const targetVideoUpdated = await targetVideo.save({ transaction: t }) 110 const targetVideoUpdated = await targetVideo.save({ transaction: t })
107 targetVideoUpdated.VideoChannel = channel 111 targetVideoUpdated.VideoChannel = channel
108 112
@@ -111,7 +115,7 @@ async function acceptOwnership (req: express.Request, res: express.Response) {
111 await sendUpdateVideo(targetVideoUpdated, t, oldVideoChannel.Account.Actor) 115 await sendUpdateVideo(targetVideoUpdated, t, oldVideoChannel.Account.Actor)
112 } 116 }
113 117
114 videoChangeOwnership.set('status', VideoChangeOwnershipStatus.ACCEPTED) 118 videoChangeOwnership.status = VideoChangeOwnershipStatus.ACCEPTED
115 await videoChangeOwnership.save({ transaction: t }) 119 await videoChangeOwnership.save({ transaction: t })
116 120
117 return res.sendStatus(204) 121 return res.sendStatus(204)
@@ -122,7 +126,7 @@ async function refuseOwnership (req: express.Request, res: express.Response) {
122 return sequelizeTypescript.transaction(async t => { 126 return sequelizeTypescript.transaction(async t => {
123 const videoChangeOwnership = res.locals.videoChangeOwnership 127 const videoChangeOwnership = res.locals.videoChangeOwnership
124 128
125 videoChangeOwnership.set('status', VideoChangeOwnershipStatus.REFUSED) 129 videoChangeOwnership.status = VideoChangeOwnershipStatus.REFUSED
126 await videoChangeOwnership.save({ transaction: t }) 130 await videoChangeOwnership.save({ transaction: t })
127 131
128 return res.sendStatus(204) 132 return res.sendStatus(204)