ActivityPub-federated video streaming platform using P2P directly in your web browser
Support changing video channel owner
Chocobozzz163fef0d50ea
diff --git a/client/src/app/+my-library/+my-video-channels/edit/pages/video-channel-editors.component.html b/client/src/app/+my-library/+my-video-channels/edit/pages/video-channel-editors.component.htmlindex fe82b3d86d..20b6ef0a09 100644--- a/client/src/app/+my-library/+my-video-channels/edit/pages/video-channel-editors.component.html+++ b/client/src/app/+my-library/+my-video-channels/edit/pages/video-channel-editors.component.html@@ -42,7 +42,7 @@<ul><li i18n>Publish videos in this channel</li>- <li i18n>Manage, update or delete videos, comments, playlists of this channel</li>+ <li i18n>Manage, update, transfer or delete videos, comments, playlists of this channel</li><li i18n>Add or delete channel synchronization</li><li i18n>Update information of this channel (title, description, banner...)</li></ul>diff --git a/client/src/app/+videos-publish-manage/+video-manage/video-manage.resolver.ts b/client/src/app/+videos-publish-manage/+video-manage/video-manage.resolver.tsindex bbd5ef6577..146efc7676 100644--- a/client/src/app/+videos-publish-manage/+video-manage/video-manage.resolver.ts+++ b/client/src/app/+videos-publish-manage/+video-manage/video-manage.resolver.ts@@ -12,6 +12,7 @@ import { PlayerSettingsService } from '@app/shared/shared-video/player-settings.import {LiveVideo,PlayerVideoSettings,+ UserRight,UserVideoQuota,VideoCaption,VideoChapter,@@ -64,7 +65,7 @@ export class VideoManageResolver {async ([video,videoSource,- allUserChannels,+ userChannels,captions,chapters,live,@@ -85,7 +86,7 @@ export class VideoManageResolver {return {video,- userChannels: allUserChannels.filter(c => c.ownerAccountId === video.channel.ownerAccount.id),+ userChannels,captions,chapters,videoSource,diff --git a/client/src/app/+videos-publish-manage/shared-manage/main-info/video-main-info.component.html b/client/src/app/+videos-publish-manage/shared-manage/main-info/video-main-info.component.htmlindex c356487698..bc2d34d79c 100644--- a/client/src/app/+videos-publish-manage/shared-manage/main-info/video-main-info.component.html+++ b/client/src/app/+videos-publish-manage/shared-manage/main-info/video-main-info.component.html@@ -90,21 +90,9 @@<label i18n for="channel">Channel</label>@if (manageType === 'update') {- @if (isEditor()) {- <div class="form-group-description">- <div i18n>- Only {{ videoEdit.getVideoAttributes().ownerAccountDisplayName }}'s channels are listed- </div>-- <div i18n>- You do not have the right to <a href="https://docs.joinpeertube.org/use/library#change-ownership-of-a-video" target="_blank">transfer ownership <my-global-icon iconName="external-link"></my-global-icon></a> of this video but {{ videoEdit.getVideoAttributes().ownerAccountDisplayName }} can do it- </div>- </div>- } @else {- <div class="form-group-description" i18n>- You can also <a href="https://docs.joinpeertube.org/use/library#change-ownership-of-a-video" target="_blank">transfer this video <my-global-icon iconName="external-link"></my-global-icon></a> to another account- </div>- }+ <div class="form-group-description" i18n>+ You can also <a href="https://docs.joinpeertube.org/use/library#change-ownership-of-a-video" target="_blank">transfer this video <my-global-icon iconName="external-link"></my-global-icon></a> to another account+ </div>}<my-select-channel class="d-block" inputId="channel" [items]="userChannels" formControlName="channelId"></my-select-channel>@@ -209,26 +197,24 @@<div class="danger-zone mt-5"><h3 class="mb-3" i18n>DANGER ZONE</h3>- @if (!isEditor()) {- <div class="form-group">- <label i18n for="deleteVideo">Change ownership of your video</label>- <div class="form-group-description" i18n>A modal window will open for you to specify the local account to which you want to transfer your video</div>+ <div class="form-group">+ <label i18n for="deleteVideo">Change ownership of your video</label>+ <div class="form-group-description" i18n>A modal window will open for you to specify the local account to which you want to transfer your video</div>- <button class="peertube-button danger-button" (click)="showChangeOwnershipModal()" [disabled]="ownershipRequestSent" i18n>Transfer ownership</button>+ <button class="peertube-button danger-button" (click)="showChangeOwnershipModal()" [disabled]="ownershipRequestSent" i18n>Transfer ownership</button>- @if (ownershipRequestSent) {- <my-alert class="d-block mt-3" type="success">- <ng-container i18n>- <a routerLink="/my-library/ownership">Ownership change request</a> sent to {{ ownershipRequestSent }}</ng-container>- </my-alert>- }- </div>+ @if (ownershipRequestSent) {+ <my-alert class="d-block mt-3" type="success">+ <ng-container i18n>+ <a routerLink="/my-library/ownership">Ownership change request</a> sent to {{ ownershipRequestSent }}</ng-container>+ </my-alert>+ }+ </div>- <my-video-change-ownership- #videoChangeOwnershipModal- [videoId]="videoEdit.getVideoAttributes().id" (requestSent)="onChangeOwnershipRequest($event)"- ></my-video-change-ownership>- }+ <my-video-change-ownership+ #videoChangeOwnershipModal+ [videoId]="videoEdit.getVideoAttributes().id" (requestSent)="onChangeOwnershipRequest($event)"+ ></my-video-change-ownership><div class="form-group"><label i18n for="deleteVideo">Delete your video</label>diff --git a/client/src/app/+videos-publish-manage/shared-manage/main-info/video-main-info.component.ts b/client/src/app/+videos-publish-manage/shared-manage/main-info/video-main-info.component.tsindex 9bfd5c3150..dc9887d043 100644--- a/client/src/app/+videos-publish-manage/shared-manage/main-info/video-main-info.component.ts+++ b/client/src/app/+videos-publish-manage/shared-manage/main-info/video-main-info.component.ts@@ -513,7 +513,7 @@ export class VideoMainInfoComponent implements OnInit, OnDestroy {// ---------------------------------------------------------------------------- isEditor () {- return this.videoEdit.getVideoAttributes().ownerAccountId !== this.authService.getUser().account.id+ isVideoOwner () {+ return this.videoEdit.getVideoAttributes().ownerAccountId === this.authService.getUser().account.id}}diff --git a/client/src/app/shared/shared-main/menu/lateral-menu.component.scss b/client/src/app/shared/shared-main/menu/lateral-menu.component.scssindex cd96e0b372..e96a87b589 100644--- a/client/src/app/shared/shared-main/menu/lateral-menu.component.scss+++ b/client/src/app/shared/shared-main/menu/lateral-menu.component.scss@@ -15,6 +15,9 @@ ul {top: 0;opacity: 0.4;z-index: 0;+ overflow: hidden;+ width: 100%;+ height: 100%;::ng-deep svg {color: pvar(--bg-secondary-450);diff --git a/client/src/standalone/player/src/peertube-player.ts b/client/src/standalone/player/src/peertube-player.tsindex b31cbb05aa..f947262eb4 100644--- a/client/src/standalone/player/src/peertube-player.ts+++ b/client/src/standalone/player/src/peertube-player.ts@@ -146,8 +146,6 @@ export class PeerTubePlayer {}setPoster (thumbnails: Thumbnail[]) {- console.log('coucou')-// Use HTML video element to display posterif (!this.player) {const playerEl = this.options.playerElement()diff --git a/packages/models/src/videos/channel/video-channel-activity.model.ts b/packages/models/src/videos/channel/video-channel-activity.model.tsindex 24db955a44..f71bb478c4 100644--- a/packages/models/src/videos/channel/video-channel-activity.model.ts+++ b/packages/models/src/videos/channel/video-channel-activity.model.ts@@ -11,7 +11,10 @@ export const VideoChannelActivityAction = {UPDATE_SOURCE_FILE: 8,UPDATE_ELEMENTS: 9,REMOVE_CHANNEL_OWNERSHIP: 10,- CREATE_CHANNEL_OWNERSHIP: 11+ CREATE_CHANNEL_OWNERSHIP: 11,+ SEND_OWNERSHIP_REQUEST: 12,+ ACCEPT_OWNERSHIP_REQUEST: 13,+ REFUSE_OWNERSHIP_REQUEST: 14} as constexport type VideoChannelActivityActionType = typeof VideoChannelActivityAction[keyof typeof VideoChannelActivityAction]@@ -91,4 +94,10 @@ export interface VideoChannelActivity {id: numberexternalChannelUrl: string}++ targetAccount?: {+ username: string+ displayName: string+ url: string+ }}diff --git a/packages/tests/src/api/check-params/video-change-ownership.ts b/packages/tests/src/api/check-params/video-change-ownership.tsindex 34466ff2cb..87f5a19ffc 100644--- a/packages/tests/src/api/check-params/video-change-ownership.ts+++ b/packages/tests/src/api/check-params/video-change-ownership.ts@@ -13,6 +13,7 @@ describe('Test video change ownership API validator', function () {let userVideo: VideoCreateResultlet rootVideo: VideoCreateResult+ let rootVideo2: VideoCreateResult// ---------------------------------------------------------------@@ -29,6 +30,7 @@ describe('Test video change ownership API validator', function () {userEditorToken = await server.channelCollaborators.createEditor('user_editor', 'user_channel')rootVideo = await server.videos.quickUpload({ name: 'root video' })+ rootVideo2 = await server.videos.quickUpload({ name: 'root video 2' })userVideo = await server.videos.quickUpload({ name: 'user video', token: userToken })})@@ -43,7 +45,7 @@ describe('Test video change ownership API validator', function () {})it('Should fail with a video of another user', async function () {- for (const token of [ userToken, rootEditorToken ]) {+ for (const token of [ userToken, userEditorToken ]) {await server.changeOwnership.create({videoId: rootVideo.id,username: 'another_user',@@ -71,6 +73,7 @@ describe('Test video change ownership API validator', function () {})it('Should succeed with valid params', async function () {+ await server.changeOwnership.create({ videoId: rootVideo2.id, username: 'user', token: rootEditorToken })await server.changeOwnership.create({ videoId: rootVideo.id, username: 'user' })})})diff --git a/packages/tests/src/api/check-params/videos.ts b/packages/tests/src/api/check-params/videos.tsindex 966198cf1d..7f6e36692f 100644--- a/packages/tests/src/api/check-params/videos.ts+++ b/packages/tests/src/api/check-params/videos.ts@@ -39,6 +39,7 @@ describe('Test videos API validator', function () {let channelId2: numberlet channelIdEditor: number+ let channelIdEditor2: numberlet video: VideoCreateResultlet privateVideo: VideoCreateResult@@ -73,6 +74,9 @@ describe('Test videos API validator', function () {{channelIdEditor = await server.channels.getDefaultId({ token: editorToken })+ const anotherEditorChannel = await server.channels.create({ attributes: { name: 'another_editor_channel' }, token: editorToken })++ channelIdEditor2 = anotherEditorChannel.id}{@@ -716,15 +720,7 @@ describe('Test videos API validator', function () {})})- it('Should fail with the channel of another user', async function () {- const fields = { ...baseCorrectParams, channelId: channelIdEditor }-- for (const token of [ server.accessToken, editorToken ]) {- await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token, fields })- }- })-- it('Should fail with another channel of the same user if the editor does not have the right on the target channel', async function () {+ it('Should fail to update channel if the editor does not have the right on the target channel', async function () {const fields = { ...baseCorrectParams, channelId: channelId2 }await makePutBodyRequest({@@ -736,7 +732,7 @@ describe('Test videos API validator', function () {})})- it('Should fail with another channel of the same user if the editor does not have the right on the video', async function () {+ it('Should fail to update channel if the editor does not have the right on the video', async function () {await server.videos.update({ id: video.id, attributes: { channelId: channelId2 } })const fields = { ...baseCorrectParams, channelId }@@ -908,6 +904,31 @@ describe('Test videos API validator', function () {expectedStatus: HttpStatusCode.NO_CONTENT_204})})++ it('Should fail with the channel of another user if the video has pending ownership change', async function () {+ const video = await server.videos.quickUpload({ name: 'video to transfer', channelId: channelIdEditor, token: editorToken })++ await server.changeOwnership.create({ videoId: video.id, username: 'root', token: editorToken })++ // Can update video metadata+ await server.videos.update({ id: video.id, attributes: { name: 'video to transfer 2' }, token: editorToken })+ // Can update video channel to a channel of the same user+ await server.videos.update({ id: video.id, attributes: { channelId: channelIdEditor2 }, token: editorToken })++ // Cannot update video channel to a channel of another user+ await server.videos.update({+ id: video.id,+ attributes: { channelId },+ expectedStatus: HttpStatusCode.BAD_REQUEST_400,+ token: editorToken+ })++ const { data } = await server.changeOwnership.list()+ await server.changeOwnership.refuse({ ownershipId: data[0].id })++ // Can update video channel to a channel of another user now there's no pending ownership change+ await server.videos.update({ id: video.id, attributes: { channelId }, token: editorToken })+ })})describe('When getting a video', function () {@@ -919,7 +940,7 @@ describe('Test videos API validator', function () {})expect(res.body.data).to.be.an('array')- expect(res.body.data.length).to.equal(6)+ expect(res.body.data.length).to.equal(7)})it('Should fail without a correct uuid', async function () {diff --git a/packages/tests/src/api/videos/channel-activities.ts b/packages/tests/src/api/videos/channel-activities.tsindex 685ee4d0d8..de2c744da4 100644--- a/packages/tests/src/api/videos/channel-activities.ts+++ b/packages/tests/src/api/videos/channel-activities.ts@@ -678,6 +678,66 @@ describe('Test channel activities', function () {})})+ describe('Ownership changes', function () {+ let video: VideoCreateResult+ let userToken: string++ before(async function () {+ video = await server.videos.quickUpload({ name: 'video for ownership change', channelId })+ userToken = await server.users.generateUserAndToken('user_ownership_change')+ })++ it('Should send an ownership request', async function () {+ const a = await getActivityAfterAction(() => {+ return server.changeOwnership.create({ videoId: video.id, username: 'user_ownership_change' })+ })++ expect(a.action.id).to.equal(VideoChannelActivityAction.SEND_OWNERSHIP_REQUEST)+ expect(a.targetType.id).to.equal(VideoChannelActivityTarget.VIDEO)++ expect(a.account.name).to.equal('root')++ expect(a.video.name).to.equal('video for ownership change')++ expect(a.targetAccount.username).to.equal('user_ownership_change')+ expect(a.targetAccount.url).to.equal(server.url + '/accounts/user_ownership_change')+ expect(a.targetAccount.displayName).to.equal('user_ownership_change')+ })++ it('Should refuse an ownership request', async function () {+ const { data } = await server.changeOwnership.list({ token: userToken })++ const a = await getActivityAfterAction(async () => {+ await server.changeOwnership.refuse({ ownershipId: data[0].id, token: userToken })+ })++ expect(a.action.id).to.equal(VideoChannelActivityAction.REFUSE_OWNERSHIP_REQUEST)+ expect(a.targetType.id).to.equal(VideoChannelActivityTarget.VIDEO)+ expect(a.account.name).to.equal('user_ownership_change')+ expect(a.video.name).to.equal('video for ownership change')+ expect(a.targetAccount.username).to.equal('user_ownership_change')+ })++ it('Should accept an ownership request', async function () {+ await server.changeOwnership.create({ videoId: video.id, username: 'user_ownership_change' })+ const { data } = await server.changeOwnership.list({ token: userToken })++ const a = await getActivityAfterAction(async () => {+ await server.changeOwnership.accept({+ ownershipId: data[0].id,+ channelId: await server.channels.getIdOf({ channelName: 'user_ownership_change_channel' }),+ token: userToken+ })+ })++ expect(a.action.id).to.equal(VideoChannelActivityAction.ACCEPT_OWNERSHIP_REQUEST)+ expect(a.targetType.id).to.equal(VideoChannelActivityTarget.VIDEO)+ expect(a.account.name).to.equal('user_ownership_change')+ expect(a.video.name).to.equal('video for ownership change')+ expect(a.targetAccount.username).to.equal('user_ownership_change')+ })+ })+describe('Common', function () {let channelId: numberdiff --git a/packages/tests/src/api/videos/channel-collaborators.ts b/packages/tests/src/api/videos/channel-collaborators.tsindex af85486824..a4068d6e3c 100644--- a/packages/tests/src/api/videos/channel-collaborators.ts+++ b/packages/tests/src/api/videos/channel-collaborators.ts@@ -492,13 +492,30 @@ describe('Test channel collaborators', function () {const { id } = await servers[0].channelCollaborators.invite({ channel: 'channel_collaboration2', target: 'collaborator1' })await servers[0].channelCollaborators.accept({ channel: 'channel_collaboration2', id, token: collaborator1 })- await servers[0].videos.update({ id: videoId, attributes: { channelId: channelCollabId2 }, token: collaborator1 })+ {+ await servers[0].videos.update({ id: videoId, attributes: { channelId: channelCollabId2 }, token: collaborator1 })- await waitJobs(servers)+ await waitJobs(servers)- for (const server of servers) {- const video = await server.videos.get({ id: videoId })- expect(video.channel.name).to.equal('channel_collaboration2')+ for (const server of servers) {+ const video = await server.videos.get({ id: videoId })+ expect(video.channel.name).to.equal('channel_collaboration2')+ }+ }++ {+ await servers[0].videos.update({+ id: videoId,+ attributes: { channelId: await servers[0].channels.getDefaultId({ token: collaborator1 }) },+ token: collaborator1+ })++ await waitJobs(servers)++ for (const server of servers) {+ const video = await server.videos.get({ id: videoId })+ expect(video.channel.name).to.equal('collaborator1_channel')+ }}})diff --git a/server/core/controllers/api/videos/ownership.ts b/server/core/controllers/api/videos/ownership.tsindex b3350441ac..bebcc2b846 100644--- a/server/core/controllers/api/videos/ownership.ts+++ b/server/core/controllers/api/videos/ownership.ts@@ -1,5 +1,6 @@-import { HttpStatusCode, VideoChangeOwnershipStatus } from '@peertube/peertube-models'+import { HttpStatusCode, VideoChangeOwnershipStatus, VideoChannelActivityAction } from '@peertube/peertube-models'import { canVideoBeFederated } from '@server/lib/activitypub/videos/federate.js'+import { VideoChannelActivityModel } from '@server/models/video/video-channel-activity.js'import { MVideoFullLight } from '@server/types/models/index.js'import express from 'express'import { logger } from '../../../helpers/logger.js'@@ -62,32 +63,40 @@ export {// ---------------------------------------------------------------------------async function giveVideoOwnership (req: express.Request, res: express.Response) {- const videoInstance = res.locals.videoAll+ const video = res.locals.videoAllconst initiatorAccountId = res.locals.oauth.token.User.Account.idconst nextOwner = res.locals.nextOwner- await sequelizeTypescript.transaction(t => {- return VideoChangeOwnershipModel.findOrCreate({+ await sequelizeTypescript.transaction(async t => {+ await VideoChangeOwnershipModel.findOrCreate({where: {initiatorAccountId,nextOwnerAccountId: nextOwner.id,- videoId: videoInstance.id,+ videoId: video.id,status: VideoChangeOwnershipStatus.WAITING},defaults: {initiatorAccountId,nextOwnerAccountId: nextOwner.id,- videoId: videoInstance.id,+ videoId: video.id,status: VideoChangeOwnershipStatus.WAITING},transaction: t})++ await VideoChannelActivityModel.addVideoOwnershipChangeActivity({+ action: VideoChannelActivityAction.SEND_OWNERSHIP_REQUEST,+ user: res.locals.oauth.token.User,+ channel: video.VideoChannel,+ video,+ targetAccount: nextOwner,+ transaction: t+ })})- logger.info('Ownership change for video %s created.', videoInstance.name)- return res.type('json')- .status(HttpStatusCode.NO_CONTENT_204)- .end()+ logger.info('Ownership change for video %s created.', video.name)++ return res.sendStatus(HttpStatusCode.NO_CONTENT_204)}async function listVideoOwnership (req: express.Request, res: express.Response) {@@ -126,7 +135,18 @@ function acceptOwnership (req: express.Request, res: express.Response) {videoChangeOwnership.status = VideoChangeOwnershipStatus.ACCEPTEDawait videoChangeOwnership.save({ transaction: t })- return res.status(HttpStatusCode.NO_CONTENT_204).end()+ for (const channel of [ oldVideoChannel, targetVideoUpdated.VideoChannel ]) {+ await VideoChannelActivityModel.addVideoOwnershipChangeActivity({+ action: VideoChannelActivityAction.ACCEPT_OWNERSHIP_REQUEST,+ user: res.locals.oauth.token.User,+ channel,+ video: targetVideoUpdated,+ targetAccount: videoChangeOwnership.NextOwner,+ transaction: t+ })+ }++ return res.sendStatus(HttpStatusCode.NO_CONTENT_204)})}@@ -137,6 +157,17 @@ function refuseOwnership (req: express.Request, res: express.Response) {videoChangeOwnership.status = VideoChangeOwnershipStatus.REFUSEDawait videoChangeOwnership.save({ transaction: t })- return res.status(HttpStatusCode.NO_CONTENT_204).end()+ const channel = await VideoChannelModel.loadAndPopulateAccount(videoChangeOwnership.Video.channelId, t)++ await VideoChannelActivityModel.addVideoOwnershipChangeActivity({+ action: VideoChannelActivityAction.REFUSE_OWNERSHIP_REQUEST,+ user: res.locals.oauth.token.User,+ channel,+ video: videoChangeOwnership.Video,+ targetAccount: videoChangeOwnership.NextOwner,+ transaction: t+ })++ return res.sendStatus(HttpStatusCode.NO_CONTENT_204)})}diff --git a/server/core/initializers/constants.ts b/server/core/initializers/constants.tsindex 535f6b7d5d..285f5c65db 100644--- a/server/core/initializers/constants.ts+++ b/server/core/initializers/constants.ts@@ -727,7 +727,10 @@ export const VIDEO_CHANNEL_ACTIVITY_ACTIONS: { [id in VideoChannelActivityAction[VideoChannelActivityAction.UPDATE_SOURCE_FILE]: 'Update source file',[VideoChannelActivityAction.UPDATE_ELEMENTS]: 'Update elements',[VideoChannelActivityAction.REMOVE_CHANNEL_OWNERSHIP]: 'Remove channel ownership',- [VideoChannelActivityAction.CREATE_CHANNEL_OWNERSHIP]: 'Create channel ownership'+ [VideoChannelActivityAction.CREATE_CHANNEL_OWNERSHIP]: 'Create channel ownership',+ [VideoChannelActivityAction.SEND_OWNERSHIP_REQUEST]: 'Send ownership request',+ [VideoChannelActivityAction.ACCEPT_OWNERSHIP_REQUEST]: 'Accept ownership request',+ [VideoChannelActivityAction.REFUSE_OWNERSHIP_REQUEST]: 'Refuse ownership request'}export const VIDEO_CHANNEL_ACTIVITY_TARGETS: { [id in VideoChannelActivityTargetType]: string } = {diff --git a/server/core/middlewares/validators/videos/video-ownership-changes.ts b/server/core/middlewares/validators/videos/video-ownership-changes.tsindex 742a46dee2..2392fb531f 100644--- a/server/core/middlewares/validators/videos/video-ownership-changes.ts+++ b/server/core/middlewares/validators/videos/video-ownership-changes.ts@@ -29,7 +29,7 @@ export const videosChangeOwnershipValidator = [user: res.locals.oauth.token.User,video: res.locals.videoAll,right: UserRight.CHANGE_VIDEO_OWNERSHIP,- checkIsOwner: true,+ checkIsOwner: false,checkIsLocal: true,req,resdiff --git a/server/core/middlewares/validators/videos/videos.ts b/server/core/middlewares/validators/videos/videos.tsindex 4491a65c70..1367262374 100644--- a/server/core/middlewares/validators/videos/videos.ts+++ b/server/core/middlewares/validators/videos/videos.ts@@ -11,6 +11,7 @@ import { isHostValid } from '@server/helpers/custom-validators/servers.js'import { VideoLoadType } from '@server/lib/model-loaders/video.js'import { Redis } from '@server/lib/redis.js'import { buildUploadXFile, safeUploadXCleanup } from '@server/lib/uploadx.js'+import { VideoChangeOwnershipModel } from '@server/models/video/video-change-ownership.js'import { ExpressPromiseHandler } from '@server/types/express-handler.js'import { MUserAccountId, MVideoFullLight } from '@server/types/models/index.js'import express from 'express'@@ -234,17 +235,7 @@ export const videosUpdateValidator = getCommonVideoEditAttributes().concat([// Check if the user who did the request is able to update the videoconst user = res.locals.oauth.token.User- if (- !await checkCanManageVideo({- user,- video: res.locals.videoAll,- right: UserRight.UPDATE_ANY_VIDEO,- req,- res,- checkIsLocal: true,- checkIsOwner: false- })- ) {+ if (!await checkCanManageVideo({ user, video, right: UserRight.UPDATE_ANY_VIDEO, req, res, checkIsLocal: true, checkIsOwner: false })) {return cleanUpReqFiles(req)}@@ -255,13 +246,21 @@ export const videosUpdateValidator = getCommonVideoEditAttributes().concat([return cleanUpReqFiles(req)}- if (res.locals.videoChannel && res.locals.videoChannel.accountId !== video.VideoChannel.accountId) {- res.fail({- status: HttpStatusCode.BAD_REQUEST_400,- message: req.t('The channel must belong to the same account as the original channel')- })+ // Not the same account as original video channel+ if (+ res.locals.videoChannel &&+ res.locals.videoChannel.accountId !== video.VideoChannel.accountId+ ) {+ const ownershipChange = await VideoChangeOwnershipModel.loadPendingByVideo(video.id)- return cleanUpReqFiles(req)+ if (ownershipChange) {+ res.fail({+ status: HttpStatusCode.BAD_REQUEST_400,+ message: req.t('Cannot change video channel owner because there is already a pending ownership change for this video')+ })++ return cleanUpReqFiles(req)+ }}return next()diff --git a/server/core/models/video/video-change-ownership.ts b/server/core/models/video/video-change-ownership.tsindex 73a7c00b68..dd92a0f220 100644--- a/server/core/models/video/video-change-ownership.ts+++ b/server/core/models/video/video-change-ownership.ts@@ -1,5 +1,9 @@-import { VideoChangeOwnership, type VideoChangeOwnershipStatusType } from '@peertube/peertube-models'-import { MVideoChangeOwnershipFormattable, MVideoChangeOwnershipFull } from '@server/types/models/video/video-change-ownership.js'+import { VideoChangeOwnership, VideoChangeOwnershipStatus, type VideoChangeOwnershipStatusType } from '@peertube/peertube-models'+import {+ MVideoChangeOwnership,+ MVideoChangeOwnershipFormattable,+ MVideoChangeOwnershipFull+} 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'@@ -123,6 +127,15 @@ export class VideoChangeOwnershipModel extends SequelizeModel<VideoChangeOwnersh.findByPk(id)}+ static loadPendingByVideo (videoId: number): Promise<MVideoChangeOwnership> {+ return VideoChangeOwnershipModel.findOne({+ where: {+ videoId,+ status: VideoChangeOwnershipStatus.WAITING+ }+ })+ }+toFormattedJSON (this: MVideoChangeOwnershipFormattable): VideoChangeOwnership {return {id: this.id,diff --git a/server/core/models/video/video-channel-activity.ts b/server/core/models/video/video-channel-activity.tsindex 8c5d0a3a78..e4a5793d59 100644--- a/server/core/models/video/video-channel-activity.ts+++ b/server/core/models/video/video-channel-activity.ts@@ -9,7 +9,15 @@ import {} from '@peertube/peertube-models'import { uuidToShort } from '@peertube/peertube-node-utils'import { VIDEO_CHANNEL_ACTIVITY_ACTIONS, VIDEO_CHANNEL_ACTIVITY_TARGETS } from '@server/initializers/constants.js'-import { MChannelId, MChannelSync, MUserAccountId, MVideo, MVideoImport, MVideoPlaylist } from '@server/types/models/index.js'+import {+ MAccountActor,+ MChannelId,+ MChannelSync,+ MUserAccountId,+ MVideo,+ MVideoImport,+ MVideoPlaylist+} from '@server/types/models/index.js'import { MChannelActivityFormattable } from '@server/types/models/video/video-channel-activity.js'import { Op, Transaction } from 'sequelize'import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Table, UpdatedAt } from 'sequelize-typescript'@@ -57,6 +65,12 @@ interface VideoChannelActivityData {id: numberexternalChannelUrl: string}++ targetAccount?: {+ username: string+ displayName: string+ url: string+ }}@Table({@@ -290,6 +304,40 @@ export class VideoChannelActivityModel extends SequelizeModel<VideoChannelActivi}, { transaction })}+ static async addVideoOwnershipChangeActivity (options: {+ action: VideoChannelActivityActionType+ user: MUserAccountId+ channel: MChannelId+ video: MVideo+ targetAccount: MAccountActor+ transaction: Transaction+ }) {+ const { action, user, channel, video, targetAccount, transaction } = options++ return this.create({+ action,+ targetType: VideoChannelActivityTarget.VIDEO,+ data: {+ video: {+ id: video.id,+ name: video.name,+ uuid: video.uuid,+ url: video.url,+ isLive: video.isLive+ },+ targetAccount: {+ username: targetAccount.Actor.preferredUsername,+ displayName: targetAccount.name,+ url: targetAccount.Actor.url+ }+ },+ details: null,+ accountId: user.Account.id,+ videoChannelId: channel.id,+ videoId: video.id+ }, { transaction })+ }+static async addVideoImportActivity (options: {action: VideoChannelActivityActionTypeuser: MUserAccountId@@ -427,6 +475,7 @@ export class VideoChannelActivityModel extends SequelizeModel<VideoChannelActivichannel: this.formatChannel(),channelSync: this.formatSync(),videoImport: this.formatVideoImport(),+ targetAccount: this.formatTargetAccount(),details: this.details,createdAt: this.createdAt@@ -505,4 +554,14 @@ export class VideoChannelActivityModel extends SequelizeModel<VideoChannelActiviexternalChannelUrl: target.externalChannelUrl}}++ formatTargetAccount (): VideoChannelActivity['targetAccount'] {+ if (!this.data.targetAccount) return null++ return {+ username: this.data.targetAccount.username,+ displayName: this.data.targetAccount.displayName,+ url: this.data.targetAccount.url+ }+ }}