aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/config.ts5
-rw-r--r--server/initializers/checker-before-init.ts2
-rw-r--r--server/initializers/config.ts5
-rw-r--r--server/lib/user.ts2
-rw-r--r--server/middlewares/validators/config.ts1
-rw-r--r--server/middlewares/validators/users.ts3
-rw-r--r--server/tests/api/check-params/config.ts5
-rw-r--r--server/tests/api/check-params/users-admin.ts12
-rw-r--r--server/tests/api/server/config-defaults.ts78
-rw-r--r--server/tests/api/server/config.ts7
10 files changed, 107 insertions, 13 deletions
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts
index 86434f382..60d168d12 100644
--- a/server/controllers/api/config.ts
+++ b/server/controllers/api/config.ts
@@ -204,6 +204,11 @@ function customConfig (): CustomConfig {
204 enabled: CONFIG.CONTACT_FORM.ENABLED 204 enabled: CONFIG.CONTACT_FORM.ENABLED
205 }, 205 },
206 user: { 206 user: {
207 history: {
208 videos: {
209 enabled: CONFIG.USER.HISTORY.VIDEOS.ENABLED
210 }
211 },
207 videoQuota: CONFIG.USER.VIDEO_QUOTA, 212 videoQuota: CONFIG.USER.VIDEO_QUOTA,
208 videoQuotaDaily: CONFIG.USER.VIDEO_QUOTA_DAILY 213 videoQuotaDaily: CONFIG.USER.VIDEO_QUOTA_DAILY
209 }, 214 },
diff --git a/server/initializers/checker-before-init.ts b/server/initializers/checker-before-init.ts
index 1351749a6..49010c059 100644
--- a/server/initializers/checker-before-init.ts
+++ b/server/initializers/checker-before-init.ts
@@ -24,7 +24,7 @@ function checkMissedConfig () {
24 'open_telemetry.metrics.enabled', 'open_telemetry.metrics.prometheus_exporter.hostname', 24 'open_telemetry.metrics.enabled', 'open_telemetry.metrics.prometheus_exporter.hostname',
25 'open_telemetry.metrics.prometheus_exporter.port', 'open_telemetry.tracing.enabled', 'open_telemetry.tracing.jaeger_exporter.endpoint', 25 'open_telemetry.metrics.prometheus_exporter.port', 'open_telemetry.tracing.enabled', 'open_telemetry.tracing.jaeger_exporter.endpoint',
26 'open_telemetry.metrics.http_request_duration.enabled', 26 'open_telemetry.metrics.http_request_duration.enabled',
27 'user.video_quota', 'user.video_quota_daily', 27 'user.history.videos.enabled', 'user.video_quota', 'user.video_quota_daily',
28 'video_channels.max_per_user', 28 'video_channels.max_per_user',
29 'csp.enabled', 'csp.report_only', 'csp.report_uri', 29 'csp.enabled', 'csp.report_only', 'csp.report_uri',
30 'security.frameguard.enabled', 'security.powered_by_header.enabled', 30 'security.frameguard.enabled', 'security.powered_by_header.enabled',
diff --git a/server/initializers/config.ts b/server/initializers/config.ts
index eb9d0079c..e2442213c 100644
--- a/server/initializers/config.ts
+++ b/server/initializers/config.ts
@@ -324,6 +324,11 @@ const CONFIG = {
324 } 324 }
325 }, 325 },
326 USER: { 326 USER: {
327 HISTORY: {
328 VIDEOS: {
329 get ENABLED () { return config.get<boolean>('user.history.videos.enabled') }
330 }
331 },
327 get VIDEO_QUOTA () { return parseBytes(config.get<number>('user.video_quota')) }, 332 get VIDEO_QUOTA () { return parseBytes(config.get<number>('user.video_quota')) },
328 get VIDEO_QUOTA_DAILY () { return parseBytes(config.get<number>('user.video_quota_daily')) } 333 get VIDEO_QUOTA_DAILY () { return parseBytes(config.get<number>('user.video_quota_daily')) }
329 }, 334 },
diff --git a/server/lib/user.ts b/server/lib/user.ts
index ffb57944a..56995cca3 100644
--- a/server/lib/user.ts
+++ b/server/lib/user.ts
@@ -56,6 +56,8 @@ function buildUser (options: {
56 56
57 nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, 57 nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY,
58 p2pEnabled: CONFIG.DEFAULTS.P2P.WEBAPP.ENABLED, 58 p2pEnabled: CONFIG.DEFAULTS.P2P.WEBAPP.ENABLED,
59 videosHistoryEnabled: CONFIG.USER.HISTORY.VIDEOS.ENABLED,
60
59 autoPlayVideo: true, 61 autoPlayVideo: true,
60 62
61 role, 63 role,
diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts
index c2dbfadb7..4a9d1cb54 100644
--- a/server/middlewares/validators/config.ts
+++ b/server/middlewares/validators/config.ts
@@ -35,6 +35,7 @@ const customConfigUpdateValidator = [
35 body('admin.email').isEmail(), 35 body('admin.email').isEmail(),
36 body('contactForm.enabled').isBoolean(), 36 body('contactForm.enabled').isBoolean(),
37 37
38 body('user.history.videos.enabled').isBoolean(),
38 body('user.videoQuota').custom(isUserVideoQuotaValid), 39 body('user.videoQuota').custom(isUserVideoQuotaValid),
39 body('user.videoQuotaDaily').custom(isUserVideoQuotaDailyValid), 40 body('user.videoQuotaDaily').custom(isUserVideoQuotaDailyValid),
40 41
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts
index f7033f44a..7ebea048d 100644
--- a/server/middlewares/validators/users.ts
+++ b/server/middlewares/validators/users.ts
@@ -65,8 +65,11 @@ const usersAddValidator = [
65 .custom(isVideoChannelUsernameValid), 65 .custom(isVideoChannelUsernameValid),
66 66
67 body('videoQuota') 67 body('videoQuota')
68 .optional()
68 .custom(isUserVideoQuotaValid), 69 .custom(isUserVideoQuotaValid),
70
69 body('videoQuotaDaily') 71 body('videoQuotaDaily')
72 .optional()
70 .custom(isUserVideoQuotaDailyValid), 73 .custom(isUserVideoQuotaDailyValid),
71 74
72 body('role') 75 body('role')
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
index 93a3f3eb9..f49a4b868 100644
--- a/server/tests/api/check-params/config.ts
+++ b/server/tests/api/check-params/config.ts
@@ -90,6 +90,11 @@ describe('Test config API validators', function () {
90 enabled: false 90 enabled: false
91 }, 91 },
92 user: { 92 user: {
93 history: {
94 videos: {
95 enabled: true
96 }
97 },
93 videoQuota: 5242881, 98 videoQuota: 5242881,
94 videoQuotaDaily: 318742 99 videoQuotaDaily: 318742
95 }, 100 },
diff --git a/server/tests/api/check-params/users-admin.ts b/server/tests/api/check-params/users-admin.ts
index be2496bb4..819da0bb2 100644
--- a/server/tests/api/check-params/users-admin.ts
+++ b/server/tests/api/check-params/users-admin.ts
@@ -216,18 +216,6 @@ describe('Test users admin API validators', function () {
216 }) 216 })
217 }) 217 })
218 218
219 it('Should fail without a videoQuota', async function () {
220 const fields = omit(baseCorrectParams, [ 'videoQuota' ])
221
222 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
223 })
224
225 it('Should fail without a videoQuotaDaily', async function () {
226 const fields = omit(baseCorrectParams, [ 'videoQuotaDaily' ])
227
228 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
229 })
230
231 it('Should fail with an invalid videoQuota', async function () { 219 it('Should fail with an invalid videoQuota', async function () {
232 const fields = { ...baseCorrectParams, videoQuota: -5 } 220 const fields = { ...baseCorrectParams, videoQuota: -5 }
233 221
diff --git a/server/tests/api/server/config-defaults.ts b/server/tests/api/server/config-defaults.ts
index d3b3a2447..041032f2b 100644
--- a/server/tests/api/server/config-defaults.ts
+++ b/server/tests/api/server/config-defaults.ts
@@ -204,6 +204,84 @@ describe('Test config defaults', function () {
204 }) 204 })
205 }) 205 })
206 206
207 describe('Default user attributes', function () {
208 it('Should create a user and register a user with the default config', async function () {
209 await server.config.updateCustomSubConfig({
210 newConfig: {
211 user: {
212 history: {
213 videos: {
214 enabled: true
215 }
216 },
217 videoQuota : -1,
218 videoQuotaDaily: -1
219 },
220 signup: {
221 enabled: true,
222 requiresApproval: false
223 }
224 }
225 })
226
227 const config = await server.config.getConfig()
228
229 expect(config.user.videoQuota).to.equal(-1)
230 expect(config.user.videoQuotaDaily).to.equal(-1)
231
232 const user1Token = await server.users.generateUserAndToken('user1')
233 const user1 = await server.users.getMyInfo({ token: user1Token })
234
235 const user = { displayName: 'super user 2', username: 'user2', password: 'super password' }
236 const channel = { name: 'my_user_2_channel', displayName: 'my channel' }
237 await server.registrations.register({ ...user, channel })
238 const user2Token = await server.login.getAccessToken(user)
239 const user2 = await server.users.getMyInfo({ token: user2Token })
240
241 for (const user of [ user1, user2 ]) {
242 expect(user.videosHistoryEnabled).to.be.true
243 expect(user.videoQuota).to.equal(-1)
244 expect(user.videoQuotaDaily).to.equal(-1)
245 }
246 })
247
248 it('Should update config and create a user and register a user with the new default config', async function () {
249 await server.config.updateCustomSubConfig({
250 newConfig: {
251 user: {
252 history: {
253 videos: {
254 enabled: false
255 }
256 },
257 videoQuota : 5242881,
258 videoQuotaDaily: 318742
259 },
260 signup: {
261 enabled: true,
262 requiresApproval: false
263 }
264 }
265 })
266
267 const user3Token = await server.users.generateUserAndToken('user3')
268 const user3 = await server.users.getMyInfo({ token: user3Token })
269
270 const user = { displayName: 'super user 4', username: 'user4', password: 'super password' }
271 const channel = { name: 'my_user_4_channel', displayName: 'my channel' }
272 await server.registrations.register({ ...user, channel })
273 const user4Token = await server.login.getAccessToken(user)
274 const user4 = await server.users.getMyInfo({ token: user4Token })
275
276 for (const user of [ user3, user4 ]) {
277 expect(user.videosHistoryEnabled).to.be.false
278 expect(user.videoQuota).to.equal(5242881)
279 expect(user.videoQuotaDaily).to.equal(318742)
280 }
281 })
282
283 })
284
207 after(async function () { 285 after(async function () {
208 await cleanupTests([ server ]) 286 await cleanupTests([ server ])
209 }) 287 })
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts
index de7c2f6e2..3683c4ae1 100644
--- a/server/tests/api/server/config.ts
+++ b/server/tests/api/server/config.ts
@@ -56,6 +56,7 @@ function checkInitialConfig (server: PeerTubeServer, data: CustomConfig) {
56 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com') 56 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
57 expect(data.contactForm.enabled).to.be.true 57 expect(data.contactForm.enabled).to.be.true
58 58
59 expect(data.user.history.videos.enabled).to.be.true
59 expect(data.user.videoQuota).to.equal(5242880) 60 expect(data.user.videoQuota).to.equal(5242880)
60 expect(data.user.videoQuotaDaily).to.equal(-1) 61 expect(data.user.videoQuotaDaily).to.equal(-1)
61 62
@@ -164,6 +165,7 @@ function checkUpdatedConfig (data: CustomConfig) {
164 165
165 expect(data.contactForm.enabled).to.be.false 166 expect(data.contactForm.enabled).to.be.false
166 167
168 expect(data.user.history.videos.enabled).to.be.false
167 expect(data.user.videoQuota).to.equal(5242881) 169 expect(data.user.videoQuota).to.equal(5242881)
168 expect(data.user.videoQuotaDaily).to.equal(318742) 170 expect(data.user.videoQuotaDaily).to.equal(318742)
169 171
@@ -298,6 +300,11 @@ const newCustomConfig: CustomConfig = {
298 enabled: false 300 enabled: false
299 }, 301 },
300 user: { 302 user: {
303 history: {
304 videos: {
305 enabled: false
306 }
307 },
301 videoQuota: 5242881, 308 videoQuota: 5242881,
302 videoQuotaDaily: 318742 309 videoQuotaDaily: 318742
303 }, 310 },