]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Don't display remove file icon in some cases
authorChocobozzz <me@florianbigard.com>
Tue, 13 Sep 2022 10:00:13 +0000 (12:00 +0200)
committerChocobozzz <me@florianbigard.com>
Tue, 13 Sep 2022 10:00:13 +0000 (12:00 +0200)
client/src/app/+admin/overview/videos/video-list.component.html
client/src/app/+admin/overview/videos/video-list.component.ts
client/src/app/shared/shared-main/video/video.model.ts
server/tests/api/live/live.ts
server/tests/api/transcoding/transcoder.ts
server/tests/api/transcoding/video-studio.ts
server/tests/cli/update-host.ts
server/tests/shared/videos.ts
shared/core-utils/videos/privacy.ts

index 06b9ab3471e85082435c3f669c87e183eaf065d3..14bbb55e9bcfec629476eb9241a0f153e282ec27 100644 (file)
                 {{ file.resolution.label }}: {{ file.size | bytes: 1 }}
 
                 <my-global-icon
+                  *ngIf="canRemoveOneFile(video)"
                   i18n-ngbTooltip ngbTooltip="Delete this file" iconName="delete" role="button"
                   (click)="removeVideoFile(video, file, 'webtorrent')"
                 ></my-global-icon>
                 {{ file.resolution.label }}: {{ file.size | bytes: 1 }}
 
                 <my-global-icon
+                  *ngIf="canRemoveOneFile(video)"
                   i18n-ngbTooltip ngbTooltip="Delete this file" iconName="delete" role="button"
                   (click)="removeVideoFile(video, file, 'hls')"
                 ></my-global-icon>
index ed7ec54a1c1a0e06c7c964e10292d4046bdf49f3..cb693ce12dd1690830cf33006d83438a128b520a 100644 (file)
@@ -166,6 +166,10 @@ export class VideoListComponent extends RestTable implements OnInit {
     return video.files.length !== 0
   }
 
+  canRemoveOneFile (video: Video) {
+    return video.canRemoveOneFile(this.authUser)
+  }
+
   getFilesSize (video: Video) {
     let files = video.files
 
index 2e4ab87d75ce0f65ef1f441f63f6c659db70ad81..c9c6b979c2a50ed409c51bbd8db21181c73a5660 100644 (file)
@@ -1,8 +1,8 @@
 import { AuthUser } from '@app/core'
 import { User } from '@app/core/users/user.model'
-import { durationToString, prepareIcu, getAbsoluteAPIUrl, getAbsoluteEmbedUrl } from '@app/helpers'
+import { durationToString, getAbsoluteAPIUrl, getAbsoluteEmbedUrl, prepareIcu } from '@app/helpers'
 import { Actor } from '@app/shared/shared-main/account/actor.model'
-import { buildVideoWatchPath } from '@shared/core-utils'
+import { buildVideoWatchPath, getAllFiles } from '@shared/core-utils'
 import { peertubeTranslate } from '@shared/core-utils/i18n'
 import {
   ActorImage,
@@ -240,6 +240,13 @@ export class Video implements VideoServerModel {
     return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.SEE_ALL_VIDEOS))
   }
 
