Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Also list received ownership changes

Chocobozzz2db076f65a55
diff --git a/packages/tests/src/api/check-params/video-change-ownership.ts b/packages/tests/src/api/check-params/video-change-ownership.ts
index d506f65c7c..743595cd68 100644
--- a/packages/tests/src/api/check-params/video-change-ownership.ts
+++ b/packages/tests/src/api/check-params/video-change-ownership.ts
@@ -76,6 +76,15 @@ describe('Test video change ownership API validator', function () {
await server.changeOwnership.create({ videoId: rootVideo2.id, username: 'user', token: rootEditorToken })
await server.changeOwnership.create({ videoId: rootVideo.id, username: 'user' })
})
+
+ it('Should fail to create a request for a video with a pending ownership change request', async function () {
+ await server.changeOwnership.create({
+ videoId: rootVideo2.id,
+ username: 'user',
+ token: rootEditorToken,
+ expectedStatus: HttpStatusCode.BAD_REQUEST_400
+ })
+ })
})
describe('List ownership change requests', function () {
@@ -85,7 +94,7 @@ describe('Test video change ownership API validator', function () {
it('Should succeed with valid params', async function () {
const { data } = await server.changeOwnership.list({ token: userToken })
- ownershipChangeId = data[0].id
+ ownershipChangeId = data.find(d => d.video.id === rootVideo2.id).id
})
})
@@ -103,7 +112,7 @@ describe('Test video change ownership API validator', function () {
})
it('Should fail with a ownership of another user', async function () {
- for (const token of [ userEditorToken, anotherUserToken ]) {
+ for (const token of [ userEditorToken, anotherUserToken, rootEditorToken ]) {
await server.changeOwnership.refuse({
ownershipId: ownershipChangeId,
token,
@@ -129,7 +138,7 @@ describe('Test video change ownership API validator', function () {
let targetChannelId: number
before(async function () {
- await server.changeOwnership.create({ videoId: rootVideo.id, username: 'user' })
+ await server.changeOwnership.create({ videoId: rootVideo2.id, username: 'user' })
const { data } = await server.changeOwnership.list({ token: userToken })
ownershipChangeId = data[0].id
diff --git a/packages/tests/src/api/videos/video-change-ownership.ts b/packages/tests/src/api/videos/video-change-ownership.ts
index bbaa2fb8e4..55c3ab6a57 100644
--- a/packages/tests/src/api/videos/video-change-ownership.ts
+++ b/packages/tests/src/api/videos/video-change-ownership.ts
@@ -1,6 +1,6 @@
/* oxlint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
-import { expect } from 'chai'
+import { HttpStatusCode, VideoPrivacy } from '@peertube/peertube-models'
import {
ChangeOwnershipCommand,
cleanupTests,
@@ -12,7 +12,7 @@ import {
setDefaultVideoChannel,
waitJobs
} from '@peertube/peertube-server-commands'
-import { HttpStatusCode, VideoPrivacy } from '@peertube/peertube-models'
+import { expect } from 'chai'
describe('Test video change ownership - nominal', function () {
let servers: PeerTubeServer[] = []
@@ -26,6 +26,11 @@ describe('Test video change ownership - nominal', function () {
let secondUserToken = ''
let secondUserChannelId: number
+ let unrelatedUserToken = ''
+
+ let firstUserEditorToken = ''
+ let secondUserEditorToken = ''
+
let lastRequestId: number
let liveId: number
@@ -52,6 +57,10 @@ describe('Test video change ownership - nominal', function () {
firstUserToken = await servers[0].users.generateUserAndToken(firstUser)
secondUserToken = await servers[0].users.generateUserAndToken(secondUser)
+ unrelatedUserToken = await servers[0].users.generateUserAndToken('unrelated')
+
+ firstUserEditorToken = await servers[0].channelCollaborators.createEditor('first_user_editor', firstUser + '_channel')
+ secondUserEditorToken = await servers[0].channelCollaborators.createEditor('second_user_editor', secondUser + '_channel')
{
const { videoChannels } = await servers[0].users.getMyInfo({ token: firstUserToken })
@@ -86,16 +95,8 @@ describe('Test video change ownership - nominal', function () {
})
it('Should not have video change ownership', async function () {
- {
- const body = await command.list({ token: firstUserToken })
-
- expect(body.total).to.equal(0)
- expect(body.data).to.be.an('array')
- expect(body.data.length).to.equal(0)
- }
-
- {
- const body = await command.list({ token: secondUserToken })
+ for (const token of [ firstUserToken, secondUserToken, unrelatedUserToken ]) {
+ const body = await command.list({ token })
expect(body.total).to.equal(0)
expect(body.data).to.be.an('array')
@@ -109,17 +110,17 @@ describe('Test video change ownership - nominal', function () {
await command.create({ token: firstUserToken, videoId: servers[0].store.videoCreated.id, username: secondUser })
})
- it('Should only return a request to change ownership for the second user', async function () {
+ it('Should correctly list ownership change', async function () {
{
- const body = await command.list({ token: firstUserToken })
+ const body = await command.list({ token: unrelatedUserToken })
expect(body.total).to.equal(0)
expect(body.data).to.be.an('array')
expect(body.data.length).to.equal(0)
}
- {
- const body = await command.list({ token: secondUserToken })
+ for (const token of [ firstUserToken, secondUserToken ]) {
+ const body = await command.list({ token })
expect(body.total).to.equal(1)
expect(body.data).to.be.an('array')
@@ -129,18 +130,6 @@ describe('Test video change ownership - nominal', function () {
}
})
- it('Should accept the same change ownership request without crashing', async function () {
- await command.create({ token: firstUserToken, videoId: servers[0].store.videoCreated.id, username: secondUser })
- })
-
- it('Should not create multiple change ownership requests while one is waiting', async function () {
- const body = await command.list({ token: secondUserToken })
-
- expect(body.total).to.equal(1)
- expect(body.data).to.be.an('array')
- expect(body.data.length).to.equal(1)
- })
-
it('Should not be possible to refuse the change of ownership from first user', async function () {
await command.refuse({ token: firstUserToken, ownershipId: lastRequestId, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
})
@@ -150,22 +139,20 @@ describe('Test video change ownership - nominal', function () {
})
it('Should send a new request to change ownership of a video', async function () {
- this.timeout(15000)
-
await command.create({ token: firstUserToken, videoId: servers[0].store.videoCreated.id, username: secondUser })
})
it('Should return two requests to change ownership for the second user', async function () {
{
- const body = await command.list({ token: firstUserToken })
+ const body = await command.list({ token: unrelatedUserToken })
expect(body.total).to.equal(0)
expect(body.data).to.be.an('array')
expect(body.data.length).to.equal(0)
}
- {
- const body = await command.list({ token: secondUserToken })
+ for (const token of [ firstUserToken, secondUserToken ]) {
+ const body = await command.list({ token })
expect(body.total).to.equal(2)
expect(body.data).to.be.an('array')
@@ -175,6 +162,22 @@ describe('Test video change ownership - nominal', function () {
}
})
+ it('Should list change ownership requests for collaborators', async function () {
+ const body = await command.list({ token: firstUserEditorToken })
+
+ expect(body.total).to.equal(2)
+ expect(body.data).to.be.an('array')
+ expect(body.data.length).to.equal(2)
+ })
+
+ it('Should list change ownership requests for collaborators of a channel of next owner', async function () {
+ const body = await command.list({ token: secondUserEditorToken })
+
+ expect(body.total).to.equal(0)
+ expect(body.data).to.be.an('array')
+ expect(body.data.length).to.equal(0)
+ })
+
it('Should not be possible to accept the change of ownership from first user', async function () {
await command.accept({
token: firstUserToken,
@@ -201,8 +204,6 @@ describe('Test video change ownership - nominal', function () {
})
it('Should send a request to change ownership of a live', async function () {
- this.timeout(15000)
-
await command.create({ token: firstUserToken, videoId: liveId, username: secondUser })
const body = await command.list({ token: secondUserToken })
@@ -271,32 +272,13 @@ describe('Test video change ownership - quota too small', function () {
})
it('Should send a request to change ownership of a video', async function () {
- this.timeout(15000)
-
await server.changeOwnership.create({ token: firstUserToken, videoId: server.store.videoCreated.id, username: secondUser })
})
- it('Should only return a request to change ownership for the second user', async function () {
- {
- const body = await server.changeOwnership.list({ token: firstUserToken })
-
- expect(body.total).to.equal(0)
- expect(body.data).to.be.an('array')
- expect(body.data.length).to.equal(0)
- }
-
- {
- const body = await server.changeOwnership.list({ token: secondUserToken })
-
- expect(body.total).to.equal(1)
- expect(body.data).to.be.an('array')
- expect(body.data.length).to.equal(1)
-
- lastRequestId = body.data[0].id
- }
- })
-
it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () {
+ const body = await server.changeOwnership.list({ token: secondUserToken })
+ lastRequestId = body.data[0].id
+
const { videoChannels } = await server.users.getMyInfo({ token: secondUserToken })
const channelId = videoChannels[0].id
diff --git a/server/core/controllers/api/videos/ownership.ts b/server/core/controllers/api/videos/ownership.ts
index 0806aa402d..3bbe781549 100644
--- a/server/core/controllers/api/videos/ownership.ts
+++ b/server/core/controllers/api/videos/ownership.ts
@@ -102,12 +102,12 @@ async function giveVideoOwnership (req: express.Request, res: express.Response)
async function listVideoOwnership (req: express.Request, res: express.Response) {
const currentAccountId = res.locals.oauth.token.User.Account.id
- const resultList = await VideoChangeOwnershipModel.listForApi(
- currentAccountId,
- req.query.start,
- req.query.count,
- req.query.sort || 'createdAt'
- )
+ const resultList = await VideoChangeOwnershipModel.listForApi({
+ accountId: currentAccountId,
+ start: req.query.start,
+ count: req.query.count,
+ sort: req.query.sort || 'createdAt'
+ })
return res.json(getFormattedObjects(resultList.data, resultList.total))
}
diff --git a/server/core/middlewares/validators/videos/video-ownership-changes.ts b/server/core/middlewares/validators/videos/video-ownership-changes.ts
index 4edba2bb80..6fa39da18b 100644
--- a/server/core/middlewares/validators/videos/video-ownership-changes.ts
+++ b/server/core/middlewares/validators/videos/video-ownership-changes.ts
@@ -15,6 +15,7 @@ import {
doesVideoExist,
isValidVideoIdParam
} from '../shared/index.js'
+import { VideoChangeOwnershipModel } from '@server/models/video/video-change-ownership.js'
export const videosChangeOwnershipValidator = [
isValidVideoIdParam('videoId'),
@@ -44,6 +45,15 @@ export const videosChangeOwnershipValidator = [
return
}
+ const existing = await VideoChangeOwnershipModel.loadPendingByVideo(res.locals.videoWithRights.id)
+ if (existing) {
+ res.fail({
+ status: HttpStatusCode.BAD_REQUEST_400,
+ message: req.t('There is already a pending ownership change request for this video')
+ })
+ return
+ }
+
res.locals.videoChangeOwnershipNextOwner = nextOwner
return next()
}
diff --git a/server/core/models/shared/model-builder.ts b/server/core/models/shared/model-builder.ts
index 5428fa878e..e5a60ff99c 100644
--- a/server/core/models/shared/model-builder.ts
+++ b/server/core/models/shared/model-builder.ts
@@ -41,7 +41,9 @@ export class ModelBuilder<T extends SequelizeModel> {
VideoPlaylists: 'VideoPlaylistModel',
NotificationSetting: 'UserNotificationSettingModel',
VideoChannelCollaborators: 'VideoChannelCollaboratorModel',
- Tags: 'TagModel'
+ Tags: 'TagModel',
+ Initiator: 'AccountModel',
+ NextOwner: 'AccountModel'
}
constructor (private readonly sequelize: Sequelize) {
diff --git a/server/core/models/video/sql/change-ownership/video-change-ownership-list-query-builder.ts b/server/core/models/video/sql/change-ownership/video-change-ownership-list-query-builder.ts
new file mode 100644
index 0000000000..fe5ace4e06
--- /dev/null
+++ b/server/core/models/video/sql/change-ownership/video-change-ownership-list-query-builder.ts
@@ -0,0 +1,194 @@
+import { VideoChannelCollaboratorState } from '@peertube/peertube-models'
+import { AbstractListQuery, AbstractListQueryOptions } from '@server/models/shared/abstract-list-query.js'
+import { getActorJoin, getAvatarsJoin, getChannelJoin } from '@server/models/shared/sql/actor-helpers.js'
+import { Sequelize } from 'sequelize'
+import { VideoChangeOwnershipTableAttributes } from './video-change-ownership-table-attributes.js'
+
+export interface ListVideoChangeOwnershipOptions extends AbstractListQueryOptions {
+ accountId: number
+}
+
+export class VideoChangeOwnershipListQueryBuilder extends AbstractListQuery {
+ private readonly tableAttributes = new VideoChangeOwnershipTableAttributes()
+
+ private builtInitiatorJoin = false
+ private builtNextOwnerJoin = false
+ private builtVideoJoin = false
+ private builtInitiatorAvatarJoin = false
+ private builtNextOwnerAvatarJoin = false
+ private builtChannelAvatarJoin = false
+ private builtChannelAccountAvatarJoin = false
+ private builtThumbnailJoin = false
+ private builtChannelCollaboratorsJoin = false
+
+ constructor (
+ protected readonly sequelize: Sequelize,
+ protected readonly options: ListVideoChangeOwnershipOptions
+ ) {
+ super(sequelize, { modelName: 'VideoChangeOwnershipModel', tableName: 'videoChangeOwnership' }, options)
+ }
+
+ // ---------------------------------------------------------------------------
+
+ protected buildSubQueryWhere () {
+ this.buildChannelCollaboratorsJoin()
+ this.subQueryWhere = `WHERE "VideoChangeOwnershipModel"."nextOwnerAccountId" = :nextOwnerAccountId ` +
+ `OR (` +
+ `"Video->VideoChannel->VideoChannelCollaborators"."accountId" = :collaborationAccountId OR ` +
+ `"Video->VideoChannel->Account"."id" = :videoAccountId` +
+ `)`
+
+ this.replacements.collaborationAccountId = this.options.accountId
+ this.replacements.videoAccountId = this.options.accountId
+ this.replacements.nextOwnerAccountId = this.options.accountId
+ }
+
+ // ---------------------------------------------------------------------------
+
+ private buildInitiatorJoin () {
+ if (this.builtInitiatorJoin) return
+
+ this.subQueryJoin += ' INNER JOIN "account" "Initiator" ON "Initiator"."id" = "VideoChangeOwnershipModel"."initiatorAccountId" ' +
+ getActorJoin({ base: 'Initiator->', on: '"Initiator"."id"', type: 'account', required: true })
+
+ this.builtInitiatorJoin = true
+ }
+
+ private buildNextOwnerJoin () {
+ if (this.builtNextOwnerJoin) return
+
+ this.subQueryJoin += ' INNER JOIN "account" "NextOwner" ON "NextOwner"."id" = "VideoChangeOwnershipModel"."nextOwnerAccountId" ' +
+ getActorJoin({ base: 'NextOwner->', on: '"NextOwner"."id"', type: 'account', required: true })
+
+ this.builtNextOwnerJoin = true
+ }
+
+ private buildVideoJoin () {
+ if (this.builtVideoJoin) return
+
+ this.subQueryJoin += ' INNER JOIN "video" "Video" ON "Video"."id" = "VideoChangeOwnershipModel"."videoId" ' +
+ getChannelJoin({
+ base: 'Video->',
+ on: '"Video"."channelId"',
+ includeAccount: true,
+ includeActors: true,
+ includeAvatars: false,
+ required: true
+ })
+
+ this.builtVideoJoin = true
+ }
+
+ private buildChannelCollaboratorsJoin () {
+ if (this.builtChannelCollaboratorsJoin) return
+
+ this.buildVideoJoin()
+
+ this.subQueryJoin += ' LEFT JOIN "videoChannelCollaborator" "Video->VideoChannel->VideoChannelCollaborators" ' +
+ 'ON "Video->VideoChannel->VideoChannelCollaborators"."channelId" = "Video->VideoChannel"."id" ' +
+ 'AND "Video->VideoChannel->VideoChannelCollaborators"."state" = :channelCollaboratorState ' +
+ // Ensure we join with max 1 collaborator to not duplicate rows
+ 'AND "Video->VideoChannel->VideoChannelCollaborators"."accountId" = :collaborationAccountId '
+
+ this.replacements.channelCollaboratorState = VideoChannelCollaboratorState.ACCEPTED
+ this.replacements.collaborationAccountId = this.options.accountId
+
+ this.builtChannelCollaboratorsJoin = true
+ }
+
+ // ---------------------------------------------------------------------------
+
+ private buildInitiatorAvatarsJoin () {
+ if (this.builtInitiatorAvatarJoin) return
+
+ this.join += getAvatarsJoin({ base: 'Initiator->Actor->', on: '"Initiator.Actor.id"' })
+
+ this.builtInitiatorAvatarJoin = true
+ }
+
+ private buildNextOwnerAvatarsJoin () {
+ if (this.builtNextOwnerAvatarJoin) return
+
+ this.join += getAvatarsJoin({ base: 'NextOwner->Actor->', on: '"NextOwner.Actor.id"' })
+
+ this.builtNextOwnerAvatarJoin = true
+ }
+
+ private buildChannelAvatarsJoin () {
+ if (this.builtChannelAvatarJoin) return
+
+ this.join += getAvatarsJoin({ base: 'Video->VideoChannel->Actor->', on: '"Video.VideoChannel.Actor.id"' })
+
+ this.builtChannelAvatarJoin = true
+ }
+
+ private buildChannelAccountAvatarsJoin () {
+ if (this.builtChannelAccountAvatarJoin) return
+
+ this.join += getAvatarsJoin({ base: 'Video->VideoChannel->Account->Actor->', on: '"Video.VideoChannel.Account.Actor.id"' })
+
+ this.builtChannelAccountAvatarJoin = true
+ }
+
+ private buildThumbnailJoin () {
+ if (this.builtThumbnailJoin) return
+
+ this.join += ' LEFT JOIN "thumbnail" "Video->Thumbnails" ON "Video->Thumbnails"."videoId" = "Video.id" '
+
+ this.builtThumbnailJoin = true
+ }
+
+ // ---------------------------------------------------------------------------
+
+ protected buildQueryJoin () {
+ this.buildInitiatorAvatarsJoin()
+ this.buildNextOwnerAvatarsJoin()
+ this.buildChannelAvatarsJoin()
+ this.buildChannelAccountAvatarsJoin()
+ this.buildThumbnailJoin()
+ }
+
+ protected buildQueryAttributes () {
+ this.attributes = [
+ ...this.attributes,
+
+ this.tableAttributes.getInitiatorAvatarAttributes(),
+ this.tableAttributes.getNextOwnerAvatarAttributes(),
+ this.tableAttributes.getVideoChannelAvatarAttributes(),
+ this.tableAttributes.getVideoChannelAccountAvatarAttributes(),
+ this.tableAttributes.getThumbnailAttributes()
+ ]
+ }
+
+ protected buildSubQueryJoin () {
+ this.buildInitiatorJoin()
+ this.buildNextOwnerJoin()
+ this.buildVideoJoin()
+ }
+
+ protected buildSubQueryAttributes () {
+ this.subQueryAttributes = [
+ ...this.subQueryAttributes,
+
+ this.tableAttributes.getChangeOwnershipAttributes(),
+
+ this.tableAttributes.getInitiatorAttributes(),
+ this.tableAttributes.getInitiatorActorAttributes(),
+ this.tableAttributes.getInitiatorServerAttributes(),
+
+ this.tableAttributes.getNextOwnerAttributes(),
+ this.tableAttributes.getNextOwnerActorAttributes(),
+ this.tableAttributes.getNextOwnerServerAttributes(),
+
+ this.tableAttributes.getVideoAttributes(),
+
+ this.tableAttributes.getVideoChannelAttributes(),
+ this.tableAttributes.getVideoChannelActorAttributes(),
+ this.tableAttributes.getVideoChannelServerAttributes(),
+
+ this.tableAttributes.getVideoChannelAccountAttributes(),
+ this.tableAttributes.getVideoChannelAccountActorAttributes(),
+ this.tableAttributes.getVideoChannelAccountServerAttributes()
+ ]
+ }
+}
diff --git a/server/core/models/video/sql/change-ownership/video-change-ownership-table-attributes.ts b/server/core/models/video/sql/change-ownership/video-change-ownership-table-attributes.ts
new file mode 100644
index 0000000000..2278c25449
--- /dev/null
+++ b/server/core/models/video/sql/change-ownership/video-change-ownership-table-attributes.ts
@@ -0,0 +1,124 @@
+import { Memoize } from '@server/helpers/memoize.js'
+import { AccountModel } from '@server/models/account/account.js'
+import { ActorImageModel } from '@server/models/actor/actor-image.js'
+import { ActorModel } from '@server/models/actor/actor.js'
+import { ServerModel } from '@server/models/server/server.js'
+import { ThumbnailModel } from '../../thumbnail.js'
+import { VideoChannelModel } from '../../video-channel.js'
+import { VideoChangeOwnershipModel } from '../../video-change-ownership.js'
+import { VideoModel } from '../../video.js'
+
+export class VideoChangeOwnershipTableAttributes {
+ @Memoize()
+ getChangeOwnershipAttributes () {
+ return VideoChangeOwnershipModel.getSQLAttributes('VideoChangeOwnershipModel').join(', ')
+ }
+
+ // ---------------------------------------------------------------------------
+
+ @Memoize()
+ getInitiatorAttributes () {
+ return AccountModel.getSQLAttributes('Initiator', 'Initiator.').join(', ')
+ }
+
+ @Memoize()
+ getInitiatorActorAttributes () {
+ return ActorModel.getSQLAPIAttributes('Initiator->Actor', 'Initiator.Actor.').join(', ')
+ }
+
+ @Memoize()
+ getInitiatorServerAttributes () {
+ return ServerModel.getSQLSummaryAttributes('Initiator->Actor->Server', 'Initiator.Actor.Server.').join(', ')
+ }
+
+ @Memoize()
+ getInitiatorAvatarAttributes () {
+ return ActorImageModel.getSQLAttributes('Initiator->Actor->Avatars', 'Initiator.Actor.Avatars.').join(', ')
+ }
+
+ // ---------------------------------------------------------------------------
+
+ @Memoize()
+ getNextOwnerAttributes () {
+ return AccountModel.getSQLAttributes('NextOwner', 'NextOwner.').join(', ')
+ }
+
+ @Memoize()
+ getNextOwnerActorAttributes () {
+ return ActorModel.getSQLAPIAttributes('NextOwner->Actor', 'NextOwner.Actor.').join(', ')
+ }
+
+ @Memoize()
+ getNextOwnerServerAttributes () {
+ return ServerModel.getSQLSummaryAttributes('NextOwner->Actor->Server', 'NextOwner.Actor.Server.').join(', ')
+ }
+
+ @Memoize()
+ getNextOwnerAvatarAttributes () {
+ return ActorImageModel.getSQLAttributes('NextOwner->Actor->Avatars', 'NextOwner.Actor.Avatars.').join(', ')
+ }
+
+ // ---------------------------------------------------------------------------
+
+ @Memoize()
+ getVideoAttributes () {
+ return VideoModel.getSQLAttributes('Video', 'Video.').join(', ')
+ }
+
+ // ---------------------------------------------------------------------------
+
+ @Memoize()
+ getVideoChannelAttributes () {
+ return VideoChannelModel.getSQLSummaryAttributes('Video->VideoChannel', 'Video.VideoChannel.').join(', ')
+ }
+
+ @Memoize()
+ getVideoChannelActorAttributes () {
+ return ActorModel.getSQLSummaryAttributes('Video->VideoChannel->Actor', 'Video.VideoChannel.Actor.').join(', ')
+ }
+
+ @Memoize()
+ getVideoChannelServerAttributes () {
+ return ServerModel.getSQLSummaryAttributes('Video->VideoChannel->Actor->Server', 'Video.VideoChannel.Actor.Server.').join(', ')
+ }
+
+ @Memoize()
+ getVideoChannelAvatarAttributes () {
+ return ActorImageModel.getSQLAttributes('Video->VideoChannel->Actor->Avatars', 'Video.VideoChannel.Actor.Avatars.').join(', ')
+ }
+
+ // ---------------------------------------------------------------------------
+
+ @Memoize()
+ getVideoChannelAccountAttributes () {
+ return AccountModel.getSQLSummaryAttributes('Video->VideoChannel->Account', 'Video.VideoChannel.Account.').join(', ')
+ }
+
+ @Memoize()
+ getVideoChannelAccountActorAttributes () {
+ return ActorModel.getSQLSummaryAttributes('Video->VideoChannel->Account->Actor', 'Video.VideoChannel.Account.Actor.').join(', ')
+ }
+
+ @Memoize()
+ getVideoChannelAccountServerAttributes () {
+ return ServerModel.getSQLSummaryAttributes(
+ 'Video->VideoChannel->Account->Actor->Server',
+ 'Video.VideoChannel.Account.Actor.Server.'
+ ).join(', ')
+ }
+
+ @Memoize()
+ getVideoChannelAccountAvatarAttributes () {
+ return ActorImageModel.getSQLAttributes(
+ 'Video->VideoChannel->Account->Actor->Avatars',
+ 'Video.VideoChannel.Account.Actor.Avatars.'
+ ).join(', ')
+ }
+
+ // ---------------------------------------------------------------------------
+
+ @Memoize()
+ getThumbnailAttributes () {
+ return ThumbnailModel.getSQLAttributes('Video->Thumbnails', 'Video.Thumbnails.').join(', ')
+ }
+}
diff --git a/server/core/models/video/video-change-ownership.ts b/server/core/models/video/video-change-ownership.ts
index dd92a0f220..1434c6e266 100644
--- a/server/core/models/video/video-change-ownership.ts
+++ b/server/core/models/video/video-change-ownership.ts
@@ -6,7 +6,11 @@ import {
} from '@server/types/models/video/video-change-ownership.js'
import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
import { AccountModel } from '../account/account.js'
-import { SequelizeModel, getSort } from '../shared/index.js'
+import { SequelizeModel, buildSQLAttributes } from '../shared/index.js'
+import {
+ ListVideoChangeOwnershipOptions,
+ VideoChangeOwnershipListQueryBuilder
+} from './sql/change-ownership/video-change-ownership-list-query-builder.js'
import { VideoModel, ScopeNames as VideoScopeNames } from './video.js'
enum ScopeNames {
@@ -106,20 +110,21 @@ export class VideoChangeOwnershipModel extends SequelizeModel<VideoChangeOwnersh
})
declare Video: Awaited<VideoModel>
- static listForApi (nextOwnerId: number, start: number, count: number, sort: string) {
- const query = {
- offset: start,
- limit: count,
- order: getSort(sort),
- where: {
- nextOwnerAccountId: nextOwnerId
- }
- }
+ static getSQLAttributes (tableName: string, aliasPrefix = '') {
+ return buildSQLAttributes({
+ model: this,
+ tableName,
+ aliasPrefix
+ })
+ }
+
+ // ---------------------------------------------------------------------------
+ static listForApi (options: ListVideoChangeOwnershipOptions) {
return Promise.all([
- VideoChangeOwnershipModel.count(query),
- VideoChangeOwnershipModel.scope([ ScopeNames.WITH_ACCOUNTS, ScopeNames.WITH_VIDEO ]).findAll<MVideoChangeOwnershipFull>(query)
- ]).then(([ count, rows ]) => ({ total: count, data: rows }))
+ new VideoChangeOwnershipListQueryBuilder(VideoChangeOwnershipModel.sequelize, options).list<MVideoChangeOwnershipFull>(),
+ new VideoChangeOwnershipListQueryBuilder(VideoChangeOwnershipModel.sequelize, options).count()
+ ]).then(([ rows, total ]) => ({ total, data: rows }))
}
static load (id: number): Promise<MVideoChangeOwnershipFull> {