X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fvideos%2Fownership.ts;h=41d7cdc43b50b77b62e5f32a590f1848bd2caec6;hb=a3b7421abb4192e215aa280418b62e96958c5e42;hp=d26ed6cfc39adb8385f5e9e0d5504ec86b8a4a32;hpb=5cf84858d49f4231cc4efec5e3132f17f65f6cf6;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/videos/ownership.ts b/server/controllers/api/videos/ownership.ts index d26ed6cfc..41d7cdc43 100644 --- a/server/controllers/api/videos/ownership.ts +++ b/server/controllers/api/videos/ownership.ts @@ -11,14 +11,14 @@ import { videosChangeOwnershipValidator, videosTerminateChangeOwnershipValidator } from '../../../middlewares' -import { AccountModel } from '../../../models/account/account' -import { VideoModel } from '../../../models/video/video' 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 { getFormattedObjects } from '../../../helpers/utils' import { changeVideoChannelShare } from '../../../lib/activitypub' import { sendUpdateVideo } from '../../../lib/activitypub/send' +import { VideoModel } from '../../../models/video/video' +import { MVideoFullLight } from '@server/typings/models' const ownershipVideoRouter = express.Router() @@ -57,27 +57,26 @@ export { // --------------------------------------------------------------------------- async function giveVideoOwnership (req: express.Request, res: express.Response) { - const videoInstance = res.locals.video as VideoModel - const initiatorAccount = res.locals.oauth.token.User.Account as AccountModel - const nextOwner = res.locals.nextOwner as AccountModel + const videoInstance = res.locals.videoAll + const initiatorAccountId = res.locals.oauth.token.User.Account.id + const nextOwner = res.locals.nextOwner await sequelizeTypescript.transaction(t => { return VideoChangeOwnershipModel.findOrCreate({ where: { - initiatorAccountId: initiatorAccount.id, + initiatorAccountId, nextOwnerAccountId: nextOwner.id, videoId: videoInstance.id, status: VideoChangeOwnershipStatus.WAITING }, defaults: { - initiatorAccountId: initiatorAccount.id, + initiatorAccountId, nextOwnerAccountId: nextOwner.id, videoId: videoInstance.id, status: VideoChangeOwnershipStatus.WAITING }, transaction: t }) - }) logger.info('Ownership change for video %s created.', videoInstance.name) @@ -85,9 +84,10 @@ async function giveVideoOwnership (req: express.Request, res: express.Response) } async function listVideoOwnership (req: express.Request, res: express.Response) { - const currentAccount = res.locals.oauth.token.User.Account as AccountModel + const currentAccountId = res.locals.oauth.token.User.Account.id + const resultList = await VideoChangeOwnershipModel.listForApi( - currentAccount.id, + currentAccountId, req.query.start || 0, req.query.count || 10, req.query.sort || 'createdAt' @@ -98,22 +98,25 @@ async function listVideoOwnership (req: express.Request, res: express.Response) async function acceptOwnership (req: express.Request, res: express.Response) { return sequelizeTypescript.transaction(async t => { - const videoChangeOwnership = res.locals.videoChangeOwnership as VideoChangeOwnershipModel - const targetVideo = videoChangeOwnership.Video - const channel = res.locals.videoChannel as VideoChannelModel + const videoChangeOwnership = res.locals.videoChangeOwnership + const channel = res.locals.videoChannel + + // We need more attributes for federation + const targetVideo = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoChangeOwnership.Video.id) const oldVideoChannel = await VideoChannelModel.loadByIdAndPopulateAccount(targetVideo.channelId) - targetVideo.set('channelId', channel.id) - const targetVideoUpdated = await targetVideo.save({ transaction: t }) + targetVideo.channelId = channel.id + + const targetVideoUpdated = await targetVideo.save({ transaction: t }) as MVideoFullLight 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 sendUpdateVideo(targetVideoUpdated, t, oldVideoChannel.Account.Actor) } - videoChangeOwnership.set('status', VideoChangeOwnershipStatus.ACCEPTED) + videoChangeOwnership.status = VideoChangeOwnershipStatus.ACCEPTED await videoChangeOwnership.save({ transaction: t }) return res.sendStatus(204) @@ -122,9 +125,9 @@ async function acceptOwnership (req: express.Request, res: express.Response) { async function refuseOwnership (req: express.Request, res: express.Response) { return sequelizeTypescript.transaction(async t => { - const videoChangeOwnership = res.locals.videoChangeOwnership as VideoChangeOwnershipModel + const videoChangeOwnership = res.locals.videoChangeOwnership - videoChangeOwnership.set('status', VideoChangeOwnershipStatus.REFUSED) + videoChangeOwnership.status = VideoChangeOwnershipStatus.REFUSED await videoChangeOwnership.save({ transaction: t }) return res.sendStatus(204)