+  canRemoveOneFile (user: AuthUser) {
+    return this.isLocal &&
+      user && user.hasRight(UserRight.MANAGE_VIDEO_FILES) &&
+      this.state.id !== VideoState.TO_TRANSCODE &&
+      getAllFiles(this).length > 1
+  }
+
   canRemoveFiles (user: AuthUser) {
     return this.isLocal &&
       user && user.hasRight(UserRight.MANAGE_VIDEO_FILES) &&
index 48982f4de36a7e254148e102ef4a701f7caa3105..885751285de0aceffff7ee58846f1bdbe706b126 100644 (file)
@@ -3,8 +3,8 @@
 import { expect } from 'chai'
 import { basename, join } from 'path'
 import { ffprobePromise, getVideoStream } from '@server/helpers/ffmpeg'
-import { checkLiveSegmentHash, checkResolutionsInMasterPlaylist, getAllFiles, testImage } from '@server/tests/shared'
-import { wait } from '@shared/core-utils'
+import { checkLiveSegmentHash, checkResolutionsInMasterPlaylist, testImage } from '@server/tests/shared'
+import { getAllFiles, wait } from '@shared/core-utils'
 import {
   HttpStatusCode,
   LiveVideo,
index db012780520ae5414cd775984530b324aabe9cbe..c591f5f6f8ee464a08dfb5b36b0a35b75c8d0e54 100644 (file)
@@ -2,8 +2,8 @@
 
 import { expect } from 'chai'
 import { canDoQuickTranscode } from '@server/helpers/ffmpeg'
-import { generateHighBitrateVideo, generateVideoWithFramerate, getAllFiles } from '@server/tests/shared'
-import { buildAbsoluteFixturePath, getMaxBitrate, getMinLimitBitrate, omit } from '@shared/core-utils'
+import { generateHighBitrateVideo, generateVideoWithFramerate } from '@server/tests/shared'
+import { buildAbsoluteFixturePath, getAllFiles, getMaxBitrate, getMinLimitBitrate, omit } from '@shared/core-utils'
 import {
   buildFileMetadata,
   getAudioStream,
index ac1c0fc7e7ecbf5b807dd1f8bd93b10641ff2d77..9613111b52ebf438745d529814b8c00cefd0abca 100644 (file)
@@ -1,6 +1,6 @@
 import { expect } from 'chai'
-import { expectStartWith, getAllFiles } from '@server/tests/shared'
-import { areObjectStorageTestsDisabled } from '@shared/core-utils'
+import { expectStartWith } from '@server/tests/shared'
+import { areObjectStorageTestsDisabled, getAllFiles } from '@shared/core-utils'
 import { VideoStudioTask } from '@shared/models'
 import {
   cleanupTests,
index 53c4e7824248bec60dc10d0fc49016e441e0cf5a..97632450a297c3130944f677b40e4bb312e24f39 100644 (file)
@@ -1,6 +1,7 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
 import { expect } from 'chai'
+import { getAllFiles } from '@shared/core-utils'
 import {
   cleanupTests,
   createSingleServer,
@@ -11,7 +12,6 @@ import {
   setAccessTokensToServers,
   waitJobs
 } from '@shared/server-commands'
-import { getAllFiles } from '../shared'
 
 describe('Test update host scripts', function () {
   let server: PeerTubeServer
index 3ab2453920f9a2df3d7b268576eb47fe7f980bed..e18329e07677279d9b7703a74577c0021f14bf2b 100644 (file)
@@ -241,16 +241,6 @@ async function uploadRandomVideoOnServers (
   return res
 }
 
-function getAllFiles (video: VideoDetails) {
-  const files = video.files
-
-  if (video.streamingPlaylists[0]) {
-    return files.concat(video.streamingPlaylists[0].files)
-  }
-
-  return files
-}
-
 // ---------------------------------------------------------------------------
 
 export {
@@ -258,6 +248,5 @@ export {
   checkUploadVideoParam,
   uploadRandomVideoOnServers,
   checkVideoFilesWereRemoved,
-  saveVideoInServers,
-  getAllFiles
+  saveVideoInServers
 }
index 7d3b67d501221886f51c09d48e1fd7e92669aa04..f33487b490c5363a2a928231becfaa8f8f911ff0 100644 (file)
@@ -1,9 +1,21 @@
+import { VideoDetails } from '../../models/videos/video.model'
 import { VideoPrivacy } from '../../models/videos/video-privacy.enum'
 
 function getAllPrivacies () {
   return [ VideoPrivacy.PUBLIC, VideoPrivacy.INTERNAL, VideoPrivacy.PRIVATE, VideoPrivacy.UNLISTED ]
 }
 
+function getAllFiles (video: Partial<Pick<VideoDetails, 'files' | 'streamingPlaylists'>>) {
+  const files = video.files
+
+  if (video.streamingPlaylists[0]) {
+    return files.concat(video.streamingPlaylists[0].files)
+  }
+
+  return files
+}
+
 export {
-  getAllPrivacies
+  getAllPrivacies,
+  getAllFiles
 }