Skip to content

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

Fix non owned video manage page

Chocobozzz87f44f996be3
diff --git a/client/src/app/+my-library/my-ownership-changes/my-video-ownership-changes/accept-change-video-ownership.component.ts b/client/src/app/+my-library/my-ownership-changes/my-video-ownership-changes/accept-change-video-ownership.component.ts
index 0dbbe26db0..a07d756482 100644
--- a/client/src/app/+my-library/my-ownership-changes/my-video-ownership-changes/accept-change-video-ownership.component.ts
+++ b/client/src/app/+my-library/my-ownership-changes/my-video-ownership-changes/accept-change-video-ownership.component.ts
@@ -1,15 +1,16 @@
import { ChangeDetectionStrategy, Component, ElementRef, OnInit, inject, output, viewChild } from '@angular/core'
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
import { AuthService, Notifier } from '@app/core'
-import { formatICU, listChannelsForSelect } from '@app/helpers'
+import { formatICU } from '@app/helpers'
import { OWNERSHIP_CHANGE_CHANNEL_VALIDATOR } from '@app/shared/form-validators/video-ownership-change-validators'
import { ChangeOwnershipService } from '@app/shared/shared-change-ownership/change-ownership.service'
import { FormReactive } from '@app/shared/shared-forms/form-reactive'
import { FormReactiveService } from '@app/shared/shared-forms/form-reactive.service'
+import { listChannelsForSelect } from '@app/shared/shared-forms/select/channel/select-channel-helpers'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { ChangeOwnership } from '@peertube/peertube-models'
import { SelectChannelItem } from '@pt-types'
-import { SelectChannelUserComponent } from '../../../shared/shared-forms/select/select-channel-user.component'
+import { SelectChannelUserComponent } from '../../../shared/shared-forms/select/channel/select-channel-user.component'
import { GlobalIconComponent } from '../../../shared/shared-icons/global-icon.component'
@Component({
diff --git a/client/src/app/+my-library/my-video-channel-syncs/video-channel-sync-edit/video-channel-sync-edit.component.ts b/client/src/app/+my-library/my-video-channel-syncs/video-channel-sync-edit/video-channel-sync-edit.component.ts
index 3c42ff0049..b0da36914d 100644
--- a/client/src/app/+my-library/my-video-channel-syncs/video-channel-sync-edit/video-channel-sync-edit.component.ts
+++ b/client/src/app/+my-library/my-video-channel-syncs/video-channel-sync-edit/video-channel-sync-edit.component.ts
@@ -3,18 +3,18 @@ import { ChangeDetectionStrategy, Component, OnInit, inject } from '@angular/cor
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
import { Router } from '@angular/router'
import { AuthService, Notifier } from '@app/core'
-import { listChannelsForSelect } from '@app/helpers'
import { REQUIRED_VALIDATOR } from '@app/shared/form-validators/common-validators'
import { VIDEO_CHANNEL_EXTERNAL_URL_VALIDATOR } from '@app/shared/form-validators/video-channel-validators'
import { FormReactive } from '@app/shared/shared-forms/form-reactive'
import { FormReactiveService } from '@app/shared/shared-forms/form-reactive.service'
+import { listChannelsForSelect } from '@app/shared/shared-forms/select/channel/select-channel-helpers'
import { VideoChannelSyncService } from '@app/shared/shared-main/channel/video-channel-sync.service'
import { VideoChannelService } from '@app/shared/shared-main/channel/video-channel.service'
import { AlertComponent } from '@app/shared/shared-main/common/alert.component'
import { VideoChannelSyncCreate } from '@peertube/peertube-models'
import { SelectChannelItem } from '@pt-types'
import { mergeMap } from 'rxjs'
-import { SelectChannelUserComponent } from '../../../shared/shared-forms/select/select-channel-user.component'
+import { SelectChannelUserComponent } from '../../../shared/shared-forms/select/channel/select-channel-user.component'
@Component({
selector: 'my-video-channel-sync-edit',
diff --git a/client/src/app/+my-library/my-video-playlists/my-video-playlist-create.component.ts b/client/src/app/+my-library/my-video-playlists/my-video-playlist-create.component.ts
index 873ed3acd4..45c18ea973 100644
--- a/client/src/app/+my-library/my-video-playlists/my-video-playlist-create.component.ts
+++ b/client/src/app/+my-library/my-video-playlists/my-video-playlist-create.component.ts
@@ -3,7 +3,6 @@ import { ChangeDetectionStrategy, Component, inject, OnInit } from '@angular/cor
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
import { Router, RouterLink } from '@angular/router'
import { AuthService, Notifier, ServerService } from '@app/core'
-import { listChannelsForSelect } from '@app/helpers'
import {
setPlaylistChannelValidator,
VIDEO_PLAYLIST_CHANNEL_ID_VALIDATOR,
@@ -13,13 +12,14 @@ import {
} from '@app/shared/form-validators/video-playlist-validators'
import { FormReactiveService } from '@app/shared/shared-forms/form-reactive.service'
import { PeertubeCheckboxComponent } from '@app/shared/shared-forms/peertube-checkbox.component'
+import { listChannelsForSelect } from '@app/shared/shared-forms/select/channel/select-channel-helpers'
import { AlertComponent } from '@app/shared/shared-main/common/alert.component'
import { VideoPlaylistService } from '@app/shared/shared-video-playlist/video-playlist.service'
import { VideoPlaylistCreate, VideoPlaylistPrivacy } from '@peertube/peertube-models'
import { of, switchMap } from 'rxjs'
import { ImageInputComponent } from '../../shared/shared-forms/image-input.component'
import { MarkdownTextareaComponent } from '../../shared/shared-forms/markdown-textarea.component'
-import { SelectChannelUserComponent } from '../../shared/shared-forms/select/select-channel-user.component'
+import { SelectChannelUserComponent } from '../../shared/shared-forms/select/channel/select-channel-user.component'
import { SelectOptionsComponent } from '../../shared/shared-forms/select/select-options.component'
import { HelpComponent } from '../../shared/shared-main/buttons/help.component'
import { MyVideoPlaylistEdit } from './my-video-playlist-edit'
diff --git a/client/src/app/+my-library/my-video-playlists/my-video-playlist-update.component.ts b/client/src/app/+my-library/my-video-playlists/my-video-playlist-update.component.ts
index 8dc7de2042..97701f2f7a 100644
--- a/client/src/app/+my-library/my-video-playlists/my-video-playlist-update.component.ts
+++ b/client/src/app/+my-library/my-video-playlists/my-video-playlist-update.component.ts
@@ -3,7 +3,6 @@ import { ChangeDetectionStrategy, Component, inject, OnDestroy, OnInit } from '@
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
import { ActivatedRoute, Router, RouterLink } from '@angular/router'
import { AuthService, Notifier, ServerService } from '@app/core'
-import { listChannelsForSelect } from '@app/helpers'
import {
setPlaylistChannelValidator,
VIDEO_PLAYLIST_CHANNEL_ID_VALIDATOR,
@@ -13,7 +12,8 @@ import {
} from '@app/shared/form-validators/video-playlist-validators'
import { FormReactiveService } from '@app/shared/shared-forms/form-reactive.service'
import { PeertubeCheckboxComponent } from '@app/shared/shared-forms/peertube-checkbox.component'
-import { SelectChannelUserComponent } from '@app/shared/shared-forms/select/select-channel-user.component'
+import { listChannelsForSelect } from '@app/shared/shared-forms/select/channel/select-channel-helpers'
+import { SelectChannelUserComponent } from '@app/shared/shared-forms/select/channel/select-channel-user.component'
import { AlertComponent } from '@app/shared/shared-main/common/alert.component'
import { VideoPlaylistService } from '@app/shared/shared-video-playlist/video-playlist.service'
import { VideoPlaylistUpdate } from '@peertube/peertube-models'
diff --git a/client/src/app/+videos-publish-manage/+video-manage/video-manage.resolver.ts b/client/src/app/+videos-publish-manage/+video-manage/video-manage.resolver.ts
index 38d6492b8e..c024c4686d 100644
--- a/client/src/app/+videos-publish-manage/+video-manage/video-manage.resolver.ts
+++ b/client/src/app/+videos-publish-manage/+video-manage/video-manage.resolver.ts
@@ -1,7 +1,7 @@
import { Injectable, inject } from '@angular/core'
import { ActivatedRouteSnapshot, Router } from '@angular/router'
import { AuthService, ServerService, UserService } from '@app/core'
-import { listChannelsForSelect } from '@app/helpers'
+import { listChannelsForSelect } from '@app/shared/shared-forms/select/channel/select-channel-helpers'
import { VideoCaptionService } from '@app/shared/shared-main/video-caption/video-caption.service'
import { VideoChapterService } from '@app/shared/shared-main/video/video-chapter.service'
import { VideoDetails } from '@app/shared/shared-main/video/video-details.model'
diff --git a/client/src/app/+videos-publish-manage/+video-publish/import/video-import-torrent.component.ts b/client/src/app/+videos-publish-manage/+video-publish/import/video-import-torrent.component.ts
index c73cfc7fa6..5029c469cd 100644
--- a/client/src/app/+videos-publish-manage/+video-publish/import/video-import-torrent.component.ts
+++ b/client/src/app/+videos-publish-manage/+video-publish/import/video-import-torrent.component.ts
@@ -15,7 +15,7 @@ import { PeerTubeProblemDocument, ServerErrorCode, UserVideoQuota, VideoPrivacyT
import { SelectChannelItem } from '@pt-types'
import debug from 'debug'
import { forkJoin, switchMap } from 'rxjs'
-import { SelectChannelUserComponent } from '../../../shared/shared-forms/select/select-channel-user.component'
+import { SelectChannelUserComponent } from '../../../shared/shared-forms/select/channel/select-channel-user.component'
import { GlobalIconComponent } from '../../../shared/shared-icons/global-icon.component'
import { HelpComponent } from '../../../shared/shared-main/buttons/help.component'
import { VideoManageContainerComponent } from '../../shared-manage/video-manage-container.component'
@@ -123,11 +123,14 @@ export class VideoImportTorrentComponent implements OnInit, AfterViewInit, CanCo
const serverConfig = this.serverService.getHTMLConfig()
+ const channel = this.userChannels().find(c => c.id === this.firstStepChannelId)
const videoEdit = VideoEdit.createFromImport(serverConfig, {
torrentfile,
magnetUri: this.firstStepMagnetUri,
channelId: this.firstStepChannelId,
- support: this.userChannels().find(c => c.id === this.firstStepChannelId).support ?? '',
+ channelName: channel.name,
+ channelDisplayName: channel.displayName,
+ support: channel.support ?? '',
user: this.authService.getUser()
})
this.manageController.setConfig({ manageType: 'import-torrent', serverConfig: this.serverService.getHTMLConfig() })
diff --git a/client/src/app/+videos-publish-manage/+video-publish/import/video-import-url.component.ts b/client/src/app/+videos-publish-manage/+video-publish/import/video-import-url.component.ts
index 6e6d3c429d..f6d49fe52b 100644
--- a/client/src/app/+videos-publish-manage/+video-publish/import/video-import-url.component.ts
+++ b/client/src/app/+videos-publish-manage/+video-publish/import/video-import-url.component.ts
@@ -17,7 +17,7 @@ import { SelectChannelItem } from '@pt-types'
import debug from 'debug'
import { forkJoin } from 'rxjs'
import { map, switchMap } from 'rxjs/operators'
-import { SelectChannelUserComponent } from '../../../shared/shared-forms/select/select-channel-user.component'
+import { SelectChannelUserComponent } from '../../../shared/shared-forms/select/channel/select-channel-user.component'
import { GlobalIconComponent } from '../../../shared/shared-icons/global-icon.component'
import { HelpComponent } from '../../../shared/shared-main/buttons/help.component'
import { VideoManageContainerComponent } from '../../shared-manage/video-manage-container.component'
@@ -112,10 +112,13 @@ export class VideoImportUrlComponent implements OnInit, AfterViewInit, CanCompon
const serverConfig = this.serverService.getHTMLConfig()
+ const channel = this.userChannels().find(c => c.id === this.firstStepChannelId)
const videoEdit = VideoEdit.createFromImport(serverConfig, {
targetUrl: this.targetUrl,
channelId: this.firstStepChannelId,
- support: this.userChannels().find(c => c.id === this.firstStepChannelId).support ?? '',
+ channelName: channel.name,
+ channelDisplayName: channel.displayName,
+ support: channel.support ?? '',
user: this.authService.getUser()
})
this.manageController.setConfig({ manageType: 'import-url', serverConfig: this.serverService.getHTMLConfig() })
diff --git a/client/src/app/+videos-publish-manage/+video-publish/live/video-go-live.component.ts b/client/src/app/+videos-publish-manage/+video-publish/live/video-go-live.component.ts
index 1fd3e08c16..5dce23f8ec 100644
--- a/client/src/app/+videos-publish-manage/+video-publish/live/video-go-live.component.ts
+++ b/client/src/app/+videos-publish-manage/+video-publish/live/video-go-live.component.ts
@@ -11,7 +11,7 @@ import { LiveVideoLatencyMode, PeerTubeProblemDocument, ServerErrorCode, UserVid
import { SelectChannelItem } from '@pt-types'
import debug from 'debug'
import { forkJoin, map, switchMap } from 'rxjs'
-import { SelectChannelUserComponent } from '../../../shared/shared-forms/select/select-channel-user.component'
+import { SelectChannelUserComponent } from '../../../shared/shared-forms/select/channel/select-channel-user.component'
import { GlobalIconComponent } from '../../../shared/shared-icons/global-icon.component'
import { VideoManageContainerComponent } from '../../shared-manage/video-manage-container.component'
@@ -88,10 +88,14 @@ export class VideoGoLiveComponent implements OnInit, AfterViewInit, CanComponent
const serverConfig = this.serverService.getHTMLConfig()
+ const channel = this.userChannels().find(c => c.id === this.firstStepChannelId)
+
const videoEdit = VideoEdit.createFromLive(serverConfig, {
name: $localize`:The translation must be at least 3 characters long:Live`,
channelId: this.firstStepChannelId,
- support: this.userChannels().find(c => c.id === this.firstStepChannelId).support ?? '',
+ support: channel.support ?? '',
+ channelName: channel.name,
+ channelDisplayName: channel.displayName,
permanentLive: this.firstStepPermanentLive,
latencyMode: LiveVideoLatencyMode.DEFAULT,
dvrWindow: serverConfig.live.dvr.maxWindow,
diff --git a/client/src/app/+videos-publish-manage/+video-publish/upload/video-upload.component.ts b/client/src/app/+videos-publish-manage/+video-publish/upload/video-upload.component.ts
index ae17048877..f9e35796df 100644
--- a/client/src/app/+videos-publish-manage/+video-publish/upload/video-upload.component.ts
+++ b/client/src/app/+videos-publish-manage/+video-publish/upload/video-upload.component.ts
@@ -23,7 +23,7 @@ import debug from 'debug'
import { truncate } from 'lodash-es'
import { Subscription } from 'rxjs'
import { ImageInputComponent } from '../../../shared/shared-forms/image-input.component'
-import { SelectChannelUserComponent } from '../../../shared/shared-forms/select/select-channel-user.component'
+import { SelectChannelUserComponent } from '../../../shared/shared-forms/select/channel/select-channel-user.component'
import { GlobalIconComponent } from '../../../shared/shared-icons/global-icon.component'
import { ButtonComponent } from '../../../shared/shared-main/buttons/button.component'
import { VideoManageContainerComponent } from '../../shared-manage/video-manage-container.component'
@@ -221,10 +221,13 @@ export class VideoUploadComponent implements OnInit, OnDestroy, AfterViewInit, C
private uploadFile (file: File, thumbnailfile?: File) {
const serverConfig = this.serverService.getHTMLConfig()
+ const channel = this.userChannels().find(c => c.id === this.firstStepChannelId)
this.videoEdit = VideoEdit.createFromUpload(serverConfig, {
name: this.buildVideoFilename(file.name),
channelId: this.firstStepChannelId,
- support: this.userChannels().find(c => c.id === this.firstStepChannelId).support ?? '',
+ channelName: channel.name,
+ channelDisplayName: channel.displayName,
+ support: channel.support ?? '',
user: this.authService.getUser()
})
diff --git a/client/src/app/+videos-publish-manage/+video-publish/video-publish.resolver.ts b/client/src/app/+videos-publish-manage/+video-publish/video-publish.resolver.ts
index 488be75858..1a5fd79be3 100644
--- a/client/src/app/+videos-publish-manage/+video-publish/video-publish.resolver.ts
+++ b/client/src/app/+videos-publish-manage/+video-publish/video-publish.resolver.ts
@@ -1,6 +1,6 @@
import { Injectable, inject } from '@angular/core'
import { AuthService, ServerService, UserService } from '@app/core'
-import { listChannelsForSelect } from '@app/helpers'
+import { listChannelsForSelect } from '@app/shared/shared-forms/select/channel/select-channel-helpers'
import { ConstantLabel, UserVideoQuota, VideoPrivacyType } from '@peertube/peertube-models'
import { forkJoin } from 'rxjs'
import { map } from 'rxjs/operators'
diff --git a/client/src/app/+videos-publish-manage/shared-manage/common/video-edit.model.ts b/client/src/app/+videos-publish-manage/shared-manage/common/video-edit.model.ts
index c695f8e621..7329b3af9d 100644
--- a/client/src/app/+videos-publish-manage/shared-manage/common/video-edit.model.ts
+++ b/client/src/app/+videos-publish-manage/shared-manage/common/video-edit.model.ts
@@ -88,6 +88,7 @@ type EmbedPrivacyForm = {
// ---------------------------------------------------------------------------
type LoadFromPublishOptions = Required<Pick<VideoCreate, 'channelId' | 'support'>> & Partial<Pick<VideoCreate, 'name'>> & {
+ channelName: string
channelDisplayName: string
user: AuthUser
}
@@ -479,8 +480,10 @@ export class VideoEdit {
this.metadata.channelName = video.channel.name
this.metadata.channelDisplayName = video.channel.displayName
- this.initialMetadata.accountName = this.metadata.accountName
- this.initialMetadata.channelId = this.common.channelId
+ this.initialMetadata = {
+ accountName: this.metadata.accountName,
+ channelId: this.common.channelId
+ }
}
loadPluginDataDefaults (pluginDefaults: Record<string, string | boolean>) {
diff --git a/client/src/app/+videos-publish-manage/shared-manage/main-info/video-main-info.component.html b/client/src/app/+videos-publish-manage/shared-manage/main-info/video-main-info.component.html
index 09b7784437..865222c86d 100644
--- a/client/src/app/+videos-publish-manage/shared-manage/main-info/video-main-info.component.html
+++ b/client/src/app/+videos-publish-manage/shared-manage/main-info/video-main-info.component.html
@@ -98,7 +98,7 @@
<my-select-channel-auto
class="d-block" inputId="adminChannel" formControlName="channelId"
[ownerAccount]="{ name: initialOwner.accountName }" [ownerChannel]="{ id: initialOwner.channelId }"
- (onChannelChanged)="onAdminChannelChanged($event)"
+ (onChannelChanged)="onChannelChanged($event)"
></my-select-channel-auto>
</div>
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 f6e39a6bd0..720ecc2a9e 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
@@ -25,7 +25,7 @@ import { FormValidatorService } from '@app/shared/shared-forms/form-validator.se
import { InputTextComponent } from '@app/shared/shared-forms/input-text.component'
import { MarkdownTextareaComponent } from '@app/shared/shared-forms/markdown-textarea.component'
import { PeertubeCheckboxComponent } from '@app/shared/shared-forms/peertube-checkbox.component'
-import { SelectChannelAutoComponent } from '@app/shared/shared-forms/select/select-channel-auto.component'
+import { SelectChannelAutoComponent } from '@app/shared/shared-forms/select/channel/select-channel-auto.component'
import { SelectOptionsComponent } from '@app/shared/shared-forms/select/select-options.component'
import { SelectTagsComponent } from '@app/shared/shared-forms/select/select-tags.component'
import { ButtonComponent } from '@app/shared/shared-main/buttons/button.component'
@@ -495,8 +495,8 @@ export class VideoMainInfoComponent implements OnInit, OnDestroy {
// ---------------------------------------------------------------------------
- onAdminChannelChanged ({ channelId, channelDisplayName }) {
- this.videoEdit.loadChannelChange({ channelId, channelDisplayName })
+ onChannelChanged (item: SelectChannelItem) {
+ this.videoEdit.loadChannelChange({ displayName: item.displayName, name: item.name, ownerAccountName: item.ownerAccountName })
}
canBeDeletedOrTransferred () {
diff --git a/client/src/app/helpers/utils/channel.ts b/client/src/app/helpers/utils/channel.ts
deleted file mode 100644
index 4c44af8fa4..0000000000
--- a/client/src/app/helpers/utils/channel.ts
+++ /dev/null
@@ -1,70 +0,0 @@
-import { minBy, sortBy } from '@peertube/peertube-core-utils'
-import { VideoChannel } from '@peertube/peertube-models'
-import { first, map } from 'rxjs/operators'
-import { AuthService } from '../../core/auth'
-
-// List channels of selected accountName
-// Set the currentChannelId to correctly display channel editor/owner information
-export function listChannelsForSelect (options: {
- authService: AuthService
- includeCollaborations: boolean
-}) {
- const { authService } = options
-
- return authService.userInformationLoaded
- .pipe(
- first(),
- map(() => buildUserChannelsForSelect(options))
- )
-}
-
-export function buildUserChannelsForSelect (options: {
- authService: AuthService
- includeCollaborations: boolean
-}) {
- const { authService, includeCollaborations } = options
-
- const user = authService.getUser()
- const collaborate = user.isCollaboratingToChannels()
-
- const allChannels = includeCollaborations
- ? [
- ...formatChannels(user.videoChannels, { editor: false, owner: true, collaborate }),
- ...formatChannels(user.videoChannelCollaborations, { editor: true, owner: false, collaborate })
- ]
- : formatChannels(user.videoChannels, { editor: false, owner: false, collaborate })
-
- return sortBy(allChannels, 'updatedAt').reverse()
-}
-
-// ---------------------------------------------------------------------------
-// Private
-// ---------------------------------------------------------------------------
-
-function formatChannels (channel: (VideoChannel & { ownerAccountId?: number })[], options: {
- editor: boolean
- owner: boolean
- collaborate: boolean
-}) {
- const { editor, collaborate, owner } = options
-
- return channel
- .map(c => ({
- id: c.id,
- name: c.name,
- label: c.displayName,
- support: c.support,
- editor,
- collaborate,
- owner,
- avatarFileUrl: getAvatarFileUrl(c),
- ownerAccountId: c.ownerAccountId,
- updatedAt: c.updatedAt
- }))
-}
-
-function getAvatarFileUrl (c: VideoChannel) {
- if (!c.avatars || c.avatars.length === 0) return undefined
-
- return minBy(c.avatars, 'width')?.fileUrl || c.avatars[0].fileUrl
-}
diff --git a/client/src/app/helpers/utils/index.ts b/client/src/app/helpers/utils/index.ts
index afa8f8f5c4..8fc138b5ac 100644
--- a/client/src/app/helpers/utils/index.ts
+++ b/client/src/app/helpers/utils/index.ts
@@ -1,8 +1,7 @@
-export * from './channel'
export * from './date'
+export * from './dom'
export * from './html'
export * from './object'
export * from './simple-memoize'
-export * from './dom'
export * from './upload'
export * from './url'
diff --git a/client/src/app/shared/shared-forms/select/select-channel-admin.component.ts b/client/src/app/shared/shared-forms/select/channel/select-channel-admin.component.ts
similarity index 68%
rename from client/src/app/shared/shared-forms/select/select-channel-admin.component.ts
rename to client/src/app/shared/shared-forms/select/channel/select-channel-admin.component.ts
index 7704179c47..3e0629fec7 100644
--- a/client/src/app/shared/shared-forms/select/select-channel-admin.component.ts
+++ b/client/src/app/shared/shared-forms/select/channel/select-channel-admin.component.ts
@@ -1,19 +1,12 @@
import { ChangeDetectionStrategy, Component, forwardRef, inject, input, OnChanges, OnDestroy, output } from '@angular/core'
import { ControlValueAccessor, FormsModule, NG_VALUE_ACCESSOR } from '@angular/forms'
import { AuthService, Notifier } from '@app/core'
-import { VideoChannel } from '@app/shared/shared-main/channel/video-channel.model'
import { VideoChannelService } from '@app/shared/shared-main/channel/video-channel.service'
import { SearchService } from '@app/shared/shared-search/search.service'
-import { pick } from '@peertube/peertube-core-utils'
-import { VideoChannel as VideoChannelServer } from '@peertube/peertube-models'
-import { SelectOptionsItem } from '@pt-types'
-import { findAppropriateImageFileUrl } from '@root-helpers/images'
+import { SelectChannelItem } from '@pt-types'
import { first, forkJoin, map, Subscription } from 'rxjs'
-import { ChannelMetadata } from './select-channel-metadata.model'
-import { SelectOptionsComponent } from './select-options.component'
-
-interface ChannelOption extends SelectOptionsItem, ChannelMetadata {
-}
+import { SelectOptionsComponent } from '../select-options.component'
+import { formatChannelForSelect } from './select-channel-helpers'
@Component({
selector: 'my-select-channel-admin',
@@ -36,7 +29,7 @@ interface ChannelOption extends SelectOptionsItem, ChannelMetadata {
>
</my-select-options>
`,
- styleUrls: [ 'select-options.component.scss' ],
+ styleUrls: [ '../select-options.component.scss' ],
providers: [
{
provide: NG_VALUE_ACCESSOR,
@@ -57,13 +50,13 @@ export class SelectChannelAdminComponent implements ControlValueAccessor, OnChan
readonly inputId = input.required<string>()
readonly ownerAccountName = input.required<string>()
- readonly channelChanged = output<ChannelMetadata>()
+ readonly channelChanged = output<SelectChannelItem>()
selectedId: number
- options: { label: string, value: string, items: ChannelOption[] }[] = []
+ options: { label: string, value: string, items: SelectChannelItem[] }[] = []
- baseOptions: { label: string, value: string, items: ChannelOption[] }[] = []
+ baseOptions: { label: string, value: string, items: SelectChannelItem[] }[] = []
loading = false
@@ -116,13 +109,22 @@ export class SelectChannelAdminComponent implements ControlValueAccessor, OnChan
private buildUserChannelObs () {
return this.auth.userInformationLoaded.pipe(first())
- .pipe(map(() => this.auth.getUser().videoChannels.map(c => this.formatChannel({ channel: c, displayOwner: false }))))
+ .pipe(map(() => {
+ return this.auth.getUser().videoChannels
+ .map(c => formatChannelForSelect(c, { editor: false, owner: false, collaborate: false }))
+ }))
}
private buildOwnerChannelObs () {
return this.channelService.listAccountChannels({
account: { nameWithHost: this.ownerAccountName() }
- }).pipe(map(({ data }) => data.map(c => this.formatChannel({ channel: c, displayOwner: false }))))
+ }).pipe(map(({ data }) => {
+ return data.map(c => {
+ const channel = { ...c, ownerAccountId: c.ownerAccount.id, ownerAccountName: c.ownerAccount.name }
+
+ return formatChannelForSelect(channel, { editor: false, owner: false, collaborate: false })
+ })
+ }))
}
onHide () {
@@ -148,7 +150,15 @@ export class SelectChannelAdminComponent implements ControlValueAccessor, OnChan
{
label: $localize`Searched channels`,
value: 'search',
- items: data.map(c => this.formatChannel({ channel: c, displayOwner: true }))
+ items: data.map(c => {
+ const userChannel = { ...c, ownerAccountId: c.ownerAccount.id, ownerAccountName: c.ownerAccount.name }
+
+ return {
+ ...formatChannelForSelect(userChannel, { editor: false, owner: false, collaborate: false }),
+
+ description: c.ownerAccount.displayName
+ }
+ })
}
]
@@ -187,29 +197,6 @@ export class SelectChannelAdminComponent implements ControlValueAccessor, OnChan
const item = this.options.flatMap(o => o.items)
.find(c => c.id === this.selectedId)
- this.channelChanged.emit(pick(item, [ 'ownerAccountName', 'channelDisplayName', 'channelName' ]))
- }
-
- private formatChannel (options: {
- channel: VideoChannelServer
- displayOwner: boolean
- }): ChannelOption {
- const { channel, displayOwner } = options
-
- return {
- id: channel.id,
- label: channel.displayName,
- description: displayOwner
- ? channel.ownerAccount.displayName
- : undefined,
-
- imageUrl: channel.avatars.length
- ? findAppropriateImageFileUrl(channel.avatars, 21)
- : VideoChannel.GET_DEFAULT_AVATAR_URL(21),
-
- ownerAccountName: channel.ownerAccount.name,
- channelDisplayName: channel.displayName,
- channelName: channel.name
- }
+ this.channelChanged.emit(item)
}
}
diff --git a/client/src/app/shared/shared-forms/select/select-channel-auto.component.ts b/client/src/app/shared/shared-forms/select/channel/select-channel-auto.component.ts
similarity index 92%
rename from client/src/app/shared/shared-forms/select/select-channel-auto.component.ts
rename to client/src/app/shared/shared-forms/select/channel/select-channel-auto.component.ts
index a779f17b21..b8989c2c10 100644
--- a/client/src/app/shared/shared-forms/select/select-channel-auto.component.ts
+++ b/client/src/app/shared/shared-forms/select/channel/select-channel-auto.component.ts
@@ -1,13 +1,12 @@
import { ChangeDetectionStrategy, Component, forwardRef, inject, input, OnChanges, OnDestroy, output } from '@angular/core'
import { ControlValueAccessor, FormsModule, NG_VALUE_ACCESSOR } from '@angular/forms'
import { AuthService } from '@app/core'
-import { buildUserChannelsForSelect } from '@app/helpers/utils/channel'
+import { buildUserChannelsForSelect } from '@app/shared/shared-forms/select/channel/select-channel-helpers'
import { VideoChannel } from '@app/shared/shared-main/channel/video-channel.model'
import { Account } from '@peertube/peertube-models'
import { first, Subscription } from 'rxjs'
-import { SelectChannelItem } from '../../../../types/select-options-item.model'
+import { SelectChannelItem } from '../../../../../types/select-options-item.model'
import { SelectChannelAdminComponent } from './select-channel-admin.component'
-import { ChannelMetadata } from './select-channel-metadata.model'
import { SelectChannelUserComponent } from './select-channel-user.component'
/**
@@ -54,7 +53,7 @@ export class SelectChannelAutoComponent implements ControlValueAccessor, OnChang
readonly ownerChannel = input.required<Pick<VideoChannel, 'id'>>()
readonly ownerAccount = input.required<Pick<Account, 'name'>>()
- readonly channelChanged = output<ChannelMetadata>()
+ readonly channelChanged = output<SelectChannelItem>()
userChannels: SelectChannelItem[]
selectedId: number
diff --git a/client/src/app/shared/shared-forms/select/channel/select-channel-helpers.ts b/client/src/app/shared/shared-forms/select/channel/select-channel-helpers.ts
new file mode 100644
index 0000000000..0f0cf5f4d5
--- /dev/null
+++ b/client/src/app/shared/shared-forms/select/channel/select-channel-helpers.ts
@@ -0,0 +1,88 @@
+import { VideoChannel } from '@app/shared/shared-main/channel/video-channel.model'
+import { sortBy } from '@peertube/peertube-core-utils'
+import { UserVideoChannel, VideoChannel as VideoChannelServer } from '@peertube/peertube-models'
+import { findAppropriateImageFileUrl } from '@root-helpers/index'
+import { first, map } from 'rxjs/operators'
+import { SelectChannelItem } from '../../../../../types/select-options-item.model'
+import { AuthService } from '../../../../core/auth'
+
+// List channels of selected accountName
+// Set the currentChannelId to correctly display channel editor/owner information
+export function listChannelsForSelect (options: {
+ authService: AuthService
+ includeCollaborations: boolean
+}) {
+ const { authService } = options
+
+ return authService.userInformationLoaded
+ .pipe(
+ first(),
+ map(() => buildUserChannelsForSelect(options))
+ )
+}
+
+export function buildUserChannelsForSelect (options: {
+ authService: AuthService
+ includeCollaborations: boolean
+}) {
+ const { authService, includeCollaborations } = options
+
+ const user = authService.getUser()
+ const collaborate = user.isCollaboratingToChannels()
+
+ const allChannels = includeCollaborations
+ ? [
+ ...formatChannelsForSelect(user.videoChannels, { editor: false, owner: true, collaborate }),
+ ...formatChannelsForSelect(user.videoChannelCollaborations, { editor: true, owner: false, collaborate })
+ ]
+ : formatChannelsForSelect(user.videoChannels, { editor: false, owner: false, collaborate })
+
+ return sortBy(allChannels, 'updatedAt').reverse()
+}
+
+export function formatChannelForSelect (channel: UserVideoChannel, options: {
+ editor: boolean
+ owner: boolean
+ collaborate: boolean
+}): SelectChannelItem {
+ const { editor, collaborate, owner } = options
+
+ return {
+ id: channel.id,
+ name: channel.name,
+ label: channel.displayName,
+ support: channel.support,
+ editor,
+ collaborate,
+ owner,
+ imageUrl: getAvatarFileUrl(channel),
+
+ displayName: channel.displayName,
+ ownerAccountId: channel.ownerAccountId,
+ ownerAccountName: channel.ownerAccountName,
+
+ updatedAt: channel.updatedAt
+ }
+}
+
+// ---------------------------------------------------------------------------
+// Private
+// ---------------------------------------------------------------------------
+
+function formatChannelsForSelect (channel: UserVideoChannel[], options: {
+ editor: boolean
+ owner: boolean
+ collaborate: boolean
+}): SelectChannelItem[] {
+ const { editor, collaborate, owner } = options
+
+ return channel.map(c => formatChannelForSelect(c, { editor, collaborate, owner }))
+}
+
+function getAvatarFileUrl (channel: VideoChannelServer) {
+ if (!channel.avatars || channel.avatars.length === 0) {
+ return VideoChannel.GET_DEFAULT_AVATAR_URL(21)
+ }
+
+ return findAppropriateImageFileUrl(channel.avatars, 21)
+}
diff --git a/client/src/app/shared/shared-forms/select/select-channel-user.component.ts b/client/src/app/shared/shared-forms/select/channel/select-channel-user.component.ts
similarity index 70%
rename from client/src/app/shared/shared-forms/select/select-channel-user.component.ts
rename to client/src/app/shared/shared-forms/select/channel/select-channel-user.component.ts
index 00c891b576..0e0e6c6157 100644
--- a/client/src/app/shared/shared-forms/select/select-channel-user.component.ts
+++ b/client/src/app/shared/shared-forms/select/channel/select-channel-user.component.ts
@@ -1,9 +1,8 @@
-import { ChangeDetectionStrategy, Component, forwardRef, input, OnChanges } from '@angular/core'
+import { ChangeDetectionStrategy, Component, forwardRef, input, output } from '@angular/core'
import { ControlValueAccessor, FormsModule, NG_VALUE_ACCESSOR } from '@angular/forms'
import { CollaboratorStateComponent } from '@app/shared/shared-main/channel/collaborator-state.component'
-import { VideoChannel } from '@app/shared/shared-main/channel/video-channel.model'
-import { SelectChannelItem, SelectOptionsItem } from '../../../../types/select-options-item.model'
-import { SelectOptionsComponent } from './select-options.component'
+import { SelectChannelItem } from '../../../../../types/select-options-item.model'
+import { SelectOptionsComponent } from '../select-options.component'
@Component({
selector: 'my-select-channel-user',
@@ -11,12 +10,12 @@ import { SelectOptionsComponent } from './select-options.component'
<my-select-options
[inputId]="inputId()"
- [items]="channels"
+ [items]="items()"
[(ngModel)]="selectedId"
(ngModelChange)="onModelChange()"
- [filter]="channels && channels.length > 5"
+ [filter]="items() && items().length > 5"
>
<ng-template #itemExtra let-item>
@if (item.collaborate) {
@@ -39,25 +38,14 @@ import { SelectOptionsComponent } from './select-options.component'
changeDetection: ChangeDetectionStrategy.Eager,
imports: [ FormsModule, SelectOptionsComponent, CollaboratorStateComponent ]
})
-export class SelectChannelUserComponent implements ControlValueAccessor, OnChanges {
+export class SelectChannelUserComponent implements ControlValueAccessor {
readonly inputId = input.required<string>()
readonly items = input<SelectChannelItem[]>([])
- readonly channelChanged = output<ChannelMetadata>()
+ readonly channelChanged = output<SelectChannelItem>()
- channels: SelectOptionsItem[]
selectedId: number
- ngOnChanges () {
- this.channels = this.items().map(c => {
- const avatarFileUrl = c.avatarFileUrl
- ? c.avatarFileUrl
- : VideoChannel.GET_DEFAULT_AVATAR_URL(21)
-
- return Object.assign({}, c, { imageUrl: avatarFileUrl })
- })
- }
-
propagateChange = (_: any) => {
// empty
}
@@ -78,5 +66,8 @@ export class SelectChannelUserComponent implements ControlValueAccessor, OnChang
onModelChange () {
this.propagateChange(this.selectedId)
+
+ const channel = this.items().find(c => c.id === this.selectedId)
+ if (channel) this.channelChanged.emit(channel)
}
}
diff --git a/client/src/app/shared/shared-forms/select/select-channel-metadata.model.ts b/client/src/app/shared/shared-forms/select/select-channel-metadata.model.ts
deleted file mode 100644
index bffb7a3b5a..0000000000
--- a/client/src/app/shared/shared-forms/select/select-channel-metadata.model.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-export interface ChannelMetadata {
- ownerAccountName: string
- channelDisplayName: string
- channelName: string
-}
diff --git a/client/src/app/shared/shared-video/bulk-update-videos-modal.component.ts b/client/src/app/shared/shared-video/bulk-update-videos-modal.component.ts
index da9ccad0be..66982d06ff 100644
--- a/client/src/app/shared/shared-video/bulk-update-videos-modal.component.ts
+++ b/client/src/app/shared/shared-video/bulk-update-videos-modal.component.ts
@@ -4,7 +4,7 @@ import { FormsModule } from '@angular/forms'
import { form, FormField, required } from '@angular/forms/signals'
import { AuthService, Notifier, ServerService } from '@app/core'
import { formatICU } from '@app/helpers'
-import { listChannelsForSelect } from '@app/helpers/utils/channel'
+import { listChannelsForSelect } from '@app/shared/shared-forms/select/channel/select-channel-helpers'
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal'
import { ConstantLabel, Video, VideoCommentPolicyType, VideoPrivacy, VideoPrivacyType, VideoUpdate } from '@peertube/peertube-models'
import { SelectChannelItem } from '@pt-types'
@@ -12,7 +12,7 @@ import { concatMap, from, toArray } from 'rxjs'
import { videoSupportValidator } from '../form-validators/video-validators'
import { FormErrorComponent } from '../shared-forms/form-error.component'
import { PeertubeCheckboxComponent } from '../shared-forms/peertube-checkbox.component'
-import { SelectChannelUserComponent } from '../shared-forms/select/select-channel-user.component'
+import { SelectChannelUserComponent } from '../shared-forms/select/channel/select-channel-user.component'
import { SelectOptionsComponent } from '../shared-forms/select/select-options.component'
import { GlobalIconComponent } from '../shared-icons/global-icon.component'
import { ButtonComponent } from '../shared-main/buttons/button.component'
diff --git a/client/src/types/select-options-item.model.ts b/client/src/types/select-options-item.model.ts
index b937f2d538..2923d65891 100644
--- a/client/src/types/select-options-item.model.ts
+++ b/client/src/types/select-options-item.model.ts
@@ -10,10 +10,17 @@ export interface SelectOptionsItem<T = string | number> {
export interface SelectChannelItem extends SelectOptionsItem {
id: number // Force number
name: string
- avatarFileUrl: string
support: string
editor: boolean
+ collaborate: boolean
+ owner: boolean
+
+ ownerAccountName: string
+ ownerAccountId: number
+ displayName: string
+
+ updatedAt: string | Date
}
export interface SelectOptionsGroup {
diff --git a/packages/models/src/users/user.model.ts b/packages/models/src/users/user.model.ts
index 601f9c19fe..93aa01dd63 100644
--- a/packages/models/src/users/user.model.ts
+++ b/packages/models/src/users/user.model.ts
@@ -6,8 +6,9 @@ import { UserAdminFlagType } from './user-flag.model.js'
import { UserNotificationSetting } from './user-notification-setting.model.js'
import { UserRoleType } from './user-role.js'
-type UserVideoChannel = Omit<VideoChannel, 'ownerAccount'> & {
+export type UserVideoChannel = Omit<VideoChannel, 'ownerAccount'> & {
ownerAccountId: number
+ ownerAccountName: string
}
export interface User {
id: number
diff --git a/packages/tests/src/api/videos/channel-collaborators.ts b/packages/tests/src/api/videos/channel-collaborators.ts
index 5396bd88c0..71c28d5b41 100644
--- a/packages/tests/src/api/videos/channel-collaborators.ts
+++ b/packages/tests/src/api/videos/channel-collaborators.ts
@@ -52,6 +52,12 @@ describe('Test channel collaborators', function () {
expect(c).to.have.property('createdAt')
expect(c).to.have.property('avatars')
expect(c).to.have.property('ownerAccountId')
+ expect(c).to.have.property('ownerAccountName')
+ }
+
+ for (const c of me.videoChannelCollaborations) {
+ expect(c.ownerAccountId).to.be.above(0)
+ expect(c.ownerAccountName).to.not.be.empty
}
}
diff --git a/server/core/controllers/api/users/index.ts b/server/core/controllers/api/users/index.ts
index efd6dddadc..fc2bc36d1d 100644
--- a/server/core/controllers/api/users/index.ts
+++ b/server/core/controllers/api/users/index.ts
@@ -107,7 +107,13 @@ usersRouter.post(
asyncMiddleware(unblockUser)
)
-usersRouter.get('/:id', authenticate, ensureUserHasRight(UserRight.MANAGE_USERS), asyncMiddleware(usersGetValidator), getUser)
+usersRouter.get(
+ '/:id',
+ authenticate,
+ ensureUserHasRight(UserRight.MANAGE_USERS),
+ asyncMiddleware(usersGetValidator),
+ getUser
+)
usersRouter.post(
'/',
diff --git a/server/core/models/account/account.ts b/server/core/models/account/account.ts
index 1a1f33a717..b133a40989 100644
--- a/server/core/models/account/account.ts
+++ b/server/core/models/account/account.ts
@@ -38,6 +38,7 @@ import { ApplicationModel } from '../application/application.js'
import { AccountAutomaticTagPolicyModel } from '../automatic-tag/account-automatic-tag-policy.js'
import { CommentAutomaticTagModel } from '../automatic-tag/comment-automatic-tag.js'
import { VideoAutomaticTagModel } from '../automatic-tag/video-automatic-tag.js'
+import { AccountBlocklistModel } from '../blocklist/account-blocklist.js'
import { ServerBlocklistModel } from '../blocklist/server-blocklist.js'
import { ServerModel, serverSummaryAttributes } from '../server/server.js'
import { SequelizeModel, buildSQLAttributes, getSort, throwIfNotValid } from '../shared/index.js'
@@ -47,7 +48,6 @@ import { VideoChannelModel } from '../video/video-channel.js'
import { VideoCommentModel } from '../video/video-comment.js'
import { VideoPlaylistModel } from '../video/video-playlist.js'
import { VideoModel } from '../video/video.js'
-import { AccountBlocklistModel } from '../blocklist/account-blocklist.js'
export enum ScopeNames {
SUMMARY = 'SUMMARY'
diff --git a/server/core/models/user/sql/user/user-list-query-builder.ts b/server/core/models/user/sql/user/user-list-query-builder.ts
index 7abe4e2ce4..4788bd3eb2 100644
--- a/server/core/models/user/sql/user/user-list-query-builder.ts
+++ b/server/core/models/user/sql/user/user-list-query-builder.ts
@@ -84,6 +84,10 @@ export class UserListQueryBuilder extends AbstractListQuery {
' LEFT JOIN "actorImage" AS "Account->Collabs->Channel->Actor->Banners" ' +
' ON "Account->Collabs->Channel->Actor"."id" = "Account->Collabs->Channel->Actor->Banners"."actorId" ' +
` AND "Account->Collabs->Channel->Actor->Banners"."type" = ${ActorImageType.BANNER} ` +
+ ` INNER JOIN "account" "Account->Collabs->Channel->Account" ` +
+ ` ON "Account->Collabs->Channel"."accountId" = "Account->Collabs->Channel->Account"."id" ` +
+ ` INNER JOIN "actor" "Account->Collabs->Channel->Account->Actor" ` +
+ ` ON "Account->Collabs->Channel->Account"."id" = "Account->Collabs->Channel->Account->Actor"."accountId" ` +
') ON "Account->Collabs"."channelId" = "Account->Collabs->Channel"."id"'
this.builtChannelCollabsJoin = true
@@ -137,7 +141,9 @@ export class UserListQueryBuilder extends AbstractListQuery {
this.tableAttributes.getCollabChannelActorAttributes(),
this.tableAttributes.getCollabChannelActorServerAttributes(),
this.tableAttributes.getCollabChannelActorAvatarAttributes(),
- this.tableAttributes.getCollabChannelActorBannerAttributes()
+ this.tableAttributes.getCollabChannelActorBannerAttributes(),
+ this.tableAttributes.getCollabChannelAccountAttributes(),
+ this.tableAttributes.getCollabChannelAccountActorAttributes()
]
}
diff --git a/server/core/models/user/sql/user/user-table-attributes.ts b/server/core/models/user/sql/user/user-table-attributes.ts
index 764d1b0c2e..ab65964b8d 100644
--- a/server/core/models/user/sql/user/user-table-attributes.ts
+++ b/server/core/models/user/sql/user/user-table-attributes.ts
@@ -3,11 +3,12 @@ import { AccountModel } from '@server/models/account/account.js'
import { ActorImageModel } from '@server/models/actor/actor-image.js'
import { ActorModel } from '@server/models/actor/actor.js'
import { ServerModel } from '@server/models/server/server.js'
-import { UserModel } from '../../user.js'
+import { buildSQLAttributes } from '@server/models/shared/table.js'
+import { VideoChannelCollaboratorModel } from '@server/models/video/video-channel-collaborator.js'
import { VideoChannelModel } from '@server/models/video/video-channel.js'
import { VideoPlaylistModel } from '@server/models/video/video-playlist.js'
import { UserNotificationSettingModel } from '../../user-notification-setting.js'
-import { VideoChannelCollaboratorModel } from '@server/models/video/video-channel-collaborator.js'
+import { UserModel } from '../../user.js'
export class UserTableAttributes {
@Memoize()
@@ -117,4 +118,23 @@ export class UserTableAttributes {
'Account.Collabs.Channel.Actor.Banners.'
).join(', ')
}
+ @Memoize()
+ getCollabChannelAccountAttributes () {
+ return buildSQLAttributes({
+ model: AccountModel,
+ tableName: 'Account->Collabs->Channel->Account',
+ aliasPrefix: 'Account.Collabs.Channel.Account.',
+ includeAttributes: [ 'id', 'name' ]
+ }).join(', ')
+ }
+
+ @Memoize()
+ getCollabChannelAccountActorAttributes () {
+ return buildSQLAttributes({
+ model: ActorModel,
+ tableName: 'Account->Collabs->Channel->Account->Actor',
+ aliasPrefix: 'Account.Collabs.Channel.Account.Actor.',
+ includeAttributes: [ 'id', 'preferredUsername' ]
+ }).join(', ')
+ }
}
diff --git a/server/core/models/user/user.ts b/server/core/models/user/user.ts
index cea06f5bac..d8707858d8 100644
--- a/server/core/models/user/user.ts
+++ b/server/core/models/user/user.ts
@@ -1165,6 +1165,11 @@ export class UserModel extends SequelizeModel<UserModel> {
}
formatChannel (channel: MChannelFormattable) {
- return { ...channel.toFormattedJSON(), ownerAccountId: channel.accountId }
+ return {
+ ...channel.toFormattedJSON(),
+
+ ownerAccountId: channel.Account?.id ?? null,
+ ownerAccountName: channel.Account?.Actor.preferredUsername ?? null
+ }
}
}