diff options
-rw-r--r-- | server/controllers/api/videos/ownership.ts | 12 | ||||
-rw-r--r-- | server/initializers/database.ts | 2 | ||||
-rw-r--r-- | server/models/video/video-change-ownership.ts | 36 |
3 files changed, 29 insertions, 21 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' | |||
17 | import { getFormattedObjects } from '../../../helpers/utils' | 17 | import { getFormattedObjects } from '../../../helpers/utils' |
18 | import { changeVideoChannelShare } from '../../../lib/activitypub' | 18 | import { changeVideoChannelShare } from '../../../lib/activitypub' |
19 | import { sendUpdateVideo } from '../../../lib/activitypub/send' | 19 | import { sendUpdateVideo } from '../../../lib/activitypub/send' |
20 | import { VideoModel } from '../../../models/video/video' | ||
20 | 21 | ||
21 | const ownershipVideoRouter = express.Router() | 22 | const ownershipVideoRouter = express.Router() |
22 | 23 | ||
@@ -97,12 +98,15 @@ async function listVideoOwnership (req: express.Request, res: express.Response) | |||
97 | async function acceptOwnership (req: express.Request, res: express.Response) { | 98 | async 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) |
diff --git a/server/initializers/database.ts b/server/initializers/database.ts index d9a265e7a..142063a99 100644 --- a/server/initializers/database.ts +++ b/server/initializers/database.ts | |||
@@ -86,6 +86,7 @@ async function initDatabaseModels (silent: boolean) { | |||
86 | AccountVideoRateModel, | 86 | AccountVideoRateModel, |
87 | UserModel, | 87 | UserModel, |
88 | VideoAbuseModel, | 88 | VideoAbuseModel, |
89 | VideoModel, | ||
89 | VideoChangeOwnershipModel, | 90 | VideoChangeOwnershipModel, |
90 | VideoChannelModel, | 91 | VideoChannelModel, |
91 | VideoShareModel, | 92 | VideoShareModel, |
@@ -93,7 +94,6 @@ async function initDatabaseModels (silent: boolean) { | |||
93 | VideoCaptionModel, | 94 | VideoCaptionModel, |
94 | VideoBlacklistModel, | 95 | VideoBlacklistModel, |
95 | VideoTagModel, | 96 | VideoTagModel, |
96 | VideoModel, | ||
97 | VideoCommentModel, | 97 | VideoCommentModel, |
98 | ScheduleVideoUpdateModel, | 98 | ScheduleVideoUpdateModel, |
99 | VideoImportModel, | 99 | VideoImportModel, |
diff --git a/server/models/video/video-change-ownership.ts b/server/models/video/video-change-ownership.ts index 171d4574d..b545a2f8c 100644 --- a/server/models/video/video-change-ownership.ts +++ b/server/models/video/video-change-ownership.ts | |||
@@ -1,30 +1,30 @@ | |||
1 | import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' | 1 | import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' |
2 | import { AccountModel } from '../account/account' | 2 | import { AccountModel } from '../account/account' |
3 | import { VideoModel } from './video' | 3 | import { ScopeNames as VideoScopeNames, VideoModel } from './video' |
4 | import { VideoChangeOwnership, VideoChangeOwnershipStatus } from '../../../shared/models/videos' | 4 | import { VideoChangeOwnership, VideoChangeOwnershipStatus } from '../../../shared/models/videos' |
5 | import { getSort } from '../utils' | 5 | import { getSort } from '../utils' |
6 | import { VideoFileModel } from './video-file' | ||
7 | 6 | ||
8 | enum ScopeNames { | 7 | enum ScopeNames { |
9 | FULL = 'FULL' | 8 | WITH_ACCOUNTS = 'WITH_ACCOUNTS', |
9 | WITH_VIDEO = 'WITH_VIDEO' | ||
10 | } | 10 | } |
11 | 11 | ||
12 | @Table({ | 12 | @Table({ |
13 | tableName: 'videoChangeOwnership', | 13 | tableName: 'videoChangeOwnership', |
14 | indexes: [ | 14 | indexes: [ |
15 | { | 15 | { |
16 | fields: ['videoId'] | 16 | fields: [ 'videoId' ] |
17 | }, | 17 | }, |
18 | { | 18 | { |
19 | fields: ['initiatorAccountId'] | 19 | fields: [ 'initiatorAccountId' ] |
20 | }, | 20 | }, |
21 | { | 21 | { |
22 | fields: ['nextOwnerAccountId'] | 22 | fields: [ 'nextOwnerAccountId' ] |
23 | } | 23 | } |
24 | ] | 24 | ] |
25 | }) | 25 | }) |
26 | @Scopes(() => ({ | 26 | @Scopes(() => ({ |
27 | [ScopeNames.FULL]: { | 27 | [ScopeNames.WITH_ACCOUNTS]: { |
28 | include: [ | 28 | include: [ |
29 | { | 29 | { |
30 | model: AccountModel, | 30 | model: AccountModel, |
@@ -35,13 +35,14 @@ enum ScopeNames { | |||
35 | model: AccountModel, | 35 | model: AccountModel, |
36 | as: 'NextOwner', | 36 | as: 'NextOwner', |
37 | required: true | 37 | required: true |
38 | }, | 38 | } |
39 | ] | ||
40 | }, | ||
41 | [ScopeNames.WITH_VIDEO]: { | ||
42 | include: [ | ||
39 | { | 43 | { |
40 | model: VideoModel, | 44 | model: VideoModel.scope([ VideoScopeNames.WITH_THUMBNAILS, VideoScopeNames.WITH_FILES ]), |
41 | required: true, | 45 | required: true |
42 | include: [ | ||
43 | { model: VideoFileModel } | ||
44 | ] | ||
45 | } | 46 | } |
46 | ] | 47 | ] |
47 | } | 48 | } |
@@ -105,12 +106,15 @@ export class VideoChangeOwnershipModel extends Model<VideoChangeOwnershipModel> | |||
105 | } | 106 | } |
106 | } | 107 | } |
107 | 108 | ||
108 | return VideoChangeOwnershipModel.scope(ScopeNames.FULL).findAndCountAll(query) | 109 | return Promise.all([ |
109 | .then(({ rows, count }) => ({ total: count, data: rows })) | 110 | VideoChangeOwnershipModel.scope(ScopeNames.WITH_ACCOUNTS).count(query), |
111 | VideoChangeOwnershipModel.scope([ ScopeNames.WITH_ACCOUNTS, ScopeNames.WITH_VIDEO ]).findAll(query) | ||
112 | ]).then(([ count, rows ]) => ({ total: count, data: rows })) | ||
110 | } | 113 | } |
111 | 114 | ||
112 | static load (id: number) { | 115 | static load (id: number) { |
113 | return VideoChangeOwnershipModel.scope(ScopeNames.FULL).findByPk(id) | 116 | return VideoChangeOwnershipModel.scope([ ScopeNames.WITH_ACCOUNTS, ScopeNames.WITH_VIDEO ]) |
117 | .findByPk(id) | ||
114 | } | 118 | } |
115 | 119 | ||
116 | toFormattedJSON (): VideoChangeOwnership { | 120 | toFormattedJSON (): VideoChangeOwnership { |