aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-12-14 17:17:01 +0100
committerChocobozzz <me@florianbigard.com>2021-12-14 17:17:01 +0100
commit3cf68b869decf07ff7435fe1436d4f3134df1bf4 (patch)
tree836efe5ddc626fef3ba4c96269efbca305f46256 /server
parenta6f919e455f2c6ae8f2194da4aa66824a6bfd09e (diff)
downloadPeerTube-3cf68b869decf07ff7435fe1436d4f3134df1bf4.tar.gz
PeerTube-3cf68b869decf07ff7435fe1436d4f3134df1bf4.tar.zst
PeerTube-3cf68b869decf07ff7435fe1436d4f3134df1bf4.zip
Ability for admins to set default upload values
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/videos/import.ts6
-rw-r--r--server/initializers/checker-before-init.ts1
-rw-r--r--server/initializers/config.ts11
-rw-r--r--server/lib/server-config-manager.ts9
-rw-r--r--server/lib/video.ts7
-rw-r--r--server/tests/api/server/config-defaults.ts116
-rw-r--r--server/tests/api/server/index.ts2
7 files changed, 145 insertions, 7 deletions
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts
index 52864bdfd..3c445efce 100644
--- a/server/controllers/api/videos/import.ts
+++ b/server/controllers/api/videos/import.ts
@@ -216,10 +216,10 @@ async function buildVideo (channelId: number, body: VideoImportCreate, importDat
216 name: body.name || importData.name || 'Unknown name', 216 name: body.name || importData.name || 'Unknown name',
217 remote: false, 217 remote: false,
218 category: body.category || importData.category, 218 category: body.category || importData.category,
219 licence: body.licence || importData.licence, 219 licence: body.licence ?? importData.licence ?? CONFIG.DEFAULTS.PUBLISH.LICENCE,
220 language: body.language || importData.language, 220 language: body.language || importData.language,
221 commentsEnabled: body.commentsEnabled !== false, // If the value is not "false", the default is "true" 221 commentsEnabled: body.commentsEnabled ?? CONFIG.DEFAULTS.PUBLISH.COMMENTS_ENABLED,
222 downloadEnabled: body.downloadEnabled !== false, 222 downloadEnabled: body.downloadEnabled ?? CONFIG.DEFAULTS.PUBLISH.DOWNLOAD_ENABLED,
223 waitTranscoding: body.waitTranscoding || false, 223 waitTranscoding: body.waitTranscoding || false,
224 state: VideoState.TO_IMPORT, 224 state: VideoState.TO_IMPORT,
225 nsfw: body.nsfw || importData.nsfw || false, 225 nsfw: body.nsfw || importData.nsfw || false,
diff --git a/server/initializers/checker-before-init.ts b/server/initializers/checker-before-init.ts
index c85c389cd..2c24e20c8 100644
--- a/server/initializers/checker-before-init.ts
+++ b/server/initializers/checker-before-init.ts
@@ -34,6 +34,7 @@ function checkMissedConfig () {
34 'import.videos.http.enabled', 'import.videos.torrent.enabled', 'import.videos.concurrency', 'auto_blacklist.videos.of_users.enabled', 34 'import.videos.http.enabled', 'import.videos.torrent.enabled', 'import.videos.concurrency', 'auto_blacklist.videos.of_users.enabled',
35 'trending.videos.interval_days', 35 'trending.videos.interval_days',
36 'client.videos.miniature.prefer_author_display_name', 'client.menu.login.redirect_on_single_external_auth', 36 'client.videos.miniature.prefer_author_display_name', 'client.menu.login.redirect_on_single_external_auth',
37 'defaults.publish.download_enabled', 'defaults.publish.comments_enabled', 'defaults.publish.privacy', 'defaults.publish.licence',
37 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route', 38 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route',
38 'instance.is_nsfw', 'instance.default_nsfw_policy', 'instance.robots', 'instance.securitytxt', 39 'instance.is_nsfw', 'instance.default_nsfw_policy', 'instance.robots', 'instance.securitytxt',
39 'services.twitter.username', 'services.twitter.whitelisted', 40 'services.twitter.username', 'services.twitter.whitelisted',
diff --git a/server/initializers/config.ts b/server/initializers/config.ts
index eb848be6b..70179d25c 100644
--- a/server/initializers/config.ts
+++ b/server/initializers/config.ts
@@ -4,7 +4,7 @@ import { dirname, join } from 'path'
4import { decacheModule } from '@server/helpers/decache' 4import { decacheModule } from '@server/helpers/decache'
5import { VideoRedundancyConfigFilter } from '@shared/models/redundancy/video-redundancy-config-filter.type' 5import { VideoRedundancyConfigFilter } from '@shared/models/redundancy/video-redundancy-config-filter.type'
6import { BroadcastMessageLevel } from '@shared/models/server' 6import { BroadcastMessageLevel } from '@shared/models/server'
7import { VideosRedundancyStrategy } from '../../shared/models' 7import { VideoPrivacy, VideosRedundancyStrategy } from '../../shared/models'
8import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' 8import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type'
9import { buildPath, parseBytes, parseDurationToMs, root } from '../helpers/core-utils' 9import { buildPath, parseBytes, parseDurationToMs, root } from '../helpers/core-utils'
10 10
@@ -71,6 +71,15 @@ const CONFIG = {
71 } 71 }
72 }, 72 },
73 73
74 DEFAULTS: {
75 PUBLISH: {
76 DOWNLOAD_ENABLED: config.get<boolean>('defaults.publish.download_enabled'),
77 COMMENTS_ENABLED: config.get<boolean>('defaults.publish.comments_enabled'),
78 PRIVACY: config.get<VideoPrivacy>('defaults.publish.privacy'),
79 LICENCE: config.get<number>('defaults.publish.licence')
80 }
81 },
82
74 STORAGE: { 83 STORAGE: {
75 TMP_DIR: buildPath(config.get<string>('storage.tmp')), 84 TMP_DIR: buildPath(config.get<string>('storage.tmp')),
76 BIN_DIR: buildPath(config.get<string>('storage.bin')), 85 BIN_DIR: buildPath(config.get<string>('storage.bin')),
diff --git a/server/lib/server-config-manager.ts b/server/lib/server-config-manager.ts
index 6aa459f82..8aea4cd6d 100644
--- a/server/lib/server-config-manager.ts
+++ b/server/lib/server-config-manager.ts
@@ -55,6 +55,15 @@ class ServerConfigManager {
55 } 55 }
56 }, 56 },
57 57
58 defaults: {
59 publish: {
60 downloadEnabled: CONFIG.DEFAULTS.PUBLISH.DOWNLOAD_ENABLED,
61 commentsEnabled: CONFIG.DEFAULTS.PUBLISH.COMMENTS_ENABLED,
62 privacy: CONFIG.DEFAULTS.PUBLISH.PRIVACY,
63 licence: CONFIG.DEFAULTS.PUBLISH.LICENCE
64 }
65 },
66
58 webadmin: { 67 webadmin: {
59 configuration: { 68 configuration: {
60 edition: { 69 edition: {
diff --git a/server/lib/video.ts b/server/lib/video.ts
index 1cfe4f27c..e5af028ea 100644
--- a/server/lib/video.ts
+++ b/server/lib/video.ts
@@ -9,16 +9,17 @@ import { MThumbnail, MUserId, MVideoFile, MVideoTag, MVideoThumbnail, MVideoUUID
9import { ThumbnailType, VideoCreate, VideoPrivacy, VideoTranscodingPayload } from '@shared/models' 9import { ThumbnailType, VideoCreate, VideoPrivacy, VideoTranscodingPayload } from '@shared/models'
10import { CreateJobOptions, JobQueue } from './job-queue/job-queue' 10import { CreateJobOptions, JobQueue } from './job-queue/job-queue'
11import { updateVideoMiniatureFromExisting } from './thumbnail' 11import { updateVideoMiniatureFromExisting } from './thumbnail'
12import { CONFIG } from '@server/initializers/config'
12 13
13function buildLocalVideoFromReq (videoInfo: VideoCreate, channelId: number): FilteredModelAttributes<VideoModel> { 14function buildLocalVideoFromReq (videoInfo: VideoCreate, channelId: number): FilteredModelAttributes<VideoModel> {
14 return { 15 return {
15 name: videoInfo.name, 16 name: videoInfo.name,
16 remote: false, 17 remote: false,
17 category: videoInfo.category, 18 category: videoInfo.category,
18 licence: videoInfo.licence, 19 licence: videoInfo.licence ?? CONFIG.DEFAULTS.PUBLISH.LICENCE,
19 language: videoInfo.language, 20 language: videoInfo.language,
20 commentsEnabled: videoInfo.commentsEnabled !== false, // If the value is not "false", the default is "true" 21 commentsEnabled: videoInfo.commentsEnabled ?? CONFIG.DEFAULTS.PUBLISH.COMMENTS_ENABLED,
21 downloadEnabled: videoInfo.downloadEnabled !== false, 22 downloadEnabled: videoInfo.downloadEnabled ?? CONFIG.DEFAULTS.PUBLISH.DOWNLOAD_ENABLED,
22 waitTranscoding: videoInfo.waitTranscoding || false, 23 waitTranscoding: videoInfo.waitTranscoding || false,
23 nsfw: videoInfo.nsfw || false, 24 nsfw: videoInfo.nsfw || false,
24 description: videoInfo.description, 25 description: videoInfo.description,
diff --git a/server/tests/api/server/config-defaults.ts b/server/tests/api/server/config-defaults.ts
new file mode 100644
index 000000000..2433d3119
--- /dev/null
+++ b/server/tests/api/server/config-defaults.ts
@@ -0,0 +1,116 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
5import { cleanupTests, createSingleServer, FIXTURE_URLS, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/extra-utils'
6import { VideoDetails, VideoPrivacy } from '@shared/models'
7
8const expect = chai.expect
9
10describe('Test config defaults', function () {
11 let server: PeerTubeServer
12 let channelId: number
13
14 before(async function () {
15 this.timeout(30000)
16
17 const overrideConfig = {
18 defaults: {
19 publish: {
20 comments_enabled: false,
21 download_enabled: false,
22 privacy: VideoPrivacy.INTERNAL,
23 licence: 4
24 }
25 }
26 }
27
28 server = await createSingleServer(1, overrideConfig)
29 await setAccessTokensToServers([ server ])
30 await setDefaultVideoChannel([ server ])
31
32 channelId = server.store.channel.id
33 })
34
35 describe('Default publish values', function () {
36 const attributes = {
37 name: 'video',
38 downloadEnabled: undefined,
39 commentsEnabled: undefined,
40 licence: undefined,
41 privacy: VideoPrivacy.PUBLIC // Privacy is mandatory for server
42 }
43
44 function checkVideo (video: VideoDetails) {
45 expect(video.downloadEnabled).to.be.false
46 expect(video.commentsEnabled).to.be.false
47 expect(video.licence.id).to.equal(4)
48 }
49
50 before(async function () {
51 await server.config.disableTranscoding()
52 await server.config.enableImports()
53 await server.config.enableLive({ allowReplay: false, transcoding: false })
54 })
55
56 it('Should have the correct server configuration', async function () {
57 const config = await server.config.getConfig()
58
59 expect(config.defaults.publish.commentsEnabled).to.be.false
60 expect(config.defaults.publish.downloadEnabled).to.be.false
61 expect(config.defaults.publish.licence).to.equal(4)
62 expect(config.defaults.publish.privacy).to.equal(VideoPrivacy.INTERNAL)
63 })
64
65 it('Should respect default values when uploading a video', async function () {
66 for (const mode of [ 'legacy' as 'legacy', 'resumable' as 'resumable' ]) {
67 const { id } = await server.videos.upload({ attributes, mode })
68
69 const video = await server.videos.get({ id })
70 checkVideo(video)
71 }
72 })
73
74 it('Should respect default values when importing a video using URL', async function () {
75 const { video: { id } } = await server.imports.importVideo({
76 attributes: {
77 ...attributes,
78 channelId,
79 targetUrl: FIXTURE_URLS.goodVideo
80 }
81 })
82
83 const video = await server.videos.get({ id })
84 checkVideo(video)
85 })
86
87 it('Should respect default values when importing a video using magnet URI', async function () {
88 const { video: { id } } = await server.imports.importVideo({
89 attributes: {
90 ...attributes,
91 channelId,
92 magnetUri: FIXTURE_URLS.magnet
93 }
94 })
95
96 const video = await server.videos.get({ id })
97 checkVideo(video)
98 })
99
100 it('Should respect default values when creating a live', async function () {
101 const { id } = await server.live.create({
102 fields: {
103 ...attributes,
104 channelId
105 }
106 })
107
108 const video = await server.videos.get({ id })
109 checkVideo(video)
110 })
111 })
112
113 after(async function () {
114 await cleanupTests([ server ])
115 })
116})
diff --git a/server/tests/api/server/index.ts b/server/tests/api/server/index.ts
index 8136fc3c6..45be107ce 100644
--- a/server/tests/api/server/index.ts
+++ b/server/tests/api/server/index.ts
@@ -1,4 +1,6 @@
1import './auto-follows' 1import './auto-follows'
2import './bulk'
3import './config-defaults'
2import './config' 4import './config'
3import './contact-form' 5import './contact-form'
4import './email' 6import './email'