X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fvideos%2Fownership.ts;h=f48acbc681843190eb2b39051b4736218fbc2d28;hb=9e8789497377cac5554a622da605f5b89587aa9c;hp=abb34082e893c2d4382c74b7d3b947ed7f9bb29a;hpb=8c559fad1e1c4c2ab7f1388c73200aa4c6256d74;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/videos/ownership.ts b/server/controllers/api/videos/ownership.ts index abb34082e..f48acbc68 100644 --- a/server/controllers/api/videos/ownership.ts +++ b/server/controllers/api/videos/ownership.ts @@ -1,6 +1,12 @@ import * as express from 'express' +import { MVideoFullLight } from '@server/types/models' +import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' +import { VideoChangeOwnershipStatus, VideoState } from '../../../../shared/models/videos' import { logger } from '../../../helpers/logger' -import { sequelizeTypescript } from '../../../initializers' +import { getFormattedObjects } from '../../../helpers/utils' +import { sequelizeTypescript } from '../../../initializers/database' +import { sendUpdateVideo } from '../../../lib/activitypub/send' +import { changeVideoChannelShare } from '../../../lib/activitypub/share' import { asyncMiddleware, asyncRetryTransactionMiddleware, @@ -11,14 +17,9 @@ import { videosChangeOwnershipValidator, videosTerminateChangeOwnershipValidator } from '../../../middlewares' +import { VideoModel } from '../../../models/video/video' import { VideoChangeOwnershipModel } from '../../../models/video/video-change-ownership' -import { VideoChangeOwnershipStatus, VideoPrivacy, 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() @@ -80,7 +81,9 @@ async function giveVideoOwnership (req: express.Request, res: express.Response) }) logger.info('Ownership change for video %s created.', videoInstance.name) - return res.type('json').status(204).end() + return res.type('json') + .status(HttpStatusCode.NO_CONTENT_204) + .end() } async function listVideoOwnership (req: express.Request, res: express.Response) { @@ -96,22 +99,22 @@ async function listVideoOwnership (req: express.Request, res: express.Response) return res.json(getFormattedObjects(resultList.data, resultList.total)) } -async function acceptOwnership (req: express.Request, res: express.Response) { +function acceptOwnership (req: express.Request, res: express.Response) { return sequelizeTypescript.transaction(async t => { 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 targetVideo = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoChangeOwnership.Video.id, t) - const oldVideoChannel = await VideoChannelModel.loadByIdAndPopulateAccount(targetVideo.channelId) + const oldVideoChannel = await VideoChannelModel.loadAndPopulateAccount(targetVideo.channelId, 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) } @@ -119,17 +122,17 @@ async function acceptOwnership (req: express.Request, res: express.Response) { videoChangeOwnership.status = VideoChangeOwnershipStatus.ACCEPTED await videoChangeOwnership.save({ transaction: t }) - return res.sendStatus(204) + return res.status(HttpStatusCode.NO_CONTENT_204).end() }) } -async function refuseOwnership (req: express.Request, res: express.Response) { +function refuseOwnership (req: express.Request, res: express.Response) { return sequelizeTypescript.transaction(async t => { const videoChangeOwnership = res.locals.videoChangeOwnership videoChangeOwnership.status = VideoChangeOwnershipStatus.REFUSED await videoChangeOwnership.save({ transaction: t }) - return res.sendStatus(204) + return res.status(HttpStatusCode.NO_CONTENT_204).end() }) }