diff options
author | Chocobozzz <me@florianbigard.com> | 2018-09-04 10:22:10 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-09-04 10:49:53 +0200 |
commit | 5cf84858d49f4231cc4efec5e3132f17f65f6cf6 (patch) | |
tree | f1ff23476ff54c32c3fa34db79c11f242855d3b4 /server/controllers/api/videos/ownership.ts | |
parent | 0b74c74abe5a44e9f564ab6adb5177ab17d28e91 (diff) | |
download | PeerTube-5cf84858d49f4231cc4efec5e3132f17f65f6cf6.tar.gz PeerTube-5cf84858d49f4231cc4efec5e3132f17f65f6cf6.tar.zst PeerTube-5cf84858d49f4231cc4efec5e3132f17f65f6cf6.zip |
Add federation to ownership change
Diffstat (limited to 'server/controllers/api/videos/ownership.ts')
-rw-r--r-- | server/controllers/api/videos/ownership.ts | 33 |
1 files changed, 24 insertions, 9 deletions
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 { | |||
14 | import { AccountModel } from '../../../models/account/account' | 14 | import { AccountModel } from '../../../models/account/account' |
15 | import { VideoModel } from '../../../models/video/video' | 15 | import { VideoModel } from '../../../models/video/video' |
16 | import { VideoChangeOwnershipModel } from '../../../models/video/video-change-ownership' | 16 | import { VideoChangeOwnershipModel } from '../../../models/video/video-change-ownership' |
17 | import { VideoChangeOwnershipStatus } from '../../../../shared/models/videos' | 17 | import { VideoChangeOwnershipStatus, VideoPrivacy, VideoState } from '../../../../shared/models/videos' |
18 | import { VideoChannelModel } from '../../../models/video/video-channel' | 18 | import { VideoChannelModel } from '../../../models/video/video-channel' |
19 | import { getFormattedObjects } from '../../../helpers/utils' | 19 | import { getFormattedObjects } from '../../../helpers/utils' |
20 | import { changeVideoChannelShare } from '../../../lib/activitypub' | ||
21 | import { sendUpdateVideo } from '../../../lib/activitypub/send' | ||
20 | 22 | ||
21 | const ownershipVideoRouter = express.Router() | 23 | const 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 | ||
82 | async function listVideoOwnership (req: express.Request, res: express.Response) { | 87 | async 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) { | |||
110 | async function refuseOwnership (req: express.Request, res: express.Response) { | 123 | async 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 | } |