Fix ownership changes
This commit is contained in:
parent
dc85273764
commit
b876eaf11a
|
@ -17,6 +17,7 @@ import { VideoChannelModel } from '../../../models/video/video-channel'
|
||||||
import { getFormattedObjects } from '../../../helpers/utils'
|
import { getFormattedObjects } from '../../../helpers/utils'
|
||||||
import { changeVideoChannelShare } from '../../../lib/activitypub'
|
import { changeVideoChannelShare } from '../../../lib/activitypub'
|
||||||
import { sendUpdateVideo } from '../../../lib/activitypub/send'
|
import { sendUpdateVideo } from '../../../lib/activitypub/send'
|
||||||
|
import { VideoModel } from '../../../models/video/video'
|
||||||
|
|
||||||
const ownershipVideoRouter = express.Router()
|
const ownershipVideoRouter = express.Router()
|
||||||
|
|
||||||
|
@ -97,12 +98,15 @@ async function listVideoOwnership (req: express.Request, res: express.Response)
|
||||||
async function acceptOwnership (req: express.Request, res: express.Response) {
|
async function acceptOwnership (req: express.Request, res: express.Response) {
|
||||||
return sequelizeTypescript.transaction(async t => {
|
return sequelizeTypescript.transaction(async t => {
|
||||||
const videoChangeOwnership = res.locals.videoChangeOwnership
|
const videoChangeOwnership = res.locals.videoChangeOwnership
|
||||||
const targetVideo = videoChangeOwnership.Video
|
|
||||||
const channel = res.locals.videoChannel
|
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)
|
const oldVideoChannel = await VideoChannelModel.loadByIdAndPopulateAccount(targetVideo.channelId)
|
||||||
|
|
||||||
targetVideo.set('channelId', channel.id)
|
targetVideo.channelId = channel.id
|
||||||
|
|
||||||
const targetVideoUpdated = await targetVideo.save({ transaction: t })
|
const targetVideoUpdated = await targetVideo.save({ transaction: t })
|
||||||
targetVideoUpdated.VideoChannel = channel
|
targetVideoUpdated.VideoChannel = channel
|
||||||
|
|
||||||
|
@ -111,7 +115,7 @@ async function acceptOwnership (req: express.Request, res: express.Response) {
|
||||||
await sendUpdateVideo(targetVideoUpdated, t, oldVideoChannel.Account.Actor)
|
await sendUpdateVideo(targetVideoUpdated, t, oldVideoChannel.Account.Actor)
|
||||||
}
|
}
|
||||||
|
|
||||||
videoChangeOwnership.set('status', VideoChangeOwnershipStatus.ACCEPTED)
|
videoChangeOwnership.status = VideoChangeOwnershipStatus.ACCEPTED
|
||||||
await videoChangeOwnership.save({ transaction: t })
|
await videoChangeOwnership.save({ transaction: t })
|
||||||
|
|
||||||
return res.sendStatus(204)
|
return res.sendStatus(204)
|
||||||
|
@ -122,7 +126,7 @@ async function refuseOwnership (req: express.Request, res: express.Response) {
|
||||||
return sequelizeTypescript.transaction(async t => {
|
return sequelizeTypescript.transaction(async t => {
|
||||||
const videoChangeOwnership = res.locals.videoChangeOwnership
|
const videoChangeOwnership = res.locals.videoChangeOwnership
|
||||||
|
|
||||||
videoChangeOwnership.set('status', VideoChangeOwnershipStatus.REFUSED)
|
videoChangeOwnership.status = VideoChangeOwnershipStatus.REFUSED
|
||||||
await videoChangeOwnership.save({ transaction: t })
|
await videoChangeOwnership.save({ transaction: t })
|
||||||
|
|
||||||
return res.sendStatus(204)
|
return res.sendStatus(204)
|
||||||
|
|
|
@ -86,6 +86,7 @@ async function initDatabaseModels (silent: boolean) {
|
||||||
AccountVideoRateModel,
|
AccountVideoRateModel,
|
||||||
UserModel,
|
UserModel,
|
||||||
VideoAbuseModel,
|
VideoAbuseModel,
|
||||||
|
VideoModel,
|
||||||
VideoChangeOwnershipModel,
|
VideoChangeOwnershipModel,
|
||||||
VideoChannelModel,
|
VideoChannelModel,
|
||||||
VideoShareModel,
|
VideoShareModel,
|
||||||
|
@ -93,7 +94,6 @@ async function initDatabaseModels (silent: boolean) {
|
||||||
VideoCaptionModel,
|
VideoCaptionModel,
|
||||||
VideoBlacklistModel,
|
VideoBlacklistModel,
|
||||||
VideoTagModel,
|
VideoTagModel,
|
||||||
VideoModel,
|
|
||||||
VideoCommentModel,
|
VideoCommentModel,
|
||||||
ScheduleVideoUpdateModel,
|
ScheduleVideoUpdateModel,
|
||||||
VideoImportModel,
|
VideoImportModel,
|
||||||
|
|
|
@ -1,30 +1,30 @@
|
||||||
import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
|
import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
|
||||||
import { AccountModel } from '../account/account'
|
import { AccountModel } from '../account/account'
|
||||||
import { VideoModel } from './video'
|
import { ScopeNames as VideoScopeNames, VideoModel } from './video'
|
||||||
import { VideoChangeOwnership, VideoChangeOwnershipStatus } from '../../../shared/models/videos'
|
import { VideoChangeOwnership, VideoChangeOwnershipStatus } from '../../../shared/models/videos'
|
||||||
import { getSort } from '../utils'
|
import { getSort } from '../utils'
|
||||||
import { VideoFileModel } from './video-file'
|
|
||||||
|
|
||||||
enum ScopeNames {
|
enum ScopeNames {
|
||||||
FULL = 'FULL'
|
WITH_ACCOUNTS = 'WITH_ACCOUNTS',
|
||||||
|
WITH_VIDEO = 'WITH_VIDEO'
|
||||||
}
|
}
|
||||||
|
|
||||||
@Table({
|
@Table({
|
||||||
tableName: 'videoChangeOwnership',
|
tableName: 'videoChangeOwnership',
|
||||||
indexes: [
|
indexes: [
|
||||||
{
|
{
|
||||||
fields: ['videoId']
|
fields: [ 'videoId' ]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fields: ['initiatorAccountId']
|
fields: [ 'initiatorAccountId' ]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fields: ['nextOwnerAccountId']
|
fields: [ 'nextOwnerAccountId' ]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
@Scopes(() => ({
|
@Scopes(() => ({
|
||||||
[ScopeNames.FULL]: {
|
[ScopeNames.WITH_ACCOUNTS]: {
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
model: AccountModel,
|
model: AccountModel,
|
||||||
|
@ -35,13 +35,14 @@ enum ScopeNames {
|
||||||
model: AccountModel,
|
model: AccountModel,
|
||||||
as: 'NextOwner',
|
as: 'NextOwner',
|
||||||
required: true
|
required: true
|
||||||
},
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
[ScopeNames.WITH_VIDEO]: {
|
||||||
|
include: [
|
||||||
{
|
{
|
||||||
model: VideoModel,
|
model: VideoModel.scope([ VideoScopeNames.WITH_THUMBNAILS, VideoScopeNames.WITH_FILES ]),
|
||||||
required: true,
|
required: true
|
||||||
include: [
|
|
||||||
{ model: VideoFileModel }
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -105,12 +106,15 @@ export class VideoChangeOwnershipModel extends Model<VideoChangeOwnershipModel>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return VideoChangeOwnershipModel.scope(ScopeNames.FULL).findAndCountAll(query)
|
return Promise.all([
|
||||||
.then(({ rows, count }) => ({ total: count, data: rows }))
|
VideoChangeOwnershipModel.scope(ScopeNames.WITH_ACCOUNTS).count(query),
|
||||||
|
VideoChangeOwnershipModel.scope([ ScopeNames.WITH_ACCOUNTS, ScopeNames.WITH_VIDEO ]).findAll(query)
|
||||||
|
]).then(([ count, rows ]) => ({ total: count, data: rows }))
|
||||||
}
|
}
|
||||||
|
|
||||||
static load (id: number) {
|
static load (id: number) {
|
||||||
return VideoChangeOwnershipModel.scope(ScopeNames.FULL).findByPk(id)
|
return VideoChangeOwnershipModel.scope([ ScopeNames.WITH_ACCOUNTS, ScopeNames.WITH_VIDEO ])
|
||||||
|
.findByPk(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
toFormattedJSON (): VideoChangeOwnership {
|
toFormattedJSON (): VideoChangeOwnership {
|
||||||
|
|
Loading…
Reference in New Issue