Skip to content

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

Cleanup ownership changes

Chocobozzzbaa297cff4b1
diff --git a/client/src/app/+my-library/my-ownership/my-accept-ownership/my-accept-ownership.component.html b/client/src/app/+my-library/my-ownership-changes/my-accept-change-ownership/my-accept-change-ownership.component.html
similarity index 82%
rename from client/src/app/+my-library/my-ownership/my-accept-ownership/my-accept-ownership.component.html
rename to client/src/app/+my-library/my-ownership-changes/my-accept-change-ownership/my-accept-change-ownership.component.html
index f18fb8e6bf..00791fb298 100644
--- a/client/src/app/+my-library/my-ownership/my-accept-ownership/my-accept-ownership.component.html
+++ b/client/src/app/+my-library/my-ownership-changes/my-accept-change-ownership/my-accept-change-ownership.component.html
@@ -1,6 +1,6 @@
<ng-template #modal let-close="close" let-dismiss="dismiss">
<div class="modal-header">
- <h1 i18n class="modal-title">Accept ownership</h1>
+ <h1 class="modal-title">{{ getModalTitle() }}</h1>
<button class="border-0 p-0" title="Close this modal" i18n-title (click)="dismiss()">
<my-global-icon iconName="cross"></my-global-icon>
@@ -9,7 +9,7 @@
<div class="modal-body" [formGroup]="form">
<div class="form-group">
- <label i18n for="channel">Select a channel to receive the video</label>
+ <label i18n for="channel">{ ownershipChanges.length, plural, =1 {Select a channel to receive the video} other {Select a channel to receive the videos}}</label>
<my-select-channel class="d-block" inputId="channel" formControlName="channel" [items]="videoChannels"></my-select-channel>
@if (formErrors.channel) {
diff --git a/client/src/app/+my-library/my-ownership/my-accept-ownership/my-accept-ownership.component.scss b/client/src/app/+my-library/my-ownership-changes/my-accept-change-ownership/my-accept-change-ownership.component.scss
similarity index 100%
rename from client/src/app/+my-library/my-ownership/my-accept-ownership/my-accept-ownership.component.scss
rename to client/src/app/+my-library/my-ownership-changes/my-accept-change-ownership/my-accept-change-ownership.component.scss
diff --git a/client/src/app/+my-library/my-ownership/my-accept-ownership/my-accept-ownership.component.ts b/client/src/app/+my-library/my-ownership-changes/my-accept-change-ownership/my-accept-change-ownership.component.ts
similarity index 58%
rename from client/src/app/+my-library/my-ownership/my-accept-ownership/my-accept-ownership.component.ts
rename to client/src/app/+my-library/my-ownership-changes/my-accept-change-ownership/my-accept-change-ownership.component.ts
index 1eb5f0b9b9..bbdaf4fdbb 100644
--- a/client/src/app/+my-library/my-ownership/my-accept-ownership/my-accept-ownership.component.ts
+++ b/client/src/app/+my-library/my-ownership-changes/my-accept-change-ownership/my-accept-change-ownership.component.ts
@@ -1,26 +1,26 @@
import { Component, ElementRef, OnInit, inject, output, viewChild } from '@angular/core'
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
import { AuthService, Notifier } from '@app/core'
-import { listUserChannelsForSelect } from '@app/helpers'
+import { formatICU, listUserChannelsForSelect } from '@app/helpers'
import { OWNERSHIP_CHANGE_CHANNEL_VALIDATOR } from '@app/shared/form-validators/video-ownership-change-validators'
import { FormReactive } from '@app/shared/shared-forms/form-reactive'
import { FormReactiveService } from '@app/shared/shared-forms/form-reactive.service'
-import { VideoOwnershipService } from '@app/shared/shared-main/video/video-ownership.service'
+import { ChangeOwnershipService } from '@app/shared/shared-main/video/change-ownership.service'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
-import { VideoChangeOwnership } from '@peertube/peertube-models'
+import { ChangeOwnership } from '@peertube/peertube-models'
import { SelectChannelItem } from '@pt-types'
import { SelectChannelComponent } from '../../../shared/shared-forms/select/select-channel.component'
import { GlobalIconComponent } from '../../../shared/shared-icons/global-icon.component'
@Component({
- selector: 'my-accept-ownership',
- templateUrl: './my-accept-ownership.component.html',
- styleUrls: [ './my-accept-ownership.component.scss' ],
+ selector: 'my-accept-change-ownership',
+ templateUrl: './my-accept-change-ownership.component.html',
+ styleUrls: [ './my-accept-change-ownership.component.scss' ],
imports: [ GlobalIconComponent, FormsModule, ReactiveFormsModule, SelectChannelComponent ]
})
-export class MyAcceptOwnershipComponent extends FormReactive implements OnInit {
+export class MyAcceptChangeOwnershipComponent extends FormReactive implements OnInit {
protected formReactiveService = inject(FormReactiveService)
- private videoOwnershipService = inject(VideoOwnershipService)
+ private changeOwnershipService = inject(ChangeOwnershipService)
private notifier = inject(Notifier)
private authService = inject(AuthService)
private modalService = inject(NgbModal)
@@ -29,7 +29,8 @@ export class MyAcceptOwnershipComponent extends FormReactive implements OnInit {
readonly modal = viewChild<ElementRef>('modal')
- videoChangeOwnership: VideoChangeOwnership | undefined = undefined
+ ownershipChanges: ChangeOwnership[] = []
+
videoChannels: SelectChannelItem[]
error: string = null
@@ -45,36 +46,47 @@ export class MyAcceptOwnershipComponent extends FormReactive implements OnInit {
})
}
- show (videoChangeOwnership: VideoChangeOwnership) {
+ show (entries: ChangeOwnership[]) {
// Select the first available channel by default
- this.form.patchValue({
- channel: this.videoChannels[0].id
- })
+ this.form.patchValue({ channel: this.videoChannels[0].id })
+
+ this.ownershipChanges = entries
- this.videoChangeOwnership = videoChangeOwnership
this.modalService
.open(this.modal(), { centered: true })
.result
.then(() => this.acceptOwnership())
.catch(() => {
- this.videoChangeOwnership = undefined
+ this.ownershipChanges = []
})
}
acceptOwnership () {
const channel = this.form.value['channel']
- const videoChangeOwnership = this.videoChangeOwnership
- this.videoOwnershipService
- .accept(videoChangeOwnership.id, { channelId: channel })
+ this.changeOwnershipService
+ .acceptVideo(this.ownershipChanges.map(change => change.id), { channelId: channel })
.subscribe({
next: () => {
- this.notifier.success($localize`Ownership accepted`)
+ const count = this.ownershipChanges.length
+
+ const message = formatICU($localize`{count, plural, =1 {Video {videoName} accepted} other {{count} videos accepted}}`, {
+ count,
+ videoName: this.ownershipChanges[0].video.name
+ })
+
+ this.notifier.success(message)
+
if (this.accepted) this.accepted.emit()
- this.videoChangeOwnership = undefined
},
error: err => this.notifier.handleError(err)
})
}
+
+ getModalTitle () {
+ const count = this.ownershipChanges.length
+
+ return formatICU($localize`{count, plural, =1 {Accept video} other {Accept {count} videos}}`, { count })
+ }
}
diff --git a/client/src/app/+my-library/my-ownership-changes/my-ownership-changes.component.html b/client/src/app/+my-library/my-ownership-changes/my-ownership-changes.component.html
new file mode 100644
index 0000000000..27b73f8ec5
--- /dev/null
+++ b/client/src/app/+my-library/my-ownership-changes/my-ownership-changes.component.html
@@ -0,0 +1,48 @@
+<my-table
+ #table
+ key="MyOwnershipChangesComponent"
+ [defaultColumns]="columns"
+ i18n-paginatorText
+ paginatorText="entries per page"
+ [dataLoader]="dataLoader"
+ columnConfig="false"
+ [bulkActions]="bulkActions"
+>
+ <ng-template #totalTitle let-totalRecords>
+ <ng-container i18n>{ totalRecords, plural, =0 {No video ownership change} =1 {1 video ownership change} other {{{ totalRecords | myNumberFormatter }} video ownership changes}}</ng-container>
+ </ng-template>
+
+ <ng-template #tableCells let-entry>
+ <td>
+ <my-video-cell [video]="entry.video" size="small"></my-video-cell>
+ </td>
+
+ <td>
+ @if (isReceiver(entry)) {
+ <span class="pt-badge badge-primary">TO YOU</span>
+ } @else {
+ <my-actor-cell [actor]="entry.nextOwnerAccount" actorType="account" [displayAvatar]="true" [displayUsername]="true" target="_blank"></my-actor-cell>
+ }
+
+ </td>
+
+ <td>{{ entry.createdAt | ptDate: 'short' }}</td>
+
+ <td>
+ <span class="pt-badge" [ngClass]="getStateClass(entry.state.id)">{{ entry.state.label }}</span>
+ </td>
+ </ng-template>
+
+ <ng-template #actionCell let-entry>
+ <my-action-dropdown
+ placement="bottom-right top-right left auto" container="body"
+ i18n-label label="Actions" [actions]="actions" [entry]="entry"
+ ></my-action-dropdown>
+ </ng-template>
+
+ <ng-template #noResults>
+ <ng-container i18n>No ownership change request found.</ng-container>
+ </ng-template>
+</my-table>
+
+<my-accept-change-ownership #myAcceptChangeOwnershipComponent (accepted)="accepted()"></my-accept-change-ownership>
diff --git a/client/src/app/+my-library/my-ownership-changes/my-ownership-changes.component.ts b/client/src/app/+my-library/my-ownership-changes/my-ownership-changes.component.ts
new file mode 100644
index 0000000000..01922cd130
--- /dev/null
+++ b/client/src/app/+my-library/my-ownership-changes/my-ownership-changes.component.ts
@@ -0,0 +1,128 @@
+import { CommonModule, NgClass } from '@angular/common'
+import { Component, inject, viewChild } from '@angular/core'
+import { AuthService, Notifier } from '@app/core'
+import { Account } from '@app/shared/shared-main/account/account.model'
+import { buildDropdownSimpleAndBulkActions } from '@app/shared/shared-main/buttons/action-dropdown-helpers'
+import { ActionDropdownComponent, DropdownAction } from '@app/shared/shared-main/buttons/action-dropdown.component'
+import { PTDatePipe } from '@app/shared/shared-main/common/date.pipe'
+import { ChangeOwnershipService } from '@app/shared/shared-main/video/change-ownership.service'
+import { ActorCellComponent } from '@app/shared/shared-tables/actor-cell.component'
+import { DataLoaderOptionsBase, TableColumnInfo, TableComponent } from '@app/shared/shared-tables/table.component'
+import { ChangeOwnership, ChangeOwnershipState, ChangeOwnershipStateType } from '@peertube/peertube-models'
+import { map } from 'rxjs'
+import { ActorAvatarComponent } from '../../shared/shared-actor-image/actor-avatar.component'
+import { NumberFormatterPipe } from '../../shared/shared-main/common/number-formatter.pipe'
+import { VideoCellComponent } from '../../shared/shared-tables/video-cell.component'
+import { MyAcceptChangeOwnershipComponent } from './my-accept-change-ownership/my-accept-change-ownership.component'
+
+@Component({
+ templateUrl: './my-ownership-changes.component.html',
+ imports: [
+ CommonModule,
+ ActorAvatarComponent,
+ NgClass,
+ MyAcceptChangeOwnershipComponent,
+ PTDatePipe,
+ VideoCellComponent,
+ NumberFormatterPipe,
+ TableComponent,
+ ActionDropdownComponent,
+ ActorCellComponent
+ ]
+})
+export class MyOwnershipChangesComponent {
+ private notifier = inject(Notifier)
+ private changeOwnershipService = inject(ChangeOwnershipService)
+ private authService = inject(AuthService)
+
+ readonly myAcceptChangeOwnershipComponent = viewChild<MyAcceptChangeOwnershipComponent>('myAcceptChangeOwnershipComponent')
+ readonly table = viewChild<TableComponent<ChangeOwnership>>('table')
+
+ actions: DropdownAction<ChangeOwnership>[][] = []
+ bulkActions: DropdownAction<ChangeOwnership[]>[][] = []
+
+ columns: TableColumnInfo<string>[] = [
+ { id: 'video', label: $localize`Video`, sortable: false },
+ { id: 'targetAccount', label: $localize`Target account`, sortable: false },
+ { id: 'createdAt', label: $localize`Created`, sortable: true },
+ { id: 'status', label: $localize`Status`, sortable: false }
+ ]
+
+ dataLoader: typeof this._dataLoader
+
+ constructor () {
+ this.dataLoader = this._dataLoader.bind(this)
+
+ const { simpleActions, bulkActions } = buildDropdownSimpleAndBulkActions<ChangeOwnership>([
+ [
+ {
+ label: $localize`Accept`,
+ handler: changeOwnership => this.openAcceptModal(changeOwnership),
+ isDisplayed: changeOwnership => this.canAcceptOrReject(changeOwnership),
+ enableBulk: true
+ },
+ {
+ label: $localize`Reject`,
+ handler: changeOwnership => this.reject(changeOwnership),
+ isDisplayed: changeOwnership => this.canAcceptOrReject(changeOwnership),
+ enableBulk: true
+ }
+ ]
+ ])
+
+ this.actions = simpleActions
+ this.bulkActions = bulkActions
+ }
+
+ private canAcceptOrReject (changeOwnership: ChangeOwnership) {
+ return this.isReceiver(changeOwnership) && changeOwnership.state.id === ChangeOwnershipState.PENDING
+ }
+
+ isReceiver (changeOwnership: ChangeOwnership) {
+ return changeOwnership.nextOwnerAccount.id === this.authService.getUser().account.id
+ }
+
+ getStateClass (status: ChangeOwnershipStateType) {
+ switch (status) {
+ case ChangeOwnershipState.ACCEPTED:
+ return 'badge-green'
+
+ case ChangeOwnershipState.REJECTED:
+ return 'badge-red'
+
+ default:
+ return 'badge-yellow'
+ }
+ }
+
+ openAcceptModal (entries: ChangeOwnership[]) {
+ this.myAcceptChangeOwnershipComponent().show(entries)
+ }
+
+ accepted () {
+ this.table().loadData()
+ }
+
+ reject (entries: ChangeOwnership[]) {
+ this.changeOwnershipService.rejectVideo(entries.map(entry => entry.id))
+ .subscribe({
+ next: () => this.table().loadData(),
+ error: err => this.notifier.handleError(err)
+ })
+ }
+
+ private _dataLoader (options: DataLoaderOptionsBase) {
+ return this.changeOwnershipService.listOfVideos(options.pagination, options.sort)
+ .pipe(
+ map(resultList => ({
+ data: resultList.data.map(change => ({
+ ...change,
+
+ initiatorAccount: new Account(change.initiatorAccount),
+ nextOwnerAccount: new Account(change.nextOwnerAccount)
+ })),
+ total: resultList.total
+ }))
+ )
+ }
+}
diff --git a/client/src/app/+my-library/my-ownership/my-ownership.component.html b/client/src/app/+my-library/my-ownership/my-ownership.component.html
deleted file mode 100644
index f22eb616d7..0000000000
--- a/client/src/app/+my-library/my-ownership/my-ownership.component.html
+++ /dev/null
@@ -1,50 +0,0 @@
-<my-table
- #table
- key="MyOwnershipComponent"
- [defaultColumns]="columns"
- i18n-paginatorText
- paginatorText="entries per page"
- [dataLoader]="dataLoader"
- columnConfig="false"
->
- <ng-template #totalTitle let-totalRecords>
- <ng-container i18n>{ totalRecords, plural, =0 {No entry} =1 {1 entry} other {{{ totalRecords | myNumberFormatter }} entries}}</ng-container>
- </ng-template>
-
- <ng-template #tableCells let-entry>
- <td>
- <a [href]="entry.initiatorAccount.url" i18n-title title="Open account in a new tab" target="_blank" rel="noopener noreferrer">
- <div class="chip two-lines">
- <my-actor-avatar [actor]="entry.initiatorAccount" actorType="account" size="32"></my-actor-avatar>
- <div>
- {{ entry.initiatorAccount.displayName }}
- <span class="muted">{{ entry.initiatorAccount.nameWithHost }}</span>
- </div>
- </div>
- </a>
- </td>
-
- <td>
- <my-video-cell [video]="entry.video" size="small"></my-video-cell>
- </td>
-
- <td>{{ entry.createdAt | ptDate: 'short' }}</td>
-
- <td>
- <span class="pt-badge" [ngClass]="getStatusClass(entry.status)">{{ entry.status }}</span>
- </td>
- </ng-template>
-
- <ng-template #actionCell let-entry>
- @if (entry.status === 'WAITING') {
- <my-button i18n-title title="Accept" icon="tick" (click)="openAcceptModal(entry)"></my-button>
- <my-button i18n-title title="Refuse" icon="cross" (click)="refuse(entry)"></my-button>
- }
- </ng-template>
-
- <ng-template #noResults>
- <ng-container i18n>No ownership change request found.</ng-container>
- </ng-template>
-</my-table>
-
-<my-accept-ownership #myAcceptOwnershipComponent (accepted)="accepted()"></my-accept-ownership>
diff --git a/client/src/app/+my-library/my-ownership/my-ownership.component.ts b/client/src/app/+my-library/my-ownership/my-ownership.component.ts
deleted file mode 100644
index d77881e781..0000000000
--- a/client/src/app/+my-library/my-ownership/my-ownership.component.ts
+++ /dev/null
@@ -1,96 +0,0 @@
-import { CommonModule, NgClass } from '@angular/common'
-import { Component, inject, viewChild } from '@angular/core'
-import { AuthService, Notifier } from '@app/core'
-import { Account } from '@app/shared/shared-main/account/account.model'
-import { PTDatePipe } from '@app/shared/shared-main/common/date.pipe'
-import { VideoOwnershipService } from '@app/shared/shared-main/video/video-ownership.service'
-import { DataLoaderOptionsBase, TableColumnInfo, TableComponent } from '@app/shared/shared-tables/table.component'
-import { VideoChangeOwnership, VideoChangeOwnershipStatus, VideoChangeOwnershipStatusType } from '@peertube/peertube-models'
-import { map } from 'rxjs'
-import { ActorAvatarComponent } from '../../shared/shared-actor-image/actor-avatar.component'
-import { ButtonComponent } from '../../shared/shared-main/buttons/button.component'
-import { NumberFormatterPipe } from '../../shared/shared-main/common/number-formatter.pipe'
-import { VideoCellComponent } from '../../shared/shared-tables/video-cell.component'
-import { MyAcceptOwnershipComponent } from './my-accept-ownership/my-accept-ownership.component'
-
-@Component({
- templateUrl: './my-ownership.component.html',
- imports: [
- CommonModule,
- ButtonComponent,
- ActorAvatarComponent,
- NgClass,
- MyAcceptOwnershipComponent,
- PTDatePipe,
- VideoCellComponent,
- NumberFormatterPipe,
- TableComponent
- ]
-})
-export class MyOwnershipComponent {
- private notifier = inject(Notifier)
- private videoOwnershipService = inject(VideoOwnershipService)
- private authService = inject(AuthService)
-
- readonly myAccountAcceptOwnershipComponent = viewChild<MyAcceptOwnershipComponent>('myAcceptOwnershipComponent')
- readonly table = viewChild<TableComponent<VideoChangeOwnership>>('table')
-
- columns: TableColumnInfo<string>[] = [
- { id: 'initiator', label: $localize`Initiator`, sortable: false },
- { id: 'video', label: $localize`Video`, sortable: false },
- { id: 'createdAt', label: $localize`Created`, sortable: true },
- { id: 'status', label: $localize`Status`, sortable: false }
- ]
-
- dataLoader: typeof this._dataLoader
-
- constructor () {
- this.dataLoader = this._dataLoader.bind(this)
- }
-
- getStatusClass (status: VideoChangeOwnershipStatusType) {
- switch (status) {
- case VideoChangeOwnershipStatus.ACCEPTED:
- return 'badge-green'
- case VideoChangeOwnershipStatus.REFUSED:
- return 'badge-red'
- default:
- return 'badge-yellow'
- }
- }
-
- openAcceptModal (videoChangeOwnership: VideoChangeOwnership) {
- this.myAccountAcceptOwnershipComponent().show(videoChangeOwnership)
- }
-
- accepted () {
- this.table().loadData()
- }
-
- refuse (videoChangeOwnership: VideoChangeOwnership) {
- this.videoOwnershipService.refuse(videoChangeOwnership.id)
- .subscribe({
- next: () => this.table().loadData(),
- error: err => this.notifier.handleError(err)
- })
- }
-
- isReceiver (videoChangeOwnership: VideoChangeOwnership) {
- return videoChangeOwnership.nextOwnerAccount.id === this.authService.getUser().account.id
- }
-
- private _dataLoader (options: DataLoaderOptionsBase) {
- return this.videoOwnershipService.list(options.pagination, options.sort)
- .pipe(
- map(resultList => ({
- data: resultList.data.map(change => ({
- ...change,
-
- initiatorAccount: new Account(change.initiatorAccount),
- nextOwnerAccount: new Account(change.nextOwnerAccount)
- })),
- total: resultList.total
- }))
- )
- }
-}
diff --git a/client/src/app/+my-library/my-videos/modals/video-change-ownership.component.ts b/client/src/app/+my-library/my-videos/modals/video-change-ownership.component.ts
index 624fbca046..64760eacb1 100644
--- a/client/src/app/+my-library/my-videos/modals/video-change-ownership.component.ts
+++ b/client/src/app/+my-library/my-videos/modals/video-change-ownership.component.ts
@@ -5,9 +5,9 @@ import { OWNERSHIP_CHANGE_USERNAME_VALIDATOR } from '@app/shared/form-validators
import { FormReactive } from '@app/shared/shared-forms/form-reactive'
import { FormReactiveService } from '@app/shared/shared-forms/form-reactive.service'
import { UserAutoCompleteComponent } from '@app/shared/shared-forms/user-auto-complete.component'
-import { VideoOwnershipService } from '@app/shared/shared-main/video/video-ownership.service'
+import { ChangeOwnershipService } from '@app/shared/shared-main/video/change-ownership.service'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
-import { VideoChangeOwnership, VideoChangeOwnershipStatus } from '@peertube/peertube-models'
+import { ChangeOwnership, ChangeOwnershipState } from '@peertube/peertube-models'
import { AutoCompleteModule } from 'primeng/autocomplete'
import { switchMap } from 'rxjs'
import { GlobalIconComponent } from '../../../shared/shared-icons/global-icon.component'
@@ -20,12 +20,12 @@ import { GlobalIconComponent } from '../../../shared/shared-icons/global-icon.co
})
export class VideoChangeOwnershipComponent extends FormReactive implements OnInit {
protected formReactiveService = inject(FormReactiveService)
- private videoOwnershipService = inject(VideoOwnershipService)
+ private changeOwnershipService = inject(ChangeOwnershipService)
private notifier = inject(Notifier)
private modalService = inject(NgbModal)
videoId = input.required<number>()
- requestSent = output<VideoChangeOwnership>()
+ requestSent = output<ChangeOwnership>()
readonly modal = viewChild<ElementRef>('modal')
@@ -48,9 +48,9 @@ export class VideoChangeOwnershipComponent extends FormReactive implements OnIni
changeOwnership () {
const username = this.form.value['username']
- this.videoOwnershipService
- .sendChangeRequest(this.videoId(), username)
- .pipe(switchMap(() => this.videoOwnershipService.listFromVideo(this.videoId(), VideoChangeOwnershipStatus.WAITING)))
+ this.changeOwnershipService
+ .sendVideoChangeRequest(this.videoId(), username)
+ .pipe(switchMap(() => this.changeOwnershipService.listFromVideo(this.videoId(), ChangeOwnershipState.PENDING)))
.subscribe({
next: ({ data }) => {
this.requestSent.emit(data[0])
diff --git a/client/src/app/+my-library/routes.ts b/client/src/app/+my-library/routes.ts
index 5671ac2990..03ee7a0460 100644
--- a/client/src/app/+my-library/routes.ts
+++ b/client/src/app/+my-library/routes.ts
@@ -17,7 +17,7 @@ import { MyFollowersComponent } from './my-follows/my-followers.component'
import { MySubscriptionsComponent } from './my-follows/my-subscriptions.component'
import { MyHistoryComponent } from './my-history/my-history.component'
import { MyLibraryComponent } from './my-library.component'
-import { MyOwnershipComponent } from './my-ownership/my-ownership.component'
+import { MyOwnershipChangesComponent } from './my-ownership-changes/my-ownership-changes.component'
import { MyVideoChannelSyncsComponent } from './my-video-channel-syncs/my-video-channel-syncs.component'
import { VideoChannelSyncEditComponent } from './my-video-channel-syncs/video-channel-sync-edit/video-channel-sync-edit.component'
import { MyVideoImportsComponent } from './my-video-imports/my-video-imports.component'
@@ -105,7 +105,7 @@ const videoSpaceRoutes = [
},
{
path: 'ownership',
- component: MyOwnershipComponent,
+ component: MyOwnershipChangesComponent,
data: {
meta: {
title: $localize`Ownership changes`
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.ts
index f15d1c34af..2086115a04 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
@@ -31,15 +31,15 @@ import { ButtonComponent } from '@app/shared/shared-main/buttons/button.componen
import { AlertComponent } from '@app/shared/shared-main/common/alert.component'
import { PeerTubeTemplateDirective } from '@app/shared/shared-main/common/peertube-template.directive'
import { InstanceService } from '@app/shared/shared-main/instance/instance.service'
-import { VideoOwnershipService } from '@app/shared/shared-main/video/video-ownership.service'
+import { ChangeOwnershipService } from '@app/shared/shared-main/video/change-ownership.service'
import { VideoService } from '@app/shared/shared-main/video/video.service'
import {
+ ChangeOwnership,
+ ChangeOwnershipState,
ConstantLabel,
HTMLServerConfig,
RegisterClientFormFieldOptions,
RegisterClientVideoFieldOptions,
- VideoChangeOwnership,
- VideoChangeOwnershipStatus,
VideoPrivacy,
VideoPrivacyType
} from '@peertube/peertube-models'
@@ -127,7 +127,7 @@ export class VideoMainInfoComponent implements OnInit, OnDestroy {
private confirmService = inject(ConfirmService)
private notifier = inject(Notifier)
private router = inject(Router)
- private videoOwnershipService = inject(VideoOwnershipService)
+ private changeOwnershipService = inject(ChangeOwnershipService)
readonly videoChangeOwnershipModal = viewChild<VideoChangeOwnershipComponent>('videoChangeOwnershipModal')
@@ -166,7 +166,7 @@ export class VideoMainInfoComponent implements OnInit, OnDestroy {
privacies: VideoPrivacyType[] = []
videoEdit: VideoEdit
- pendingOwnershipRequest: VideoChangeOwnership
+ pendingOwnershipRequest: ChangeOwnership
private schedulerInterval: any
private updatedSub: Subscription
@@ -512,7 +512,7 @@ export class VideoMainInfoComponent implements OnInit, OnDestroy {
this.videoChangeOwnershipModal().show()
}
- onChangeOwnershipRequest (ownershipChange: VideoChangeOwnership) {
+ onChangeOwnershipRequest (ownershipChange: ChangeOwnership) {
this.pendingOwnershipRequest = ownershipChange
}
@@ -522,7 +522,7 @@ export class VideoMainInfoComponent implements OnInit, OnDestroy {
const res = await this.confirmService.confirm(message, $localize`Cancel request`)
if (res === false) return
- this.videoOwnershipService.cancel(this.pendingOwnershipRequest.id)
+ this.changeOwnershipService.cancelVideo(this.pendingOwnershipRequest.id)
.subscribe({
next: () => {
this.notifier.success($localize`Ownership change request cancelled`)
@@ -534,7 +534,7 @@ export class VideoMainInfoComponent implements OnInit, OnDestroy {
}
loadOwnershipRequest () {
- this.videoOwnershipService.listFromVideo(this.videoEdit.getVideoAttributes().id, VideoChangeOwnershipStatus.WAITING)
+ this.changeOwnershipService.listFromVideo(this.videoEdit.getVideoAttributes().id, ChangeOwnershipState.PENDING)
.subscribe(({ data }) => {
if (data.length === 0) return
diff --git a/client/src/app/shared/shared-main/main-providers.ts b/client/src/app/shared/shared-main/main-providers.ts
index 95e61a8ac1..4cac4c5f69 100644
--- a/client/src/app/shared/shared-main/main-providers.ts
+++ b/client/src/app/shared/shared-main/main-providers.ts
@@ -16,7 +16,7 @@ import { RedundancyService } from './video/redundancy.service'
import { VideoChapterService } from './video/video-chapter.service'
import { VideoFileTokenService } from './video/video-file-token.service'
import { VideoImportService } from './video/video-import.service'
-import { VideoOwnershipService } from './video/video-ownership.service'
+import { ChangeOwnershipService } from './video/change-ownership.service'
import { VideoPasswordService } from './video/video-password.service'
import { VideoResolver } from './video/video.resolver'
import { VideoService } from './video/video.service'
@@ -31,7 +31,7 @@ export function getMainProviders () {
UserNotificationService,
RedundancyService,
VideoImportService,
- VideoOwnershipService,
+ ChangeOwnershipService,
VideoService,
VideoFileTokenService,
VideoResolver,
diff --git a/client/src/app/shared/shared-main/video/change-ownership.service.ts b/client/src/app/shared/shared-main/video/change-ownership.service.ts
new file mode 100644
index 0000000000..a5ce1dc964
--- /dev/null
+++ b/client/src/app/shared/shared-main/video/change-ownership.service.ts
@@ -0,0 +1,88 @@
+import { HttpClient, HttpParams } from '@angular/common/http'
+import { inject, Injectable } from '@angular/core'
+import { RestExtractor, RestPagination, RestService } from '@app/core'
+import {
+ ChangeOwnership,
+ ChangeOwnershipAccept,
+ ChangeOwnershipCreate,
+ ChangeOwnershipStateType,
+ ResultList
+} from '@peertube/peertube-models'
+import { SortMeta } from 'primeng/api'
+import { from, Observable } from 'rxjs'
+import { catchError, concatMap, toArray } from 'rxjs/operators'
+import { environment } from '../../../../environments/environment'
+
+@Injectable()
+export class ChangeOwnershipService {
+ private authHttp = inject(HttpClient)
+ private restService = inject(RestService)
+ private restExtractor = inject(RestExtractor)
+
+ private static BASE_VIDEO_CHANGE_OWNERSHIP_URL = environment.apiUrl + '/api/v1/videos/'
+
+ sendVideoChangeRequest (id: number, username: string) {
+ const url = ChangeOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + id + '/give-ownership'
+ const body: ChangeOwnershipCreate = {
+ username
+ }
+
+ return this.authHttp.post(url, body)
+ .pipe(catchError(res => this.restExtractor.handleError(res)))
+ }
+
+ listOfVideos (pagination: RestPagination, sort: SortMeta): Observable<ResultList<ChangeOwnership>> {
+ const url = ChangeOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership'
+
+ let params = new HttpParams()
+ params = this.restService.addRestGetParams(params, pagination, sort)
+
+ return this.authHttp.get<ResultList<ChangeOwnership>>(url, { params })
+ .pipe(catchError(res => this.restExtractor.handleError(res)))
+ }
+
+ listFromVideo (videoId: number, state: ChangeOwnershipStateType): Observable<ResultList<ChangeOwnership>> {
+ const url = ChangeOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + videoId + '/ownership'
+
+ let params = new HttpParams()
+ params = params.set('state', state)
+
+ return this.authHttp.get<ResultList<ChangeOwnership>>(url, { params })
+ .pipe(catchError(res => this.restExtractor.handleError(res)))
+ }
+
+ acceptVideo (ids: number[], input: ChangeOwnershipAccept) {
+ return from(ids)
+ .pipe(
+ concatMap(id => {
+ const url = ChangeOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership/' + id + '/accept'
+
+ return this.authHttp.post(url, input)
+ }),
+ toArray(),
+ catchError(err => this.restExtractor.handleError(err))
+ )
+ }
+
+ rejectVideo (ids: number[]) {
+ return from(ids)
+ .pipe(
+ concatMap(id => {
+ const url = ChangeOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership/' + id + '/refuse'
+
+ return this.authHttp.post(url, {})
+ }),
+ toArray(),
+ catchError(err => this.restExtractor.handleError(err))
+ )
+ }
+
+ cancelVideo (id: number) {
+ const url = ChangeOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership/' + id
+
+ return this.authHttp.delete(url)
+ .pipe(catchError(err => this.restExtractor.handleError(err)))
+ }
+
+ // ---------------------------------------------------------------------------
+}
diff --git a/client/src/app/shared/shared-main/video/video-ownership.service.ts b/client/src/app/shared/shared-main/video/video-ownership.service.ts
deleted file mode 100644
index 2ef3a45bfb..0000000000
--- a/client/src/app/shared/shared-main/video/video-ownership.service.ts
+++ /dev/null
@@ -1,72 +0,0 @@
-import { HttpClient, HttpParams } from '@angular/common/http'
-import { Injectable, inject } from '@angular/core'
-import { RestExtractor, RestPagination, RestService } from '@app/core'
-import {
- ResultList,
- VideoChangeOwnership,
- VideoChangeOwnershipAccept,
- VideoChangeOwnershipCreate,
- VideoChangeOwnershipStatusType
-} from '@peertube/peertube-models'
-import { SortMeta } from 'primeng/api'
-import { Observable } from 'rxjs'
-import { catchError } from 'rxjs/operators'
-import { environment } from '../../../../environments/environment'
-
-@Injectable()
-export class VideoOwnershipService {
- private authHttp = inject(HttpClient)
- private restService = inject(RestService)
- private restExtractor = inject(RestExtractor)
-
- private static BASE_VIDEO_CHANGE_OWNERSHIP_URL = environment.apiUrl + '/api/v1/videos/'
-
- sendChangeRequest (id: number, username: string) {
- const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + id + '/give-ownership'
- const body: VideoChangeOwnershipCreate = {
- username
- }
-
- return this.authHttp.post(url, body)
- .pipe(catchError(res => this.restExtractor.handleError(res)))
- }
-
- list (pagination: RestPagination, sort: SortMeta): Observable<ResultList<VideoChangeOwnership>> {
- const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership'
-
- let params = new HttpParams()
- params = this.restService.addRestGetParams(params, pagination, sort)
-
- return this.authHttp.get<ResultList<VideoChangeOwnership>>(url, { params })
- .pipe(catchError(res => this.restExtractor.handleError(res)))
- }
-
- listFromVideo (videoId: number, state: VideoChangeOwnershipStatusType): Observable<ResultList<VideoChangeOwnership>> {
- const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + videoId + '/ownership'
-
- let params = new HttpParams()
- params = params.set('state', state)
-
- return this.authHttp.get<ResultList<VideoChangeOwnership>>(url, { params })
- .pipe(catchError(res => this.restExtractor.handleError(res)))
- }
-
- accept (id: number, input: VideoChangeOwnershipAccept) {
- const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership/' + id + '/accept'
- return this.authHttp.post(url, input)
- .pipe(catchError(err => this.restExtractor.handleError(err)))
- }
-
- refuse (id: number) {
- const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership/' + id + '/refuse'
- return this.authHttp.post(url, {})
- .pipe(catchError(err => this.restExtractor.handleError(err)))
- }
-
- cancel (id: number) {
- const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership/' + id
-
- return this.authHttp.delete(url)
- .pipe(catchError(err => this.restExtractor.handleError(err)))
- }
-}
diff --git a/client/src/app/shared/shared-tables/actor-cell.component.html b/client/src/app/shared/shared-tables/actor-cell.component.html
index f6da414713..eac4c89885 100644
--- a/client/src/app/shared/shared-tables/actor-cell.component.html
+++ b/client/src/app/shared/shared-tables/actor-cell.component.html
@@ -1,11 +1,18 @@
-<a [routerLink]="routerLink" [title]="linkTitle">
+<a [routerLink]="routerLink" [title]="linkTitle" [target]="target()">
<div class="chip two-lines">
@if (displayAvatar()) {
<my-actor-avatar [actor]="actor()" [actorType]="actorType()" size="32"></my-actor-avatar>
}
<div class="information">
- <span class="fw-semibold">{{ actor().displayName }}</span>
+ <span class="fw-semibold">
+ {{ actor().displayName }}
+
+ @if (target() === '_blank') {
+ <my-global-icon iconName="external-link"></my-global-icon>
+ }
+ </span>
+
@if (displayUsername()) {
<span class="muted">{{ actor().name }}</span>
}
diff --git a/client/src/app/shared/shared-tables/actor-cell.component.ts b/client/src/app/shared/shared-tables/actor-cell.component.ts
index 31e05e4a5f..d7f1f7bf7d 100644
--- a/client/src/app/shared/shared-tables/actor-cell.component.ts
+++ b/client/src/app/shared/shared-tables/actor-cell.component.ts
@@ -2,6 +2,7 @@ import { booleanAttribute, Component, inject, input, OnInit } from '@angular/cor
import { RouterModule } from '@angular/router'
import { AuthService } from '@app/core'
import { ActorAvatarComponent, ActorAvatarInput } from '../shared-actor-image/actor-avatar.component'
+import { GlobalIconComponent } from '../shared-icons/global-icon.component'
import { CollaboratorStateComponent } from '../shared-main/channel/collaborator-state.component'
@Component({
@@ -11,7 +12,8 @@ import { CollaboratorStateComponent } from '../shared-main/channel/collaborator-
imports: [
RouterModule,
CollaboratorStateComponent,
- ActorAvatarComponent
+ ActorAvatarComponent,
+ GlobalIconComponent
]
})
export class ActorCellComponent implements OnInit {
@@ -21,6 +23,7 @@ export class ActorCellComponent implements OnInit {
actorType = input.required<'channel' | 'account'>()
displayAvatar = input(true, { transform: booleanAttribute })
displayUsername = input(true, { transform: booleanAttribute })
+ target = input<'_blank' | ''>('')
routerLink: string[]
linkTitle: string
diff --git a/client/src/sass/class-helpers/_text.scss b/client/src/sass/class-helpers/_text.scss
index 9343381809..15522582d6 100644
--- a/client/src/sass/class-helpers/_text.scss
+++ b/client/src/sass/class-helpers/_text.scss
@@ -58,6 +58,10 @@
color: pvar(--fg-500);
}
+.secondary-icon-color {
+ color: pvar(--secondary-icon-color);
+}
+
// ---------------------------------------------------------------------------
.total-items {
diff --git a/client/tsconfig.json b/client/tsconfig.json
index adbbec89ca..8edbb26d3b 100644
--- a/client/tsconfig.json
+++ b/client/tsconfig.json
@@ -1,7 +1,6 @@
{
"compileOnSave": false,
"compilerOptions": {
- "outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "bundler",
@@ -16,6 +15,8 @@
"strictBindCallApply": true,
"target": "ES2022",
"isolatedModules": true,
+ "strictPropertyInitialization": false,
+ "strictNullChecks": false,
"typeRoots": [
"node_modules/@types"
],
@@ -46,7 +47,6 @@
],
"angularCompilerOptions": {
"strictInjectionParameters": true,
- "fullTemplateTypeCheck": true,
"strictTemplates": true,
"enableI18nLegacyMessageIdFormat": false
}
diff --git a/packages/models/src/users/user-notification.model.ts b/packages/models/src/users/user-notification.model.ts
index 1b4663fb34..2084dc5494 100644
--- a/packages/models/src/users/user-notification.model.ts
+++ b/packages/models/src/users/user-notification.model.ts
@@ -174,7 +174,7 @@ export interface UserNotification {
account: ActorInfo
}
- videoOwnership?: {
+ changeOwnership?: {
id: number
initiatorAccount: ActorInfo
nextOwnerAccount: ActorInfo
diff --git a/packages/models/src/videos/change-ownership/change-ownership-accept.model.ts b/packages/models/src/videos/change-ownership/change-ownership-accept.model.ts
new file mode 100644
index 0000000000..3b78596fdc
--- /dev/null
+++ b/packages/models/src/videos/change-ownership/change-ownership-accept.model.ts
@@ -0,0 +1,3 @@
+export interface ChangeOwnershipAccept {
+ channelId: number
+}
diff --git a/packages/models/src/videos/change-ownership/change-ownership-create.model.ts b/packages/models/src/videos/change-ownership/change-ownership-create.model.ts
new file mode 100644
index 0000000000..5fb4156ecf
--- /dev/null
+++ b/packages/models/src/videos/change-ownership/change-ownership-create.model.ts
@@ -0,0 +1,3 @@
+export interface ChangeOwnershipCreate {
+ username: string
+}
diff --git a/packages/models/src/videos/change-ownership/change-ownership.model.ts b/packages/models/src/videos/change-ownership/change-ownership.model.ts
new file mode 100644
index 0000000000..d90939690e
--- /dev/null
+++ b/packages/models/src/videos/change-ownership/change-ownership.model.ts
@@ -0,0 +1,30 @@
+import { Account } from '../../actors/index.js'
+import { ConstantLabel } from '../../common/constant-label.model.js'
+import { VideoChannel } from '../channel/video-channel.model.js'
+import { Video } from '../video.model.js'
+
+export interface ChangeOwnership {
+ id: number
+
+ state: ConstantLabel<ChangeOwnershipStateType>
+
+ // Deprecated in 8.2, remove in v9
+ // Use `state` instead
+ status: 'WAITING' | 'ACCEPTED' | 'REFUSED'
+
+ initiatorAccount: Account
+ nextOwnerAccount: Account
+
+ video: Video
+ videoChannel: VideoChannel
+
+ createdAt: Date
+}
+
+export const ChangeOwnershipState = {
+ PENDING: 1,
+ REJECTED: 2,
+ ACCEPTED: 3
+} as const
+
+export type ChangeOwnershipStateType = typeof ChangeOwnershipState[keyof typeof ChangeOwnershipState]
diff --git a/packages/models/src/videos/change-ownership/index.ts b/packages/models/src/videos/change-ownership/index.ts
index 6cf568f4ef..7f76369e4b 100644
--- a/packages/models/src/videos/change-ownership/index.ts
+++ b/packages/models/src/videos/change-ownership/index.ts
@@ -1,3 +1,3 @@
-export * from './video-change-ownership-accept.model.js'
-export * from './video-change-ownership-create.model.js'
-export * from './video-change-ownership.model.js'
+export * from './change-ownership-accept.model.js'
+export * from './change-ownership-create.model.js'
+export * from './change-ownership.model.js'
diff --git a/packages/models/src/videos/change-ownership/video-change-ownership-accept.model.ts b/packages/models/src/videos/change-ownership/video-change-ownership-accept.model.ts
deleted file mode 100644
index f272476330..0000000000
--- a/packages/models/src/videos/change-ownership/video-change-ownership-accept.model.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export interface VideoChangeOwnershipAccept {
- channelId: number
-}
diff --git a/packages/models/src/videos/change-ownership/video-change-ownership-create.model.ts b/packages/models/src/videos/change-ownership/video-change-ownership-create.model.ts
deleted file mode 100644
index 40fcca285b..0000000000
--- a/packages/models/src/videos/change-ownership/video-change-ownership-create.model.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export interface VideoChangeOwnershipCreate {
- username: string
-}
diff --git a/packages/models/src/videos/change-ownership/video-change-ownership.model.ts b/packages/models/src/videos/change-ownership/video-change-ownership.model.ts
deleted file mode 100644
index 353db37f04..0000000000
--- a/packages/models/src/videos/change-ownership/video-change-ownership.model.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import { Account } from '../../actors/index.js'
-import { Video } from '../video.model.js'
-
-export interface VideoChangeOwnership {
- id: number
- status: VideoChangeOwnershipStatusType
- initiatorAccount: Account
- nextOwnerAccount: Account
- video: Video
- createdAt: Date
-}
-
-export const VideoChangeOwnershipStatus = {
- WAITING: 'WAITING',
- ACCEPTED: 'ACCEPTED',
- REFUSED: 'REFUSED'
-} as const
-
-export type VideoChangeOwnershipStatusType = typeof VideoChangeOwnershipStatus[keyof typeof VideoChangeOwnershipStatus]
diff --git a/packages/server-commands/src/videos/change-ownership-command.ts b/packages/server-commands/src/videos/change-ownership-command.ts
index 1aaad2b828..3c9da65848 100644
--- a/packages/server-commands/src/videos/change-ownership-command.ts
+++ b/packages/server-commands/src/videos/change-ownership-command.ts
@@ -1,4 +1,4 @@
-import { HttpStatusCode, ResultList, VideoChangeOwnership } from '@peertube/peertube-models'
+import { ChangeOwnership, ChangeOwnershipStateType, HttpStatusCode, ResultList } from '@peertube/peertube-models'
import { AbstractCommand, OverrideCommandOptions } from '../shared/index.js'
export class ChangeOwnershipCommand extends AbstractCommand {
@@ -24,7 +24,7 @@ export class ChangeOwnershipCommand extends AbstractCommand {
list (options: OverrideCommandOptions = {}) {
const path = '/api/v1/videos/ownership'
- return this.getRequestBody<ResultList<VideoChangeOwnership>>({
+ return this.getRequestBody<ResultList<ChangeOwnership>>({
...options,
path,
@@ -37,13 +37,13 @@ export class ChangeOwnershipCommand extends AbstractCommand {
listOfVideo (
options: OverrideCommandOptions & {
videoId: number | string
- state?: string
+ state?: ChangeOwnershipStateType
}
) {
const { videoId, state } = options
const path = '/api/v1/videos/' + videoId + '/ownership'
- return this.getRequestBody<ResultList<VideoChangeOwnership>>({
+ return this.getRequestBody<ResultList<ChangeOwnership>>({
...options,
path,
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 18d98b97fe..db43147809 100644
--- a/packages/tests/src/api/check-params/video-change-ownership.ts
+++ b/packages/tests/src/api/check-params/video-change-ownership.ts
@@ -1,6 +1,6 @@
/* oxlint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
-import { HttpStatusCode, VideoCreateResult } from '@peertube/peertube-models'
+import { ChangeOwnershipState, HttpStatusCode, VideoCreateResult } from '@peertube/peertube-models'
import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@peertube/peertube-server-commands'
import { expect } from 'chai'
@@ -144,7 +144,7 @@ describe('Test video change ownership API validator', function () {
it('Should succeed with a state filter', async function () {
const { data } = await server.changeOwnership.listOfVideo({
videoId: rootVideo.id,
- state: 'WAITING'
+ state: ChangeOwnershipState.PENDING
})
expect(data).to.be.an('array')
})
diff --git a/packages/tests/src/api/notifications/user-notifications.ts b/packages/tests/src/api/notifications/user-notifications.ts
index dd876b0c56..f429afd2da 100644
--- a/packages/tests/src/api/notifications/user-notifications.ts
+++ b/packages/tests/src/api/notifications/user-notifications.ts
@@ -586,10 +586,10 @@ describe('Test user notifications', function () {
type: UserNotificationType.VIDEO_OWNERSHIP_CHANGED_REQUEST
})
expect(notification.type).to.equal(UserNotificationType.VIDEO_OWNERSHIP_CHANGED_REQUEST)
- expect(notification.videoOwnership.id).to.exist
- expect(notification.videoOwnership.video.name).to.equal(videoName)
- expect(notification.videoOwnership.initiatorAccount.name).to.equal('root')
- expect(notification.videoOwnership.nextOwnerAccount.name).to.equal(nextOwner)
+ expect(notification.changeOwnership.id).to.exist
+ expect(notification.changeOwnership.video.name).to.equal(videoName)
+ expect(notification.changeOwnership.initiatorAccount.name).to.equal('root')
+ expect(notification.changeOwnership.nextOwnerAccount.name).to.equal(nextOwner)
})
it('Should notify the video owner when ownership change is accepted', async function () {
@@ -611,10 +611,10 @@ describe('Test user notifications', function () {
const notification = await servers[0].notifications.getLatest({ type: UserNotificationType.VIDEO_OWNERSHIP_CHANGED_ACCEPTED })
expect(notification.type).to.equal(UserNotificationType.VIDEO_OWNERSHIP_CHANGED_ACCEPTED)
- expect(notification.videoOwnership.id).to.exist
- expect(notification.videoOwnership.video.name).to.equal(videoName)
- expect(notification.videoOwnership.initiatorAccount.name).to.equal('root')
- expect(notification.videoOwnership.nextOwnerAccount.name).to.equal(nextOwner)
+ expect(notification.changeOwnership.id).to.exist
+ expect(notification.changeOwnership.video.name).to.equal(videoName)
+ expect(notification.changeOwnership.initiatorAccount.name).to.equal('root')
+ expect(notification.changeOwnership.nextOwnerAccount.name).to.equal(nextOwner)
})
it('Should notify rejected channel collaborators when ownership change is rejected', async function () {
@@ -644,10 +644,10 @@ describe('Test user notifications', function () {
type: UserNotificationType.VIDEO_OWNERSHIP_CHANGED_REJECTED
})
expect(notification.type).to.equal(UserNotificationType.VIDEO_OWNERSHIP_CHANGED_REJECTED)
- expect(notification.videoOwnership.id).to.exist
- expect(notification.videoOwnership.video.name).to.equal(videoName)
- expect(notification.videoOwnership.initiatorAccount.name).to.equal('root') // root made the request on behalf of the nextOwner user
- expect(notification.videoOwnership.nextOwnerAccount.name).to.equal(nextNextOwner)
+ expect(notification.changeOwnership.id).to.exist
+ expect(notification.changeOwnership.video.name).to.equal(videoName)
+ expect(notification.changeOwnership.initiatorAccount.name).to.equal('root') // root made the request on behalf of the nextOwner user
+ expect(notification.changeOwnership.nextOwnerAccount.name).to.equal(nextNextOwner)
})
})
diff --git a/packages/tests/src/api/videos/video-change-ownership.ts b/packages/tests/src/api/videos/video-change-ownership.ts
index 8e0c5adc86..d96c15c239 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 { HttpStatusCode, VideoChangeOwnershipStatus, VideoPrivacy } from '@peertube/peertube-models'
+import { ChangeOwnershipState, HttpStatusCode, VideoPrivacy } from '@peertube/peertube-models'
import {
ChangeOwnershipCommand,
cleanupTests,
@@ -218,7 +218,7 @@ describe('Test video change ownership - nominal', function () {
await command.delete({ ownershipId: ownershipChangeId, token: firstUserToken })
- const bodyAfterDelete = await command.listOfVideo({ videoId: liveId, state: VideoChangeOwnershipStatus.WAITING })
+ const bodyAfterDelete = await command.listOfVideo({ videoId: liveId, state: ChangeOwnershipState.PENDING })
expect(bodyAfterDelete.total).to.equal(0)
})
@@ -249,17 +249,21 @@ describe('Test video change ownership - nominal', function () {
expect(body.data[0].video.id).to.equal(servers[0].store.videoCreated.id)
expect(body.data.map(i => i.status)).to.have.members([ 'ACCEPTED', 'REFUSED' ])
+ expect(body.data.map(i => i.state.label)).to.have.members([ 'Accepted', 'Rejected' ])
+ expect(body.data.map(i => i.state.id)).to.have.members([ ChangeOwnershipState.ACCEPTED, ChangeOwnershipState.REJECTED ])
})
it('Should list ownership changes with state filter', async function () {
const body = await command.listOfVideo({
videoId: servers[0].store.videoCreated.id,
- state: 'ACCEPTED'
+ state: ChangeOwnershipState.ACCEPTED
})
expect(body.total).to.equal(1)
expect(body.data[0].status).to.equal('ACCEPTED')
+ expect(body.data[0].state.id).to.equal(ChangeOwnershipState.ACCEPTED)
+ expect(body.data[0].state.label).to.equal('Accepted')
})
after(async function () {
diff --git a/server/core/controllers/api/videos/ownership.ts b/server/core/controllers/api/videos/ownership.ts
index 4436d2c4d4..d03a8fb9ad 100644
--- a/server/core/controllers/api/videos/ownership.ts
+++ b/server/core/controllers/api/videos/ownership.ts
@@ -1,9 +1,4 @@
-import {
- HttpStatusCode,
- VideoChangeOwnershipStatus,
- VideoChangeOwnershipStatusType,
- VideoChannelActivityAction
-} from '@peertube/peertube-models'
+import { ChangeOwnershipState, ChangeOwnershipStateType, HttpStatusCode, 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 { MVideoFull } from '@server/types/models/index.js'
@@ -20,13 +15,13 @@ import {
authenticate,
paginationValidator,
setDefaultPagination,
- videosAcceptChangeOwnershipValidator,
- videosChangeOwnershipValidator,
- videosDeleteChangeOwnershipValidator,
- videosListVideoOwnershipChangesValidator,
- videosTerminateChangeOwnershipValidator
+ acceptVideoChangeOwnershipValidator,
+ changeVideoOwnershipValidator,
+ deleteChangeOwnershipValidator,
+ listVideoOwnershipChangesValidator,
+ acceptOrRejectChangeOwnershipValidator
} from '../../../middlewares/index.js'
-import { VideoChangeOwnershipModel } from '../../../models/video/video-change-ownership.js'
+import { ChangeOwnershipModel } from '../../../models/video/change-ownership.js'
import { VideoChannelModel } from '../../../models/video/video-channel.js'
import { VideoModel } from '../../../models/video/video.js'
@@ -35,14 +30,14 @@ const ownershipVideoRouter = express.Router()
ownershipVideoRouter.post(
'/:videoId/give-ownership',
authenticate,
- asyncMiddleware(videosChangeOwnershipValidator),
- asyncRetryTransactionMiddleware(giveVideoOwnership)
+ asyncMiddleware(changeVideoOwnershipValidator),
+ asyncRetryTransactionMiddleware(createChangeOwnershipRequest)
)
ownershipVideoRouter.get(
'/:videoId/ownership',
authenticate,
- asyncMiddleware(videosListVideoOwnershipChangesValidator),
+ asyncMiddleware(listVideoOwnershipChangesValidator),
paginationValidator,
setDefaultPagination,
asyncRetryTransactionMiddleware(listVideoOwnershipChanges)
@@ -53,29 +48,29 @@ ownershipVideoRouter.get(
authenticate,
paginationValidator,
setDefaultPagination,
- asyncRetryTransactionMiddleware(listAccountOwnershipChanges)
+ asyncRetryTransactionMiddleware(listAccountVideoOwnershipChanges)
)
ownershipVideoRouter.post(
'/ownership/:id/accept',
authenticate,
- asyncMiddleware(videosTerminateChangeOwnershipValidator),
- asyncMiddleware(videosAcceptChangeOwnershipValidator),
- asyncRetryTransactionMiddleware(acceptOwnership)
+ asyncMiddleware(acceptOrRejectChangeOwnershipValidator),
+ asyncMiddleware(acceptVideoChangeOwnershipValidator),
+ asyncRetryTransactionMiddleware(acceptOwnershipChange)
)
ownershipVideoRouter.post(
'/ownership/:id/refuse',
authenticate,
- asyncMiddleware(videosTerminateChangeOwnershipValidator),
- asyncRetryTransactionMiddleware(refuseOwnership)
+ asyncMiddleware(acceptOrRejectChangeOwnershipValidator),
+ asyncRetryTransactionMiddleware(refuseOwnershipChange)
)
ownershipVideoRouter.delete(
'/ownership/:id',
authenticate,
- asyncMiddleware(videosDeleteChangeOwnershipValidator),
- asyncRetryTransactionMiddleware(deleteOwnership)
+ asyncMiddleware(deleteChangeOwnershipValidator),
+ asyncRetryTransactionMiddleware(deleteOwnershipChange)
)
// ---------------------------------------------------------------------------
@@ -86,29 +81,29 @@ export {
// ---------------------------------------------------------------------------
-async function giveVideoOwnership (req: express.Request, res: express.Response) {
+async function createChangeOwnershipRequest (req: express.Request, res: express.Response) {
const video = res.locals.videoWithRights
const initiatorAccountId = res.locals.oauth.token.User.Account.id
- const nextOwner = res.locals.videoChangeOwnershipNextOwner
+ const nextOwner = res.locals.changeOwnershipNextOwner
const ownershipChange = await sequelizeTypescript.transaction(async t => {
- const [ ownershipChange ] = await VideoChangeOwnershipModel.findOrCreate({
+ const [ ownershipChange ] = await ChangeOwnershipModel.findOrCreate({
where: {
initiatorAccountId,
nextOwnerAccountId: nextOwner.id,
videoId: video.id,
- status: VideoChangeOwnershipStatus.WAITING
+ state: ChangeOwnershipState.PENDING
},
defaults: {
initiatorAccountId,
nextOwnerAccountId: nextOwner.id,
videoId: video.id,
- status: VideoChangeOwnershipStatus.WAITING
+ state: ChangeOwnershipState.PENDING
},
transaction: t
})
- await VideoChannelActivityModel.addVideoOwnershipChangeActivity({
+ await VideoChannelActivityModel.addOwnershipChangeActivity({
action: VideoChannelActivityAction.SEND_OWNERSHIP_REQUEST,
user: res.locals.oauth.token.User,
channel: video.VideoChannel,
@@ -120,7 +115,7 @@ async function giveVideoOwnership (req: express.Request, res: express.Response)
return ownershipChange
})
- const ownershipChangeFull = await VideoChangeOwnershipModel.load(ownershipChange.id)
+ const ownershipChangeFull = await ChangeOwnershipModel.load(ownershipChange.id)
Notifier.Instance.notifyOfRequestedVideoOwnershipChange(ownershipChangeFull)
@@ -131,9 +126,9 @@ async function giveVideoOwnership (req: express.Request, res: express.Response)
async function listVideoOwnershipChanges (req: express.Request, res: express.Response) {
const videoId = res.locals.videoWithRights.id
- const state = req.query.state as VideoChangeOwnershipStatusType
+ const state = req.query.state as ChangeOwnershipStateType
- const resultList = await VideoChangeOwnershipModel.listForApi({
+ const resultList = await ChangeOwnershipModel.listForVideoApi({
videoId,
state,
start: req.query.start,
@@ -144,10 +139,10 @@ async function listVideoOwnershipChanges (req: express.Request, res: express.Res
return res.json(getFormattedObjects(resultList.data, resultList.total))
}
-async function listAccountOwnershipChanges (req: express.Request, res: express.Response) {
+async function listAccountVideoOwnershipChanges (req: express.Request, res: express.Response) {
const currentAccountId = res.locals.oauth.token.User.Account.id
- const resultList = await VideoChangeOwnershipModel.listForApi({
+ const resultList = await ChangeOwnershipModel.listForVideoApi({
accountId: currentAccountId,
start: req.query.start,
count: req.query.count,
@@ -157,13 +152,13 @@ async function listAccountOwnershipChanges (req: express.Request, res: express.R
return res.json(getFormattedObjects(resultList.data, resultList.total))
}
-function acceptOwnership (req: express.Request, res: express.Response) {
+function acceptOwnershipChange (req: express.Request, res: express.Response) {
return sequelizeTypescript.transaction(async t => {
- const videoChangeOwnership = res.locals.videoChangeOwnership
+ const changeOwnership = res.locals.changeOwnership
const channel = res.locals.videoChannel
// We need more attributes for federation
- const targetVideo = await VideoModel.loadFull(videoChangeOwnership.Video.id, t)
+ const targetVideo = await VideoModel.loadFull(changeOwnership.Video.id, t)
const oldVideoChannel = await VideoChannelModel.loadAndPopulateAccount(targetVideo.channelId, t)
@@ -177,67 +172,67 @@ function acceptOwnership (req: express.Request, res: express.Response) {
await sendUpdateVideo(targetVideoUpdated, t, oldVideoChannel.Account.Actor)
}
- videoChangeOwnership.status = VideoChangeOwnershipStatus.ACCEPTED
- await videoChangeOwnership.save({ transaction: t })
+ changeOwnership.state = ChangeOwnershipState.ACCEPTED
+ await changeOwnership.save({ transaction: t })
for (const channel of [ oldVideoChannel, targetVideoUpdated.VideoChannel ]) {
- await VideoChannelActivityModel.addVideoOwnershipChangeActivity({
+ await VideoChannelActivityModel.addOwnershipChangeActivity({
action: VideoChannelActivityAction.ACCEPT_OWNERSHIP_REQUEST,
user: res.locals.oauth.token.User,
channel,
video: targetVideoUpdated,
- targetAccount: videoChangeOwnership.NextOwner,
+ targetAccount: changeOwnership.NextOwner,
transaction: t
})
}
- Notifier.Instance.notifyOfAcceptedVideoOwnershipChange(videoChangeOwnership)
+ Notifier.Instance.notifyOfAcceptedVideoOwnershipChange(changeOwnership)
return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
})
}
-function refuseOwnership (req: express.Request, res: express.Response) {
+function refuseOwnershipChange (req: express.Request, res: express.Response) {
return sequelizeTypescript.transaction(async t => {
- const videoChangeOwnership = res.locals.videoChangeOwnership
+ const changeOwnership = res.locals.changeOwnership
- videoChangeOwnership.status = VideoChangeOwnershipStatus.REFUSED
- await videoChangeOwnership.save({ transaction: t })
+ changeOwnership.state = ChangeOwnershipState.REJECTED
+ await changeOwnership.save({ transaction: t })
- const channel = await VideoChannelModel.loadAndPopulateAccount(videoChangeOwnership.Video.channelId, t)
+ const channel = await VideoChannelModel.loadAndPopulateAccount(changeOwnership.Video.channelId, t)
- await VideoChannelActivityModel.addVideoOwnershipChangeActivity({
+ await VideoChannelActivityModel.addOwnershipChangeActivity({
action: VideoChannelActivityAction.REFUSE_OWNERSHIP_REQUEST,
user: res.locals.oauth.token.User,
channel,
- video: videoChangeOwnership.Video,
- targetAccount: videoChangeOwnership.NextOwner,
+ video: changeOwnership.Video,
+ targetAccount: changeOwnership.NextOwner,
transaction: t
})
- Notifier.Instance.notifyOfRejectedVideoOwnershipChange(videoChangeOwnership)
+ Notifier.Instance.notifyOfRejectedVideoOwnershipChange(changeOwnership)
return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
})
}
-function deleteOwnership (req: express.Request, res: express.Response) {
+function deleteOwnershipChange (req: express.Request, res: express.Response) {
return sequelizeTypescript.transaction(async t => {
- const videoChangeOwnership = res.locals.videoChangeOwnership
- const channel = await VideoChannelModel.loadAndPopulateAccount(videoChangeOwnership.Video.channelId, t)
+ const changeOwnership = res.locals.changeOwnership
+ const channel = await VideoChannelModel.loadAndPopulateAccount(changeOwnership.Video.channelId, t)
- await videoChangeOwnership.destroy({ transaction: t })
+ await changeOwnership.destroy({ transaction: t })
- await VideoChannelActivityModel.addVideoOwnershipChangeActivity({
+ await VideoChannelActivityModel.addOwnershipChangeActivity({
action: VideoChannelActivityAction.DELETE_OWNERSHIP_REQUEST,
user: res.locals.oauth.token.User,
channel,
- video: videoChangeOwnership.Video,
- targetAccount: videoChangeOwnership.NextOwner,
+ video: changeOwnership.Video,
+ targetAccount: changeOwnership.NextOwner,
transaction: t
})
- logger.info('Ownership change request %d deleted.', videoChangeOwnership.id)
+ logger.info('Ownership change request %d deleted.', changeOwnership.id)
return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
})
diff --git a/server/core/initializers/constants.ts b/server/core/initializers/constants.ts
index 4f8be94ad8..5d0f14b7d0 100644
--- a/server/core/initializers/constants.ts
+++ b/server/core/initializers/constants.ts
@@ -5,6 +5,8 @@ import {
ActivityPubActorType,
ActorImageType,
ActorImageType_Type,
+ ChangeOwnershipState,
+ ChangeOwnershipStateType,
FollowState,
JobType,
NSFWPolicyType,
@@ -60,7 +62,7 @@ import { CONFIG, registerConfigChangedHandler } from './config.js'
// ---------------------------------------------------------------------------
-export const LAST_MIGRATION_VERSION = 1015
+export const LAST_MIGRATION_VERSION = 1025
// ---------------------------------------------------------------------------
@@ -759,6 +761,12 @@ export const VIDEO_EMBED_PRIVACY_POLICIES: { [id in VideoEmbedPrivacyPolicyType]
[VideoEmbedPrivacyPolicy.REMOTE_RESTRICTIONS]: 'Remote restrictions'
}
+export const CHANGE_OWNERSHIP_STATES: { [id in ChangeOwnershipStateType]: string } = {
+ [ChangeOwnershipState.PENDING]: 'Pending',
+ [ChangeOwnershipState.ACCEPTED]: 'Accepted',
+ [ChangeOwnershipState.REJECTED]: 'Rejected'
+}
+
export const MIMETYPES = {
AUDIO: {
MIMETYPE_EXT: {
diff --git a/server/core/initializers/database.ts b/server/core/initializers/database.ts
index fb59a5a8c6..701ca735fc 100644
--- a/server/core/initializers/database.ts
+++ b/server/core/initializers/database.ts
@@ -61,7 +61,7 @@ import { TagModel } from '../models/video/tag.js'
import { ThumbnailModel } from '../models/video/thumbnail.js'
import { VideoBlacklistModel } from '../models/video/video-blacklist.js'
import { VideoCaptionModel } from '../models/video/video-caption.js'
-import { VideoChangeOwnershipModel } from '../models/video/video-change-ownership.js'
+import { ChangeOwnershipModel } from '../models/video/change-ownership.js'
import { VideoChannelModel } from '../models/video/video-channel.js'
import { VideoCommentModel } from '../models/video/video-comment.js'
import { VideoFileModel } from '../models/video/video-file.js'
@@ -160,7 +160,7 @@ export async function initDatabaseModels (silent: boolean) {
VideoCommentAbuseModel,
VideoAbuseModel,
VideoModel,
- VideoChangeOwnershipModel,
+ ChangeOwnershipModel,
VideoChannelModel,
VideoShareModel,
VideoFileModel,
diff --git a/server/core/initializers/migrations/1020-channel-change-ownership.ts b/server/core/initializers/migrations/1020-channel-change-ownership.ts
new file mode 100644
index 0000000000..e18a6f204e
--- /dev/null
+++ b/server/core/initializers/migrations/1020-channel-change-ownership.ts
@@ -0,0 +1,54 @@
+import * as Sequelize from 'sequelize'
+
+async function up (utils: {
+ transaction: Sequelize.Transaction
+ queryInterface: Sequelize.QueryInterface
+ sequelize: Sequelize.Sequelize
+}): Promise<void> {
+ const { transaction } = utils
+
+ {
+ await utils.queryInterface.renameTable('videoChangeOwnership', 'changeOwnership', { transaction })
+ }
+
+ {
+ await utils.sequelize.query(
+ `ALTER TABLE "changeOwnership" ` +
+ `ADD COLUMN "videoChannelId" INTEGER REFERENCES "videoChannel" ("id") ON DELETE CASCADE ON UPDATE CASCADE`,
+ { transaction }
+ )
+
+ await utils.sequelize.query(
+ `ALTER TABLE "changeOwnership" ALTER COLUMN "videoId" DROP NOT NULL`,
+ { transaction }
+ )
+ }
+
+ {
+ await utils.queryInterface.addColumn('changeOwnership', 'state', {
+ type: Sequelize.INTEGER,
+ allowNull: true
+ }, { transaction })
+
+ await utils.sequelize.query('UPDATE "changeOwnership" SET "state" = 1 WHERE "status" = \'WAITING\'', { transaction })
+ await utils.sequelize.query('UPDATE "changeOwnership" SET "state" = 3 WHERE "status" = \'ACCEPTED\'', { transaction })
+ await utils.sequelize.query('UPDATE "changeOwnership" SET "state" = 2 WHERE "state" IS NULL', { transaction })
+
+ await utils.queryInterface.changeColumn('changeOwnership', 'state', {
+ type: Sequelize.INTEGER,
+ allowNull: false,
+ defaultValue: null
+ }, { transaction })
+
+ await utils.queryInterface.removeColumn('changeOwnership', 'status', { transaction })
+ }
+}
+
+function down () {
+ throw new Error('Not implemented.')
+}
+
+export {
+ down,
+ up
+}
diff --git a/server/core/initializers/migrations/1025-change-ownership-notification.ts b/server/core/initializers/migrations/1025-change-ownership-notification.ts
new file mode 100644
index 0000000000..13a045488e
--- /dev/null
+++ b/server/core/initializers/migrations/1025-change-ownership-notification.ts
@@ -0,0 +1,22 @@
+import * as Sequelize from 'sequelize'
+
+async function up (utils: {
+ transaction: Sequelize.Transaction
+ queryInterface: Sequelize.QueryInterface
+ sequelize: Sequelize.Sequelize
+}): Promise<void> {
+ const { transaction } = utils
+
+ {
+ await utils.queryInterface.renameColumn('userNotification', 'videoOwnershipId', 'changeOwnershipId', { transaction })
+ }
+}
+
+function down () {
+ throw new Error('Not implemented.')
+}
+
+export {
+ down,
+ up
+}
diff --git a/server/core/lib/notifier/notifier.ts b/server/core/lib/notifier/notifier.ts
index eb868c2504..372169b417 100644
--- a/server/core/lib/notifier/notifier.ts
+++ b/server/core/lib/notifier/notifier.ts
@@ -8,6 +8,7 @@ import {
MAbuseMessage,
MActorFollowFull,
MApplication,
+ MChangeOwnershipFull,
MChannelAccountDefault,
MChannelCollaboratorAccount,
MChannelDefault,
@@ -15,7 +16,6 @@ import {
MPlugin,
MVideoAccountLight,
MVideoCaptionVideo,
- MVideoChangeOwnershipFull,
MVideoFull,
MVideoWithSchedule
} from '../../types/models/index.js'
@@ -53,9 +53,9 @@ import {
UnblacklistForOwner,
VideoTranscriptionGeneratedForOwner
} from './shared/index.js'
-import { RequestVideoOwnershipChange } from './shared/video-ownership/request-video-ownership-change.js'
-import { VideoOwnershipChangeAccepted } from './shared/video-ownership/video-ownership-change-accepted.js'
-import { VideoOwnershipChangeRejected } from './shared/video-ownership/video-ownership-change-rejected.js'
+import { RequestVideoChangeOwnership } from './shared/video-change-ownership/request-video-change-ownership.js'
+import { VideoChangeOwnershipAccepted } from './shared/video-change-ownership/video-change-ownership-accepted.js'
+import { VideoChangeOwnershipRejected } from './shared/video-change-ownership/video-change-ownership-rejected.js'
const lTags = loggerTagsFactory('notifier')
@@ -96,9 +96,9 @@ class Notifier {
channelCollaborationAccepted: [ AcceptedToCollaborateToChannel ],
channelCollaborationRefused: [ RefusedToCollaborateToChannel ],
- videoOwnershipRequest: [ RequestVideoOwnershipChange ],
- videoOwnershipAccepted: [ VideoOwnershipChangeAccepted ],
- videoOwnershipRejected: [ VideoOwnershipChangeRejected ]
+ changeVideoOwnershipRequest: [ RequestVideoChangeOwnership ],
+ changeVideoOwnershipAccepted: [ VideoChangeOwnershipAccepted ],
+ changeVideoOwnershipRejected: [ VideoChangeOwnershipRejected ]
}
private static instance: Notifier
@@ -354,31 +354,31 @@ class Notifier {
// Video ownership change notifications
// ---------------------------------------------------------------------------
- notifyOfRequestedVideoOwnershipChange (videoOwnership: MVideoChangeOwnershipFull) {
- const models = this.notificationModels.videoOwnershipRequest
+ notifyOfRequestedVideoOwnershipChange (changeOwnership: MChangeOwnershipFull) {
+ const models = this.notificationModels.changeVideoOwnershipRequest
- logger.debug('Notify on requested video ownership change', { id: videoOwnership.id, video: videoOwnership.Video.url, ...lTags() })
+ logger.debug('Notify on requested video ownership change', { id: changeOwnership.id, video: changeOwnership.Video.url, ...lTags() })
- this.sendNotifications(models, videoOwnership)
- .catch(err => logger.error('Cannot notify requested video ownership change %d.', videoOwnership.id, { err }))
+ this.sendNotifications(models, changeOwnership)
+ .catch(err => logger.error('Cannot notify requested video ownership change %d.', changeOwnership.id, { err }))
}
- notifyOfAcceptedVideoOwnershipChange (videoOwnership: MVideoChangeOwnershipFull) {
- const models = this.notificationModels.videoOwnershipAccepted
+ notifyOfAcceptedVideoOwnershipChange (changeOwnership: MChangeOwnershipFull) {
+ const models = this.notificationModels.changeVideoOwnershipAccepted
- logger.debug('Notify on accepted video ownership change', { id: videoOwnership.id, video: videoOwnership.Video.url, ...lTags() })
+ logger.debug('Notify on accepted video ownership change', { id: changeOwnership.id, video: changeOwnership.Video.url, ...lTags() })
- this.sendNotifications(models, videoOwnership)
- .catch(err => logger.error('Cannot notify accepted video ownership change %d.', videoOwnership.id, { err }))
+ this.sendNotifications(models, changeOwnership)
+ .catch(err => logger.error('Cannot notify accepted video ownership change %d.', changeOwnership.id, { err }))
}
- notifyOfRejectedVideoOwnershipChange (videoOwnership: MVideoChangeOwnershipFull) {
- const models = this.notificationModels.videoOwnershipRejected
+ notifyOfRejectedVideoOwnershipChange (changeOwnership: MChangeOwnershipFull) {
+ const models = this.notificationModels.changeVideoOwnershipRejected
- logger.debug('Notify on rejected video ownership change', { id: videoOwnership.id, video: videoOwnership.Video.url, ...lTags() })
+ logger.debug('Notify on rejected video ownership change', { id: changeOwnership.id, video: changeOwnership.Video.url, ...lTags() })
- this.sendNotifications(models, videoOwnership)
- .catch(err => logger.error('Cannot notify rejected video ownership change %d.', videoOwnership.id, { err }))
+ this.sendNotifications(models, changeOwnership)
+ .catch(err => logger.error('Cannot notify rejected video ownership change %d.', changeOwnership.id, { err }))
}
// ---------------------------------------------------------------------------
diff --git a/server/core/lib/notifier/shared/index.ts b/server/core/lib/notifier/shared/index.ts
index bc0d1594a0..745bcfc375 100644
--- a/server/core/lib/notifier/shared/index.ts
+++ b/server/core/lib/notifier/shared/index.ts
@@ -5,5 +5,5 @@ export * from './comment/index.js'
export * from './common/index.js'
export * from './follow/index.js'
export * from './instance/index.js'
-export * from './video-ownership/index.js'
+export * from './video-change-ownership/index.js'
export * from './video-publication/index.js'
diff --git a/server/core/lib/notifier/shared/video-ownership/abstract-video-ownership-response.ts b/server/core/lib/notifier/shared/video-change-ownership/abstract-video-change-ownership-response.ts
similarity index 75%
rename from server/core/lib/notifier/shared/video-ownership/abstract-video-ownership-response.ts
rename to server/core/lib/notifier/shared/video-change-ownership/abstract-video-change-ownership-response.ts
index d9b0a837eb..92247290c9 100644
--- a/server/core/lib/notifier/shared/video-ownership/abstract-video-ownership-response.ts
+++ b/server/core/lib/notifier/shared/video-change-ownership/abstract-video-change-ownership-response.ts
@@ -1,11 +1,11 @@
import { UserNotificationSettingValue, UserNotificationType_Type } from '@peertube/peertube-models'
import { UserModel } from '@server/models/user/user.js'
import { MUserWithNotificationSetting } from '@server/types/models/index.js'
-import { MVideoChangeOwnershipFull } from '@server/types/models/video/video-change-ownership.js'
+import { MChangeOwnershipFull } from '@server/types/models/video/change-ownership.js'
import { AbstractNotification } from '../common/abstract-notification.js'
-import { buildVideoOwnershipNotification } from './video-ownership-utils.js'
+import { buildVideoChangeOwnershipNotification } from './video-change-ownership-utils.js'
-export abstract class AbstractVideoOwnershipResponse extends AbstractNotification<MVideoChangeOwnershipFull> {
+export abstract class AbstractVideoChangeOwnershipResponse extends AbstractNotification<MChangeOwnershipFull> {
protected users: MUserWithNotificationSetting[] = []
async prepare () {
@@ -25,7 +25,7 @@ export abstract class AbstractVideoOwnershipResponse extends AbstractNotificatio
}
createNotification (user: MUserWithNotificationSetting) {
- return buildVideoOwnershipNotification({
+ return buildVideoChangeOwnershipNotification({
user,
payload: this.payload,
notificationType: this.getNotificationType()
diff --git a/server/core/lib/notifier/shared/video-change-ownership/index.ts b/server/core/lib/notifier/shared/video-change-ownership/index.ts
new file mode 100644
index 0000000000..9bdfd6f1d9
--- /dev/null
+++ b/server/core/lib/notifier/shared/video-change-ownership/index.ts
@@ -0,0 +1,3 @@
+export * from './request-video-change-ownership.js'
+export * from './video-change-ownership-accepted.js'
+export * from './video-change-ownership-rejected.js'
diff --git a/server/core/lib/notifier/shared/video-ownership/request-video-ownership-change.ts b/server/core/lib/notifier/shared/video-change-ownership/request-video-change-ownership.ts
similarity index 84%
rename from server/core/lib/notifier/shared/video-ownership/request-video-ownership-change.ts
rename to server/core/lib/notifier/shared/video-change-ownership/request-video-change-ownership.ts
index f737a25504..80e98ffaf6 100644
--- a/server/core/lib/notifier/shared/video-ownership/request-video-ownership-change.ts
+++ b/server/core/lib/notifier/shared/video-change-ownership/request-video-change-ownership.ts
@@ -4,11 +4,11 @@ import { logger } from '@server/helpers/logger.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { UserModel } from '@server/models/user/user.js'
import { MUserDefault, MUserWithNotificationSetting } from '@server/types/models/index.js'
-import { MVideoChangeOwnershipFull } from '@server/types/models/video/video-change-ownership.js'
+import { MChangeOwnershipFull } from '@server/types/models/video/change-ownership.js'
import { AbstractNotification } from '../common/abstract-notification.js'
-import { buildVideoOwnershipNotification } from './video-ownership-utils.js'
+import { buildVideoChangeOwnershipNotification } from './video-change-ownership-utils.js'
-export class RequestVideoOwnershipChange extends AbstractNotification<MVideoChangeOwnershipFull> {
+export class RequestVideoChangeOwnership extends AbstractNotification<MChangeOwnershipFull> {
private user: MUserDefault
async prepare () {
@@ -34,7 +34,7 @@ export class RequestVideoOwnershipChange extends AbstractNotification<MVideoChan
}
createNotification (user: MUserWithNotificationSetting) {
- return buildVideoOwnershipNotification({
+ return buildVideoChangeOwnershipNotification({
user,
payload: this.payload,
notificationType: UserNotificationType.VIDEO_OWNERSHIP_CHANGED_REQUEST
diff --git a/server/core/lib/notifier/shared/video-ownership/video-ownership-change-accepted.ts b/server/core/lib/notifier/shared/video-change-ownership/video-change-ownership-accepted.ts
similarity index 86%
rename from server/core/lib/notifier/shared/video-ownership/video-ownership-change-accepted.ts
rename to server/core/lib/notifier/shared/video-change-ownership/video-change-ownership-accepted.ts
index 390541858b..c3aeaf8cf2 100644
--- a/server/core/lib/notifier/shared/video-ownership/video-ownership-change-accepted.ts
+++ b/server/core/lib/notifier/shared/video-change-ownership/video-change-ownership-accepted.ts
@@ -3,9 +3,9 @@ import { t } from '@server/helpers/i18n.js'
import { logger } from '@server/helpers/logger.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { MUserWithNotificationSetting } from '@server/types/models/index.js'
-import { AbstractVideoOwnershipResponse } from './abstract-video-ownership-response.js'
+import { AbstractVideoChangeOwnershipResponse } from './abstract-video-change-ownership-response.js'
-export class VideoOwnershipChangeAccepted extends AbstractVideoOwnershipResponse {
+export class VideoChangeOwnershipAccepted extends AbstractVideoChangeOwnershipResponse {
log () {
logger.info('Notifying source channel members that ownership change of %s was accepted.', this.payload.Video.url)
}
diff --git a/server/core/lib/notifier/shared/video-ownership/video-ownership-change-rejected.ts b/server/core/lib/notifier/shared/video-change-ownership/video-change-ownership-rejected.ts
similarity index 86%
rename from server/core/lib/notifier/shared/video-ownership/video-ownership-change-rejected.ts
rename to server/core/lib/notifier/shared/video-change-ownership/video-change-ownership-rejected.ts
index b4db8eef6e..149f557c74 100644
--- a/server/core/lib/notifier/shared/video-ownership/video-ownership-change-rejected.ts
+++ b/server/core/lib/notifier/shared/video-change-ownership/video-change-ownership-rejected.ts
@@ -3,9 +3,9 @@ import { t } from '@server/helpers/i18n.js'
import { logger } from '@server/helpers/logger.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { MUserWithNotificationSetting } from '@server/types/models/index.js'
-import { AbstractVideoOwnershipResponse } from './abstract-video-ownership-response.js'
+import { AbstractVideoChangeOwnershipResponse } from './abstract-video-change-ownership-response.js'
-export class VideoOwnershipChangeRejected extends AbstractVideoOwnershipResponse {
+export class VideoChangeOwnershipRejected extends AbstractVideoChangeOwnershipResponse {
log () {
logger.info('Notifying source channel members that ownership change of %s was rejected.', this.payload.Video.url)
}
diff --git a/server/core/lib/notifier/shared/video-ownership/video-ownership-utils.ts b/server/core/lib/notifier/shared/video-change-ownership/video-change-ownership-utils.ts
similarity index 67%
rename from server/core/lib/notifier/shared/video-ownership/video-ownership-utils.ts
rename to server/core/lib/notifier/shared/video-change-ownership/video-change-ownership-utils.ts
index b7cab3bf15..ee26d90136 100644
--- a/server/core/lib/notifier/shared/video-ownership/video-ownership-utils.ts
+++ b/server/core/lib/notifier/shared/video-change-ownership/video-change-ownership-utils.ts
@@ -1,11 +1,11 @@
import { UserNotificationType_Type } from '@peertube/peertube-models'
import { UserNotificationModel } from '@server/models/user/user-notification.js'
import { MUserId, UserNotificationModelForApi } from '@server/types/models/user/index.js'
-import { MVideoChangeOwnershipFull } from '@server/types/models/video/video-change-ownership.js'
+import { MChangeOwnershipFull } from '@server/types/models/video/change-ownership.js'
-export function buildVideoOwnershipNotification (options: {
+export function buildVideoChangeOwnershipNotification (options: {
user: MUserId
- payload: MVideoChangeOwnershipFull
+ payload: MChangeOwnershipFull
notificationType: UserNotificationType_Type
}): UserNotificationModelForApi {
const { user, payload, notificationType } = options
@@ -13,10 +13,10 @@ export function buildVideoOwnershipNotification (options: {
const notification = UserNotificationModel.build<UserNotificationModelForApi>({
type: notificationType,
userId: user.id,
- videoOwnershipId: payload.id
+ changeOwnershipId: payload.id
})
- notification.VideoOwnership = payload
+ notification.ChangeOwnership = payload
return notification
}
diff --git a/server/core/lib/notifier/shared/video-ownership/index.ts b/server/core/lib/notifier/shared/video-ownership/index.ts
deleted file mode 100644
index 1a03fc1e1a..0000000000
--- a/server/core/lib/notifier/shared/video-ownership/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export * from './request-video-ownership-change.js'
-export * from './video-ownership-change-accepted.js'
-export * from './video-ownership-change-rejected.js'
diff --git a/server/core/middlewares/validators/shared/change-ownerships.ts b/server/core/middlewares/validators/shared/change-ownerships.ts
new file mode 100644
index 0000000000..9d0bd89c9f
--- /dev/null
+++ b/server/core/middlewares/validators/shared/change-ownerships.ts
@@ -0,0 +1,21 @@
+import { forceNumber } from '@peertube/peertube-core-utils'
+import { HttpStatusCode } from '@peertube/peertube-models'
+import { ChangeOwnershipModel } from '@server/models/video/change-ownership.js'
+import express from 'express'
+
+export async function doesChangeOwnershipExist (idArg: number | string, req: express.Request, res: express.Response) {
+ const id = forceNumber(idArg)
+ const changeOwnership = await ChangeOwnershipModel.load(id)
+
+ if (!changeOwnership) {
+ res.fail({
+ status: HttpStatusCode.NOT_FOUND_404,
+ message: req.t('Ownership change not found')
+ })
+ return false
+ }
+
+ res.locals.changeOwnership = changeOwnership
+
+ return true
+}
diff --git a/server/core/middlewares/validators/shared/index.ts b/server/core/middlewares/validators/shared/index.ts
index 6bb552b326..1c77496de7 100644
--- a/server/core/middlewares/validators/shared/index.ts
+++ b/server/core/middlewares/validators/shared/index.ts
@@ -9,7 +9,7 @@ export * from './video-channels.js'
export * from './video-channel-syncs.js'
export * from './video-comments.js'
export * from './video-imports.js'
-export * from './video-ownerships.js'
+export * from './change-ownerships.js'
export * from './video-playlists.js'
export * from './video-passwords.js'
export * from './videos.js'
diff --git a/server/core/middlewares/validators/shared/video-ownerships.ts b/server/core/middlewares/validators/shared/video-ownerships.ts
deleted file mode 100644
index a0394bc309..0000000000
--- a/server/core/middlewares/validators/shared/video-ownerships.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import express from 'express'
-import { VideoChangeOwnershipModel } from '@server/models/video/video-change-ownership.js'
-import { forceNumber } from '@peertube/peertube-core-utils'
-import { HttpStatusCode } from '@peertube/peertube-models'
-
-export async function doesChangeVideoOwnershipExist (idArg: number | string, req: express.Request, res: express.Response) {
- const id = forceNumber(idArg)
- const videoChangeOwnership = await VideoChangeOwnershipModel.load(id)
-
- if (!videoChangeOwnership) {
- res.fail({
- status: HttpStatusCode.NOT_FOUND_404,
- message: req.t('Video ownership change not found')
- })
- return false
- }
-
- res.locals.videoChangeOwnership = videoChangeOwnership
-
- return true
-}
diff --git a/server/core/middlewares/validators/videos/video-ownership-changes.ts b/server/core/middlewares/validators/videos/change-ownership.ts
similarity index 53%
rename from server/core/middlewares/validators/videos/video-ownership-changes.ts
rename to server/core/middlewares/validators/videos/change-ownership.ts
index de1edd5293..b6d198ddb4 100644
--- a/server/core/middlewares/validators/videos/video-ownership-changes.ts
+++ b/server/core/middlewares/validators/videos/change-ownership.ts
@@ -1,8 +1,10 @@
-import { HttpStatusCode, UserRight, VideoChangeOwnershipAccept, VideoChangeOwnershipStatus, VideoState } from '@peertube/peertube-models'
-import { isIdValid } from '@server/helpers/custom-validators/misc.js'
+import { ChangeOwnershipAccept, ChangeOwnershipState, HttpStatusCode, UserRight, VideoState } from '@peertube/peertube-models'
+import { exists, isIdValid } from '@server/helpers/custom-validators/misc.js'
import { CONFIG } from '@server/initializers/config.js'
+import { CHANGE_OWNERSHIP_STATES } from '@server/initializers/constants.js'
import { AccountModel } from '@server/models/account/account.js'
-import { MUserAccountId, MVideoChangeOwnershipFull, MVideoWithAllFiles } from '@server/types/models/index.js'
+import { ChangeOwnershipModel } from '@server/models/video/change-ownership.js'
+import { VideoModel } from '@server/models/video/video.js'
import express from 'express'
import { param, query } from 'express-validator'
import {
@@ -10,15 +12,13 @@ import {
checkCanManageAccount,
checkCanManageVideo,
checkUserQuota,
- doesChangeVideoOwnershipExist,
+ doesChangeOwnershipExist,
doesChannelIdExist,
doesVideoExist,
isValidVideoIdParam
} from '../shared/index.js'
-import { VideoChangeOwnershipModel } from '@server/models/video/video-change-ownership.js'
-import { VideoModel } from '@server/models/video/video.js'
-export const videosChangeOwnershipValidator = [
+export const changeVideoOwnershipValidator = [
isValidVideoIdParam('videoId'),
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
@@ -46,7 +46,7 @@ export const videosChangeOwnershipValidator = [
return
}
- const existing = await VideoChangeOwnershipModel.loadPendingByVideo(res.locals.videoWithRights.id)
+ const existing = await ChangeOwnershipModel.loadPendingByVideo(res.locals.videoWithRights.id)
if (existing) {
res.fail({
status: HttpStatusCode.BAD_REQUEST_400,
@@ -55,35 +55,37 @@ export const videosChangeOwnershipValidator = [
return
}
- res.locals.videoChangeOwnershipNextOwner = nextOwner
+ res.locals.changeOwnershipNextOwner = nextOwner
return next()
}
]
-export const videosTerminateChangeOwnershipValidator = [
+export const acceptOrRejectChangeOwnershipValidator = [
param('id')
.custom(isIdValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
if (areValidationErrors(req, res)) return
- if (!await doesChangeVideoOwnershipExist(req.params.id, req, res)) return
+ if (!await doesChangeOwnershipExist(req.params.id, req, res)) return
// Check if the user who did the request is able to change the ownership of the video
- if (
- !checkCanTerminateOwnershipChange({
- user: res.locals.oauth.token.User,
- videoChangeOwnership: res.locals.videoChangeOwnership,
- req,
- res
+ const user = res.locals.oauth.token.User
+ const videoChangeOwnership = res.locals.changeOwnership
+
+ if (!checkCanManageAccount({ user, account: videoChangeOwnership.NextOwner, req, res: null, specialRight: UserRight.MANAGE_USERS })) {
+ res.fail({
+ status: HttpStatusCode.FORBIDDEN_403,
+ message: req.t('Cannot terminate an ownership change of another user')
})
- ) return
+ return
+ }
- const videoChangeOwnership = res.locals.videoChangeOwnership
+ const changeOwnership = res.locals.changeOwnership
- if (videoChangeOwnership.status !== VideoChangeOwnershipStatus.WAITING) {
+ if (changeOwnership.state !== ChangeOwnershipState.PENDING) {
res.fail({
status: HttpStatusCode.BAD_REQUEST_400,
- message: req.t('Ownership already accepted or refused')
+ message: req.t('Ownership change request already accepted or refused')
})
return
}
@@ -92,31 +94,40 @@ export const videosTerminateChangeOwnershipValidator = [
}
]
-export const videosAcceptChangeOwnershipValidator = [
+export const acceptVideoChangeOwnershipValidator = [
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
- const body = req.body as VideoChangeOwnershipAccept
+ const body = req.body as ChangeOwnershipAccept
if (!await doesChannelIdExist({ id: body.channelId, req, res, checkCanManage: true, checkIsLocal: true, checkIsOwner: true })) return
- const videoChangeOwnership = res.locals.videoChangeOwnership
+ const videoChangeOwnership = res.locals.changeOwnership
const video = await VideoModel.loadWithFiles(videoChangeOwnership.Video.id)
- if (!await checkCanAccept(video, req, res)) return
+ if (video.isLive) {
+ if (video.state !== VideoState.WAITING_FOR_LIVE) {
+ res.fail({
+ status: HttpStatusCode.BAD_REQUEST_400,
+ message: req.t('You cannot accept an ownership change of a published live.')
+ })
+
+ return
+ }
+ } else {
+ const channelUser = res.locals.oauth.token.User
+
+ if (!await checkUserQuota({ channelUser, videoFileSize: video.getMaxQualityBytes(), req, res })) return
+ }
return next()
}
]
-export const videosListVideoOwnershipChangesValidator = [
+export const listVideoOwnershipChangesValidator = [
isValidVideoIdParam('videoId'),
query('state')
.optional()
- .custom(value => {
- if (!Object.values(VideoChangeOwnershipStatus).includes(value)) return false
-
- return true
- }),
+ .custom(value => exists(value) && CHANGE_OWNERSHIP_STATES[value] !== undefined),
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
if (areValidationErrors(req, res)) return
@@ -139,17 +150,17 @@ export const videosListVideoOwnershipChangesValidator = [
}
]
-export const videosDeleteChangeOwnershipValidator = [
+export const deleteChangeOwnershipValidator = [
param('id')
.custom(isIdValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
if (areValidationErrors(req, res)) return
- if (!await doesChangeVideoOwnershipExist(req.params.id, req, res)) return
+ if (!await doesChangeOwnershipExist(req.params.id, req, res)) return
- const videoChangeOwnership = res.locals.videoChangeOwnership
+ const videoChangeOwnership = res.locals.changeOwnership
- if (videoChangeOwnership.status !== VideoChangeOwnershipStatus.WAITING) {
+ if (videoChangeOwnership.state !== ChangeOwnershipState.PENDING) {
res.fail({
status: HttpStatusCode.BAD_REQUEST_400,
message: req.t('Ownership already accepted or refused')
@@ -174,48 +185,3 @@ export const videosDeleteChangeOwnershipValidator = [
return next()
}
]
-
-// ---------------------------------------------------------------------------
-// Private
-// ---------------------------------------------------------------------------
-
-async function checkCanAccept (video: MVideoWithAllFiles, req: express.Request, res: express.Response): Promise<boolean> {
- if (video.isLive) {
- if (video.state !== VideoState.WAITING_FOR_LIVE) {
- res.fail({
- status: HttpStatusCode.BAD_REQUEST_400,
- message: req.t('You cannot accept an ownership change of a published live.')
- })
-
- return false
- }
-
- return true
- }
-
- const channelUser = res.locals.oauth.token.User
-
- if (!await checkUserQuota({ channelUser, videoFileSize: video.getMaxQualityBytes(), req, res })) return false
-
- return true
-}
-
-function checkCanTerminateOwnershipChange (options: {
- user: MUserAccountId
- videoChangeOwnership: MVideoChangeOwnershipFull
- req: express.Request
- res: express.Response
-}) {
- const { user, videoChangeOwnership, req, res } = options
-
- if (!checkCanManageAccount({ user, account: videoChangeOwnership.NextOwner, req, res: null, specialRight: UserRight.MANAGE_USERS })) {
- res.fail({
- status: HttpStatusCode.FORBIDDEN_403,
- message: req.t('Cannot terminate an ownership change of another user')
- })
-
- return false
- }
-
- return true
-}
diff --git a/server/core/middlewares/validators/videos/index.ts b/server/core/middlewares/validators/videos/index.ts
index 0b3a020c9f..a3812d8fdb 100644
--- a/server/core/middlewares/validators/videos/index.ts
+++ b/server/core/middlewares/validators/videos/index.ts
@@ -8,7 +8,7 @@ export * from './video-embed-privacy.js'
export * from './video-files.js'
export * from './video-imports.js'
export * from './video-live.js'
-export * from './video-ownership-changes.js'
+export * from './change-ownership.js'
export * from './video-passwords.js'
export * from './video-rates.js'
export * from './video-shares.js'
diff --git a/server/core/middlewares/validators/videos/videos.ts b/server/core/middlewares/validators/videos/videos.ts
index bf9355d690..be64c24c8c 100644
--- a/server/core/middlewares/validators/videos/videos.ts
+++ b/server/core/middlewares/validators/videos/videos.ts
@@ -10,7 +10,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 { ChangeOwnershipModel } from '@server/models/video/change-ownership.js'
import { ExpressPromiseHandler } from '@server/types/express-handler.js'
import { MVideoFull } from '@server/types/models/index.js'
import express from 'express'
@@ -258,7 +258,7 @@ export const videosUpdateValidator = getCommonVideoEditAttributes().concat([
// Not the same account as original video channel
if (targetChannel && targetChannel.accountId !== video.VideoChannel.accountId) {
- const ownershipChange = await VideoChangeOwnershipModel.loadPendingByVideo(video.id)
+ const ownershipChange = await ChangeOwnershipModel.loadPendingByVideo(video.id)
if (ownershipChange) {
res.fail({
diff --git a/server/core/models/shared/model-builder.ts b/server/core/models/shared/model-builder.ts
index 87bb47f9c9..e5a60ff99c 100644
--- a/server/core/models/shared/model-builder.ts
+++ b/server/core/models/shared/model-builder.ts
@@ -43,8 +43,7 @@ export class ModelBuilder<T extends SequelizeModel> {
VideoChannelCollaborators: 'VideoChannelCollaboratorModel',
Tags: 'TagModel',
Initiator: 'AccountModel',
- NextOwner: 'AccountModel',
- VideoOwnership: 'VideoChangeOwnershipModel'
+ NextOwner: 'AccountModel'
}
constructor (private readonly sequelize: Sequelize) {
diff --git a/server/core/models/user/sql/user-notification/user-notification-list-query-builder.ts b/server/core/models/user/sql/user-notification/user-notification-list-query-builder.ts
index 2ad5d38084..62133a512c 100644
--- a/server/core/models/user/sql/user-notification/user-notification-list-query-builder.ts
+++ b/server/core/models/user/sql/user-notification/user-notification-list-query-builder.ts
@@ -148,13 +148,14 @@ export class UserNotificationListQueryBuilder extends AbstractListQuery {
...this.getAccountOrChannelAttributes('ChannelCollab->Channel->Account', 'ChannelCollab.Channel.Account'),
...this.getAccountOrChannelAttributes('ChannelCollab->Channel', 'ChannelCollab.Channel'),
- `"VideoOwnership"."id" AS "VideoOwnership.id"`,
- ...this.getAccountOrChannelAttributes('VideoOwnership->Initiator', 'VideoOwnership.Initiator'),
- ...this.getAccountOrChannelAttributes('VideoOwnership->NextOwner', 'VideoOwnership.NextOwner'),
- `"VideoOwnership->Video"."id" AS "VideoOwnership.Video.id"`,
- `"VideoOwnership->Video"."uuid" AS "VideoOwnership.Video.uuid"`,
- `"VideoOwnership->Video"."name" AS "VideoOwnership.Video.name"`,
- `"VideoOwnership->Video"."state" AS "VideoOwnership.Video.state"`
+ `"ChangeOwnership"."id" AS "ChangeOwnership.id"`,
+ ...this.getAccountOrChannelAttributes('ChangeOwnership->Initiator', 'ChangeOwnership.Initiator'),
+ ...this.getAccountOrChannelAttributes('ChangeOwnership->NextOwner', 'ChangeOwnership.NextOwner'),
+ `"ChangeOwnership->Video"."id" AS "ChangeOwnership.Video.id"`,
+ `"ChangeOwnership->Video"."uuid" AS "ChangeOwnership.Video.uuid"`,
+ `"ChangeOwnership->Video"."name" AS "ChangeOwnership.Video.name"`,
+ `"ChangeOwnership->Video"."state" AS "ChangeOwnership.Video.state"`,
+ ...this.getAccountOrChannelAttributes('ChangeOwnership->Channel', 'ChangeOwnership.Channel')
]
}
@@ -162,12 +163,12 @@ export class UserNotificationListQueryBuilder extends AbstractListQuery {
this.join = `
LEFT JOIN (
"video" AS "Video"
- ${this.getChannelJoin('Video', 'channelId')}
+ ${this.getChannelJoin({ tableName: 'Video', columnJoin: 'channelId' })}
) ON "UserNotificationModel"."videoId" = "Video"."id"
LEFT JOIN (
"videoComment" AS "VideoComment"
- ${this.getAccountJoin('VideoComment', 'accountId')}
+ ${this.getAccountJoin({ tableName: 'VideoComment', columnJoin: 'accountId' })}
INNER JOIN "video" AS "VideoComment->Video" ON "VideoComment"."videoId" = "VideoComment->Video"."id"
) ON "UserNotificationModel"."commentId" = "VideoComment"."id"
@@ -181,7 +182,7 @@ export class UserNotificationListQueryBuilder extends AbstractListQuery {
ON "Abuse->VideoCommentAbuse->VideoComment"."videoId" = "Abuse->VideoCommentAbuse->VideoComment->Video"."id"
LEFT JOIN (
"account" AS "Abuse->FlaggedAccount"
- ${this.getActorJoin('Abuse->FlaggedAccount', 'accountId')}
+ ${this.getActorJoin({ tableName: 'Abuse->FlaggedAccount', column: 'accountId' })}
) ON "Abuse"."flaggedAccountId" = "Abuse->FlaggedAccount"."id"
LEFT JOIN (
@@ -214,7 +215,7 @@ export class UserNotificationListQueryBuilder extends AbstractListQuery {
LEFT JOIN (
"account" AS "Account"
- ${this.getActorJoin('Account', 'accountId')}
+ ${this.getActorJoin({ tableName: 'Account', column: 'accountId' })}
) ON "UserNotificationModel"."accountId" = "Account"."id"
LEFT JOIN "userRegistration" as "UserRegistration" ON "UserNotificationModel"."userRegistrationId" = "UserRegistration"."id"
@@ -226,17 +227,18 @@ export class UserNotificationListQueryBuilder extends AbstractListQuery {
LEFT JOIN (
"videoChannelCollaborator" AS "ChannelCollab"
- ${this.getAccountJoin('ChannelCollab', 'accountId')}
- ${this.getChannelJoin('ChannelCollab', 'channelId', 'Channel')}
- ${this.getAccountJoin('ChannelCollab->Channel', 'accountId')}
+ ${this.getAccountJoin({ tableName: 'ChannelCollab', columnJoin: 'accountId' })}
+ ${this.getChannelJoin({ tableName: 'ChannelCollab', columnJoin: 'channelId', aliasTableName: 'Channel' })}
+ ${this.getAccountJoin({ tableName: 'ChannelCollab->Channel', columnJoin: 'accountId' })}
) ON "UserNotificationModel"."channelCollaboratorId" = "ChannelCollab"."id"
LEFT JOIN (
- "videoChangeOwnership" AS "VideoOwnership"
- ${this.getAccountJoin('VideoOwnership', 'initiatorAccountId', 'Initiator')}
- ${this.getAccountJoin('VideoOwnership', 'nextOwnerAccountId', 'NextOwner')}
- INNER JOIN "video" AS "VideoOwnership->Video" ON "VideoOwnership"."videoId" = "VideoOwnership->Video"."id"
- ) ON "UserNotificationModel"."videoOwnershipId" = "VideoOwnership"."id"`
+ "changeOwnership" AS "ChangeOwnership"
+ ${this.getAccountJoin({ tableName: 'ChangeOwnership', columnJoin: 'initiatorAccountId', aliasTableName: 'Initiator' })}
+ ${this.getAccountJoin({ tableName: 'ChangeOwnership', columnJoin: 'nextOwnerAccountId', aliasTableName: 'NextOwner' })}
+ LEFT JOIN "video" AS "ChangeOwnership->Video" ON "ChangeOwnership"."videoId" = "ChangeOwnership->Video"."id"
+ ${this.getChannelJoin({ tableName: 'ChangeOwnership', columnJoin: 'videoChannelId', aliasTableName: 'Channel', joinType: 'LEFT' })}
+ ) ON "UserNotificationModel"."changeOwnershipId" = "ChangeOwnership"."id"`
}
// ---------------------------------------------------------------------------
@@ -256,19 +258,39 @@ export class UserNotificationListQueryBuilder extends AbstractListQuery {
]
}
- private getAccountJoin (tableName: string, columnJoin: string, aliasTableName = 'Account') {
- return `INNER JOIN "account" AS "${tableName}->${aliasTableName}" ON "${tableName}"."${columnJoin}" = "${tableName}->${aliasTableName}"."id" ` +
- this.getActorJoin(`${tableName}->${aliasTableName}`, 'accountId')
+ private getAccountJoin (options: {
+ tableName: string
+ columnJoin: string
+ aliasTableName?: string
+ joinType?: 'INNER' | 'LEFT'
+ }) {
+ const { tableName, columnJoin, aliasTableName = 'Account', joinType = 'INNER' } = options
+
+ return `${joinType} JOIN "account" AS "${tableName}->${aliasTableName}" ON "${tableName}"."${columnJoin}" = "${tableName}->${aliasTableName}"."id" ` +
+ this.getActorJoin({ tableName: `${tableName}->${aliasTableName}`, column: 'accountId', joinType })
}
- private getChannelJoin (tableName: string, columnJoin: string, aliasTableName = 'VideoChannel') {
+ private getChannelJoin (options: {
+ tableName: string
+ columnJoin: string
+ aliasTableName?: string
+ joinType?: 'INNER' | 'LEFT'
+ }) {
+ const { tableName, columnJoin, aliasTableName = 'VideoChannel', joinType = 'INNER' } = options
+
// oxlint-disable-next-line max-len
- return `INNER JOIN "videoChannel" AS "${tableName}->${aliasTableName}" ON "${tableName}"."${columnJoin}" = "${tableName}->${aliasTableName}".id ` +
- this.getActorJoin(`${tableName}->${aliasTableName}`, 'videoChannelId')
+ return `${joinType} JOIN "videoChannel" AS "${tableName}->${aliasTableName}" ON "${tableName}"."${columnJoin}" = "${tableName}->${aliasTableName}".id ` +
+ this.getActorJoin({ tableName: `${tableName}->${aliasTableName}`, column: 'videoChannelId', joinType })
}
- private getActorJoin (tableName: string, column: string) {
- return `INNER JOIN "actor" AS "${tableName}->Actor" ON "${tableName}"."id" = "${tableName}->Actor"."${column}" ` +
+ private getActorJoin (options: {
+ tableName: string
+ column: string
+ joinType?: 'INNER' | 'LEFT'
+ }) {
+ const { tableName, column, joinType = 'INNER' } = options
+
+ return `${joinType} JOIN "actor" AS "${tableName}->Actor" ON "${tableName}"."id" = "${tableName}->Actor"."${column}" ` +
this.getActorImageJoin(`${tableName}->Actor`) +
this.getActorServerJoin(`${tableName}->Actor`)
}
diff --git a/server/core/models/user/user-notification.ts b/server/core/models/user/user-notification.ts
index 5b78652018..0248a7ed5b 100644
--- a/server/core/models/user/user-notification.ts
+++ b/server/core/models/user/user-notification.ts
@@ -17,7 +17,7 @@ import { VideoBlacklistModel } from '../video/video-blacklist.js'
import { VideoCaptionModel } from '../video/video-caption.js'
import { VideoChannelCollaboratorModel } from '../video/video-channel-collaborator.js'
import { VideoCommentModel } from '../video/video-comment.js'
-import { VideoChangeOwnershipModel } from '../video/video-change-ownership.js'
+import { ChangeOwnershipModel } from '../video/change-ownership.js'
import { VideoImportModel } from '../video/video-import.js'
import { VideoModel } from '../video/video.js'
import { UserNotificationListQueryBuilder } from './sql/user-notification/user-notification-list-query-builder.js'
@@ -127,9 +127,9 @@ import { UserModel } from './user.js'
}
},
{
- fields: [ 'videoOwnershipId' ],
+ fields: [ 'changeOwnershipId' ],
where: {
- videoOwnershipId: {
+ changeOwnershipId: {
[Op.ne]: null
}
}
@@ -315,17 +315,17 @@ export class UserNotificationModel extends SequelizeModel<UserNotificationModel>
})
declare VideoChannelCollaborator: Awaited<VideoChannelCollaboratorModel>
- @ForeignKey(() => VideoChangeOwnershipModel)
+ @ForeignKey(() => ChangeOwnershipModel)
@Column
- declare videoOwnershipId: number
+ declare changeOwnershipId: number
- @BelongsTo(() => VideoChangeOwnershipModel, {
+ @BelongsTo(() => ChangeOwnershipModel, {
foreignKey: {
allowNull: true
},
onDelete: 'cascade'
})
- declare VideoOwnership: Awaited<VideoChangeOwnershipModel>
+ declare ChangeOwnership: Awaited<ChangeOwnershipModel>
static listForApi (options: {
userId: number
@@ -435,6 +435,15 @@ export class UserNotificationModel extends SequelizeModel<UserNotificationModel>
`INNER JOIN actor ON "actor"."accountId" = "account"."id" `
),
+ // Remove notifications from muted accounts that invited us to collaborate to a channel
+ buildAccountWhereQuery(
+ `SELECT "userNotification"."id" FROM "userNotification" ` +
+ `INNER JOIN "videoChannelCollaborator" ON "videoChannelCollaborator".id = "userNotification"."channelCollaboratorId" ` +
+ `INNER JOIN "videoChannel" ON "videoChannel".id = "videoChannelCollaborator"."channelId" ` +
+ `INNER JOIN "account" ON "videoChannel"."accountId" = "account"."id" ` +
+ `INNER JOIN actor ON "actor"."accountId" = "account"."id" `
+ ),
+
// Remove notifications from muted accounts that invited us to collaborate to a channel
buildAccountWhereQuery(
`SELECT "userNotification"."id" FROM "userNotification" ` +
@@ -558,12 +567,19 @@ export class UserNotificationModel extends SequelizeModel<UserNotificationModel>
}
: undefined
- const videoOwnership = this.VideoOwnership
+ const changeOwnership = this.ChangeOwnership
? {
- id: this.VideoOwnership.id,
- initiatorAccount: this.formatActor(this.VideoOwnership.Initiator),
- nextOwnerAccount: this.formatActor(this.VideoOwnership.NextOwner),
- video: this.formatVideo(this.VideoOwnership.Video)
+ id: this.ChangeOwnership.id,
+ initiatorAccount: this.formatActor(this.ChangeOwnership.Initiator),
+ nextOwnerAccount: this.formatActor(this.ChangeOwnership.NextOwner),
+
+ video: this.ChangeOwnership.Video
+ ? this.formatVideo(this.ChangeOwnership.Video)
+ : undefined,
+
+ videoChannel: this.ChangeOwnership.VideoChannel
+ ? this.formatActor(this.ChangeOwnership.VideoChannel)
+ : undefined
}
: undefined
@@ -584,7 +600,7 @@ export class UserNotificationModel extends SequelizeModel<UserNotificationModel>
registration,
videoCaption,
videoChannelCollaborator,
- videoOwnership,
+ changeOwnership,
createdAt: this.createdAt.toISOString(),
updatedAt: this.updatedAt.toISOString()
}
diff --git a/server/core/models/video/change-ownership.ts b/server/core/models/video/change-ownership.ts
new file mode 100644
index 0000000000..907f13d06e
--- /dev/null
+++ b/server/core/models/video/change-ownership.ts
@@ -0,0 +1,150 @@
+import { ChangeOwnership, ChangeOwnershipState, type ChangeOwnershipStateType } from '@peertube/peertube-models'
+import { CHANGE_OWNERSHIP_STATES } from '@server/initializers/constants.js'
+import { MChangeOwnership, MChangeOwnershipFull } from '@server/types/models/video/change-ownership.js'
+import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Table, UpdatedAt } from 'sequelize-typescript'
+import { AccountModel } from '../account/account.js'
+import { SequelizeModel, buildSQLAttributes } from '../shared/index.js'
+import { ChangeOwnershipListQueryBuilder, ListChangeOwnershipOptions } from './sql/change-ownership/change-ownership-list-query-builder.js'
+import { VideoChannelModel } from './video-channel.js'
+import { VideoModel } from './video.js'
+
+@Table({
+ tableName: 'changeOwnership',
+ indexes: [
+ {
+ fields: [ 'videoId' ]
+ },
+ {
+ fields: [ 'videoChannelId' ]
+ },
+ {
+ fields: [ 'initiatorAccountId' ]
+ },
+ {
+ fields: [ 'nextOwnerAccountId' ]
+ }
+ ]
+})
+export class ChangeOwnershipModel extends SequelizeModel<ChangeOwnershipModel> {
+ @CreatedAt
+ declare createdAt: Date
+
+ @UpdatedAt
+ declare updatedAt: Date
+
+ @AllowNull(false)
+ @Column
+ declare state: ChangeOwnershipStateType
+
+ @ForeignKey(() => AccountModel)
+ @Column
+ declare initiatorAccountId: number
+
+ @BelongsTo(() => AccountModel, {
+ foreignKey: {
+ name: 'initiatorAccountId',
+ allowNull: false
+ },
+ onDelete: 'cascade'
+ })
+ declare Initiator: Awaited<AccountModel>
+
+ @ForeignKey(() => AccountModel)
+ @Column
+ declare nextOwnerAccountId: number
+
+ @BelongsTo(() => AccountModel, {
+ foreignKey: {
+ name: 'nextOwnerAccountId',
+ allowNull: false
+ },
+ onDelete: 'cascade'
+ })
+ declare NextOwner: Awaited<AccountModel>
+
+ @ForeignKey(() => VideoModel)
+ @Column
+ declare videoId: number
+
+ @BelongsTo(() => VideoModel, {
+ foreignKey: {
+ allowNull: true
+ },
+ onDelete: 'cascade'
+ })
+ declare Video: Awaited<VideoModel>
+
+ @ForeignKey(() => VideoChannelModel)
+ @Column
+ declare videoChannelId: number
+
+ @BelongsTo(() => VideoChannelModel, {
+ foreignKey: {
+ allowNull: true
+ },
+ onDelete: 'cascade'
+ })
+ declare VideoChannel: Awaited<VideoChannelModel>
+
+ static getSQLAttributes (tableName: string, aliasPrefix = '') {
+ return buildSQLAttributes({
+ model: this,
+ tableName,
+ aliasPrefix
+ })
+ }
+
+ // ---------------------------------------------------------------------------
+
+ static load (id: number): Promise<MChangeOwnershipFull> {
+ return new ChangeOwnershipListQueryBuilder(ChangeOwnershipModel.sequelize, { id }).get<MChangeOwnershipFull>()
+ }
+
+ // ---------------------------------------------------------------------------
+
+ static listForVideoApi (options: ListChangeOwnershipOptions) {
+ const queryOptions = { ...options, type: 'video' as const }
+
+ return Promise.all([
+ new ChangeOwnershipListQueryBuilder(ChangeOwnershipModel.sequelize, queryOptions).list<MChangeOwnershipFull>(),
+ new ChangeOwnershipListQueryBuilder(ChangeOwnershipModel.sequelize, queryOptions).count()
+ ]).then(([ rows, total ]) => ({ total, data: rows }))
+ }
+
+ static loadPendingByVideo (videoId: number): Promise<MChangeOwnership> {
+ return new ChangeOwnershipListQueryBuilder(ChangeOwnershipModel.sequelize, {
+ type: 'video',
+ videoId,
+ state: ChangeOwnershipState.PENDING
+ }).get<MChangeOwnershipFull>()
+ }
+
+ // ---------------------------------------------------------------------------
+
+ toFormattedJSON (this: MChangeOwnershipFull): ChangeOwnership {
+ let status: ChangeOwnership['status']
+
+ if (this.state === ChangeOwnershipState.PENDING) status = 'WAITING'
+ else if (this.state === ChangeOwnershipState.ACCEPTED) status = 'ACCEPTED'
+ else if (this.state === ChangeOwnershipState.REJECTED) status = 'REFUSED'
+
+ return {
+ id: this.id,
+
+ state: {
+ id: this.state,
+ label: CHANGE_OWNERSHIP_STATES[this.state]
+ },
+
+ status,
+
+ initiatorAccount: this.Initiator.toFormattedJSON(),
+ nextOwnerAccount: this.NextOwner.toFormattedJSON(),
+
+ video: this.Video?.toFormattedJSON(),
+ videoChannel: this.VideoChannel?.toFormattedJSON(),
+
+ createdAt: this.createdAt
+ }
+ }
+}
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/change-ownership-list-query-builder.ts
similarity index 83%
rename from server/core/models/video/sql/change-ownership/video-change-ownership-list-query-builder.ts
rename to server/core/models/video/sql/change-ownership/change-ownership-list-query-builder.ts
index ecd0f6b9bc..fda2352ac7 100644
--- a/server/core/models/video/sql/change-ownership/video-change-ownership-list-query-builder.ts
+++ b/server/core/models/video/sql/change-ownership/change-ownership-list-query-builder.ts
@@ -1,20 +1,22 @@
-import { VideoChangeOwnershipStatusType, VideoChannelCollaboratorState } from '@peertube/peertube-models'
+import { ChangeOwnershipStateType, 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'
+import { VideoChangeOwnershipTableAttributes } from './change-ownership-table-attributes.js'
+
+export interface ListChangeOwnershipOptions extends AbstractListQueryOptions {
+ type?: 'video' | 'video-channel'
-export interface ListVideoChangeOwnershipOptions extends AbstractListQueryOptions {
id?: number
accountId?: number
- state?: VideoChangeOwnershipStatusType
+ state?: ChangeOwnershipStateType
videoId?: number
}
-export class VideoChangeOwnershipListQueryBuilder extends AbstractListQuery {
+export class ChangeOwnershipListQueryBuilder extends AbstractListQuery {
private readonly tableAttributes = new VideoChangeOwnershipTableAttributes()
private builtInitiatorJoin = false
@@ -29,9 +31,9 @@ export class VideoChangeOwnershipListQueryBuilder extends AbstractListQuery {
constructor (
protected readonly sequelize: Sequelize,
- protected readonly options: ListVideoChangeOwnershipOptions
+ protected readonly options: ListChangeOwnershipOptions
) {
- super(sequelize, { modelName: 'VideoChangeOwnershipModel', tableName: 'videoChangeOwnership' }, options)
+ super(sequelize, { modelName: 'ChangeOwnershipModel', tableName: 'changeOwnership' }, options)
}
// ---------------------------------------------------------------------------
@@ -39,11 +41,17 @@ export class VideoChangeOwnershipListQueryBuilder extends AbstractListQuery {
protected buildSubQueryWhere () {
const where: string[] = []
+ if (this.options.type === 'video-channel') {
+ where.push(`"ChangeOwnershipModel"."videoChannelId" IS NOT NULL`)
+ } else if (this.options.type === 'video') {
+ where.push(`"ChangeOwnershipModel"."videoId" IS NOT NULL`)
+ }
+
if (this.options.accountId) {
this.buildChannelCollaboratorsJoin()
where.push(
- `"VideoChangeOwnershipModel"."nextOwnerAccountId" = :nextOwnerAccountId ` +
+ `"ChangeOwnershipModel"."nextOwnerAccountId" = :nextOwnerAccountId ` +
`OR (` +
`"Video->VideoChannel->VideoChannelCollaborators"."accountId" = :collaborationAccountId OR ` +
`"Video->VideoChannel->Account"."id" = :videoAccountId` +
@@ -56,17 +64,17 @@ export class VideoChangeOwnershipListQueryBuilder extends AbstractListQuery {
}
if (this.options.state) {
- where.push(`"VideoChangeOwnershipModel"."status" = :status`)
- this.replacements.status = this.options.state
+ where.push(`"ChangeOwnershipModel"."state" = :state`)
+ this.replacements.state = this.options.state
}
if (this.options.videoId) {
- where.push(`"VideoChangeOwnershipModel"."videoId" = :videoId`)
+ where.push(`"ChangeOwnershipModel"."videoId" = :videoId`)
this.replacements.videoId = this.options.videoId
}
if (this.options.id) {
- where.push(`"VideoChangeOwnershipModel"."id" = :id`)
+ where.push(`"ChangeOwnershipModel"."id" = :id`)
this.replacements.id = this.options.id
}
@@ -80,7 +88,7 @@ export class VideoChangeOwnershipListQueryBuilder extends AbstractListQuery {
private buildInitiatorJoin () {
if (this.builtInitiatorJoin) return
- this.subQueryJoin += ' INNER JOIN "account" "Initiator" ON "Initiator"."id" = "VideoChangeOwnershipModel"."initiatorAccountId" ' +
+ this.subQueryJoin += ' INNER JOIN "account" "Initiator" ON "Initiator"."id" = "ChangeOwnershipModel"."initiatorAccountId" ' +
getActorJoin({ base: 'Initiator->', on: '"Initiator"."id"', type: 'account', required: true })
this.builtInitiatorJoin = true
@@ -89,7 +97,7 @@ export class VideoChangeOwnershipListQueryBuilder extends AbstractListQuery {
private buildNextOwnerJoin () {
if (this.builtNextOwnerJoin) return
- this.subQueryJoin += ' INNER JOIN "account" "NextOwner" ON "NextOwner"."id" = "VideoChangeOwnershipModel"."nextOwnerAccountId" ' +
+ this.subQueryJoin += ' INNER JOIN "account" "NextOwner" ON "NextOwner"."id" = "ChangeOwnershipModel"."nextOwnerAccountId" ' +
getActorJoin({ base: 'NextOwner->', on: '"NextOwner"."id"', type: 'account', required: true })
this.builtNextOwnerJoin = true
@@ -98,7 +106,7 @@ export class VideoChangeOwnershipListQueryBuilder extends AbstractListQuery {
private buildVideoJoin () {
if (this.builtVideoJoin) return
- this.subQueryJoin += ' INNER JOIN "video" "Video" ON "Video"."id" = "VideoChangeOwnershipModel"."videoId" ' +
+ this.subQueryJoin += ' INNER JOIN "video" "Video" ON "Video"."id" = "ChangeOwnershipModel"."videoId" ' +
getChannelJoin({
base: 'Video->',
on: '"Video"."channelId"',
diff --git a/server/core/models/video/sql/change-ownership/video-change-ownership-table-attributes.ts b/server/core/models/video/sql/change-ownership/change-ownership-table-attributes.ts
similarity index 95%
rename from server/core/models/video/sql/change-ownership/video-change-ownership-table-attributes.ts
rename to server/core/models/video/sql/change-ownership/change-ownership-table-attributes.ts
index 2278c25449..26c1677369 100644
--- a/server/core/models/video/sql/change-ownership/video-change-ownership-table-attributes.ts
+++ b/server/core/models/video/sql/change-ownership/change-ownership-table-attributes.ts
@@ -5,13 +5,13 @@ 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 { ChangeOwnershipModel } from '../../change-ownership.js'
import { VideoModel } from '../../video.js'
export class VideoChangeOwnershipTableAttributes {
@Memoize()
getChangeOwnershipAttributes () {
- return VideoChangeOwnershipModel.getSQLAttributes('VideoChangeOwnershipModel').join(', ')
+ return ChangeOwnershipModel.getSQLAttributes('ChangeOwnershipModel').join(', ')
}
// ---------------------------------------------------------------------------
diff --git a/server/core/models/video/video-change-ownership.ts b/server/core/models/video/video-change-ownership.ts
deleted file mode 100644
index 6b8c1fc7c3..0000000000
--- a/server/core/models/video/video-change-ownership.ts
+++ /dev/null
@@ -1,115 +0,0 @@
-import { VideoChangeOwnership, VideoChangeOwnershipStatus, type VideoChangeOwnershipStatusType } from '@peertube/peertube-models'
-import { MVideoChangeOwnership, MVideoChangeOwnershipFull } from '@server/types/models/video/video-change-ownership.js'
-import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Table, UpdatedAt } from 'sequelize-typescript'
-import { AccountModel } from '../account/account.js'
-import { SequelizeModel, buildSQLAttributes } from '../shared/index.js'
-import {
- ListVideoChangeOwnershipOptions,
- VideoChangeOwnershipListQueryBuilder
-} from './sql/change-ownership/video-change-ownership-list-query-builder.js'
-import { VideoModel } from './video.js'
-
-@Table({
- tableName: 'videoChangeOwnership',
- indexes: [
- {
- fields: [ 'videoId' ]
- },
- {
- fields: [ 'initiatorAccountId' ]
- },
- {
- fields: [ 'nextOwnerAccountId' ]
- }
- ]
-})
-export class VideoChangeOwnershipModel extends SequelizeModel<VideoChangeOwnershipModel> {
- @CreatedAt
- declare createdAt: Date
-
- @UpdatedAt
- declare updatedAt: Date
-
- @AllowNull(false)
- @Column
- declare status: VideoChangeOwnershipStatusType
-
- @ForeignKey(() => AccountModel)
- @Column
- declare initiatorAccountId: number
-
- @BelongsTo(() => AccountModel, {
- foreignKey: {
- name: 'initiatorAccountId',
- allowNull: false
- },
- onDelete: 'cascade'
- })
- declare Initiator: Awaited<AccountModel>
-
- @ForeignKey(() => AccountModel)
- @Column
- declare nextOwnerAccountId: number
-
- @BelongsTo(() => AccountModel, {
- foreignKey: {
- name: 'nextOwnerAccountId',
- allowNull: false
- },
- onDelete: 'cascade'
- })
- declare NextOwner: Awaited<AccountModel>
-
- @ForeignKey(() => VideoModel)
- @Column
- declare videoId: number
-
- @BelongsTo(() => VideoModel, {
- foreignKey: {
- allowNull: false
- },
- onDelete: 'cascade'
- })
- declare Video: Awaited<VideoModel>
-
- static getSQLAttributes (tableName: string, aliasPrefix = '') {
- return buildSQLAttributes({
- model: this,
- tableName,
- aliasPrefix
- })
- }
-
- // ---------------------------------------------------------------------------
-
- static listForApi (options: ListVideoChangeOwnershipOptions) {
- return Promise.all([
- 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> {
- return new VideoChangeOwnershipListQueryBuilder(VideoChangeOwnershipModel.sequelize, { id }).get<MVideoChangeOwnershipFull>()
- }
-
- static loadPendingByVideo (videoId: number): Promise<MVideoChangeOwnership> {
- return new VideoChangeOwnershipListQueryBuilder(VideoChangeOwnershipModel.sequelize, {
- videoId,
- state: VideoChangeOwnershipStatus.WAITING
- }).get<MVideoChangeOwnershipFull>()
- }
-
- // ---------------------------------------------------------------------------
-
- toFormattedJSON (this: MVideoChangeOwnershipFull): VideoChangeOwnership {
- return {
- id: this.id,
- status: this.status,
- initiatorAccount: this.Initiator.toFormattedJSON(),
- nextOwnerAccount: this.NextOwner.toFormattedJSON(),
- video: this.Video.toFormattedJSON(),
- createdAt: this.createdAt
- }
- }
-}
diff --git a/server/core/models/video/video-channel-activity.ts b/server/core/models/video/video-channel-activity.ts
index 67a3b70165..214b8c481b 100644
--- a/server/core/models/video/video-channel-activity.ts
+++ b/server/core/models/video/video-channel-activity.ts
@@ -305,7 +305,7 @@ export class VideoChannelActivityModel extends SequelizeModel<VideoChannelActivi
}, { transaction })
}
- static async addVideoOwnershipChangeActivity (options: {
+ static async addOwnershipChangeActivity (options: {
action: VideoChannelActivityActionType
user: MUserAccountId
channel: MChannelId
diff --git a/server/core/types/express.d.ts b/server/core/types/express.d.ts
index 4b340c431b..5c1d13c67a 100644
--- a/server/core/types/express.d.ts
+++ b/server/core/types/express.d.ts
@@ -21,7 +21,7 @@ import {
MStreamingPlaylist,
MUserAccountUrl,
MUserExport,
- MVideoChangeOwnershipFull,
+ MChangeOwnershipFull,
MVideoEmbedDomain,
MVideoFile,
MVideoFormattableDetails,
@@ -207,8 +207,8 @@ declare module 'express' {
follow?: MActorFollowActorsDefault
subscription?: MActorFollowActorsDefaultSubscription
- videoChangeOwnership?: MVideoChangeOwnershipFull
- videoChangeOwnershipNextOwner?: MAccountDefault
+ changeOwnership?: MChangeOwnershipFull
+ changeOwnershipNextOwner?: MAccountDefault
videoEmbedDomain?: MVideoEmbedDomain
diff --git a/server/core/types/models/user/user-notification.ts b/server/core/types/models/user/user-notification.ts
index d7848345a9..a201d27b66 100644
--- a/server/core/types/models/user/user-notification.ts
+++ b/server/core/types/models/user/user-notification.ts
@@ -7,9 +7,9 @@ import { ApplicationModel } from '@server/models/application/application.js'
import { PluginModel } from '@server/models/server/plugin.js'
import { UserNotificationModel } from '@server/models/user/user-notification.js'
import { UserRegistrationModel } from '@server/models/user/user-registration.js'
+import { ChangeOwnershipModel } from '@server/models/video/change-ownership.js'
import { VideoCaptionModel } from '@server/models/video/video-caption.js'
import { VideoChannelCollaboratorModel } from '@server/models/video/video-channel-collaborator.js'
-import { VideoChangeOwnershipModel } from '@server/models/video/video-change-ownership.js'
import { AbuseModel } from '../../../models/abuse/abuse.js'
import { AccountModel } from '../../../models/account/account.js'
import { ActorFollowModel } from '../../../models/actor/actor-follow.js'
@@ -120,11 +120,12 @@ export namespace UserNotificationIncludes {
& PickWith<VideoChannelCollaboratorModel, 'Account', AccountIncludeActor>
& PickWith<VideoChannelCollaboratorModel, 'Channel', VideoChannelIncludeActorOwnerActor>
- export type VideoOwnershipInclude =
- & Pick<VideoChangeOwnershipModel, 'id'>
- & PickWith<VideoChangeOwnershipModel, 'Initiator', AccountIncludeActor>
- & PickWith<VideoChangeOwnershipModel, 'NextOwner', AccountIncludeActor>
- & PickWith<VideoChangeOwnershipModel, 'Video', VideoInclude>
+ export type ChangeOwnershipInclude =
+ & Pick<ChangeOwnershipModel, 'id'>
+ & PickWith<ChangeOwnershipModel, 'Initiator', AccountIncludeActor>
+ & PickWith<ChangeOwnershipModel, 'NextOwner', AccountIncludeActor>
+ & PickWith<ChangeOwnershipModel, 'Video', VideoInclude>
+ & PickWith<ChangeOwnershipModel, 'VideoChannel', VideoChannelIncludeActor>
}
// ############################################################################
@@ -144,7 +145,7 @@ export type MUserNotification = Omit<
| 'UserRegistration'
| 'VideoCaption'
| 'VideoChannelCollaborator'
- | 'VideoOwnership'
+ | 'ChangeOwnership'
>
// ############################################################################
@@ -163,4 +164,4 @@ export type UserNotificationModelForApi =
& Use<'UserRegistration', UserNotificationIncludes.UserRegistrationInclude>
& Use<'VideoCaption', UserNotificationIncludes.VideoCaptionInclude>
& Use<'VideoChannelCollaborator', UserNotificationIncludes.VideoChannelCollaboratorInclude>
- & Use<'VideoOwnership', UserNotificationIncludes.VideoOwnershipInclude>
+ & Use<'ChangeOwnership', UserNotificationIncludes.ChangeOwnershipInclude>
diff --git a/server/core/types/models/video/change-ownership.ts b/server/core/types/models/video/change-ownership.ts
new file mode 100644
index 0000000000..1bd49714ba
--- /dev/null
+++ b/server/core/types/models/video/change-ownership.ts
@@ -0,0 +1,18 @@
+import { PickWith } from '@peertube/peertube-typescript-utils'
+import { ChangeOwnershipModel } from '@server/models/video/change-ownership.js'
+import { MAccountFormattable } from '../account/account.js'
+import { MChannelFormattable } from './video-channel.js'
+import { MVideoFormattable } from './video.js'
+
+type Use<K extends keyof ChangeOwnershipModel, M> = PickWith<ChangeOwnershipModel, K, M>
+
+// ############################################################################
+
+export type MChangeOwnership = Omit<ChangeOwnershipModel, 'Initiator' | 'NextOwner' | 'Video' | 'VideoChannel'>
+
+export type MChangeOwnershipFull =
+ & MChangeOwnership
+ & Use<'Initiator', MAccountFormattable>
+ & Use<'NextOwner', MAccountFormattable>
+ & Use<'Video', MVideoFormattable>
+ & Use<'VideoChannel', MChannelFormattable>
diff --git a/server/core/types/models/video/index.ts b/server/core/types/models/video/index.ts
index 53fc3199a3..ee830dbfab 100644
--- a/server/core/types/models/video/index.ts
+++ b/server/core/types/models/video/index.ts
@@ -7,7 +7,7 @@ export * from './thumbnail.js'
export * from './video.js'
export * from './video-blacklist.js'
export * from './video-caption.js'
-export * from './video-change-ownership.js'
+export * from './change-ownership.js'
export * from './video-channel-sync.js'
export * from './video-channel.js'
export * from './video-channel-collaborator.js'
diff --git a/server/core/types/models/video/video-change-ownership.ts b/server/core/types/models/video/video-change-ownership.ts
deleted file mode 100644
index 75e0911fc1..0000000000
--- a/server/core/types/models/video/video-change-ownership.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import { PickWith } from '@peertube/peertube-typescript-utils'
-import { VideoChangeOwnershipModel } from '@server/models/video/video-change-ownership.js'
-import { MAccountFormattable } from '../account/account.js'
-import { MVideoFormattable } from './video.js'
-
-type Use<K extends keyof VideoChangeOwnershipModel, M> = PickWith<VideoChangeOwnershipModel, K, M>
-
-// ############################################################################
-
-export type MVideoChangeOwnership = Omit<VideoChangeOwnershipModel, 'Initiator' | 'NextOwner' | 'Video'>
-
-export type MVideoChangeOwnershipFull =
- & MVideoChangeOwnership
- & Use<'Initiator', MAccountFormattable>
- & Use<'NextOwner', MAccountFormattable>
- & Use<'Video', MVideoFormattable>
diff --git a/support/doc/api/openapi.yaml b/support/doc/api/openapi.yaml
index c26a3e1069..8308a8909e 100644
--- a/support/doc/api/openapi.yaml
+++ b/support/doc/api/openapi.yaml
@@ -2986,7 +2986,7 @@ paths:
data:
type: array
items:
- $ref: '#/components/schemas/VideoChangeOwnership'
+ $ref: '#/components/schemas/ChangeOwnership'
'/api/v1/videos/ownership/{id}/accept':
post:
@@ -3053,13 +3053,9 @@ paths:
- name: state
in: query
required: false
- description: Filter by ownership change state (WAITING, ACCEPTED, REFUSED)
+ description: Filter by ownership change state
schema:
- type: string
- enum:
- - WAITING
- - ACCEPTED
- - REFUSED
+ $ref: '#/components/schemas/ChangeOwnershipState'
- $ref: '#/components/parameters/start'
- $ref: '#/components/parameters/count'
- $ref: '#/components/parameters/sort'
@@ -3077,7 +3073,7 @@ paths:
data:
type: array
items:
- $ref: '#/components/schemas/VideoChangeOwnership'
+ $ref: '#/components/schemas/ChangeOwnership'
'403':
description: cannot manage the video
'404':
@@ -10051,19 +10047,18 @@ components:
type: integer
nsfw:
type: boolean
- VideoChangeOwnership:
+ ChangeOwnership:
type: object
- description: Representation of a video ownership change
+ description: Representation of a ownership change
properties:
id:
$ref: '#/components/schemas/id'
- status:
- type: string
- description: Status of the ownership change request
- enum:
- - WAITING
- - ACCEPTED
- - REFUSED
+ state:
+ properties:
+ id:
+ $ref: '#/components/schemas/ChangeOwnershipState'
+ label:
+ type: string
initiatorAccount:
$ref: '#/components/schemas/Account'
nextOwnerAccount:
@@ -12003,6 +11998,14 @@ components:
- 3
description: 'The registration state (Pending = `1`, Rejected = `2`, Accepted = `3`)'
+ ChangeOwnershipState:
+ type: integer
+ enum:
+ - 1
+ - 2
+ - 3
+ description: 'The ownership change state (Pending = `1`, Rejected = `2`, Accepted = `3`)'
+
UserRegistration:
properties:
id: