aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.html11
-rw-r--r--client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts5
-rw-r--r--config/default.yaml4
-rw-r--r--config/production.yaml.example6
-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
-rw-r--r--shared/models/server/custom-config.model.ts6
-rw-r--r--shared/server-commands/server/config-command.ts5
-rw-r--r--shared/server-commands/users/users-command.ts4
-rw-r--r--support/doc/api/openapi.yaml2
18 files changed, 145 insertions, 18 deletions
diff --git a/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.html b/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.html
index 8399b5d56..9fc332308 100644
--- a/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.html
+++ b/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.html
@@ -246,6 +246,17 @@
246 246
247 <div *ngIf="formErrors.user.videoQuotaDaily" class="form-error">{{ formErrors.user.videoQuotaDaily }}</div> 247 <div *ngIf="formErrors.user.videoQuotaDaily" class="form-error">{{ formErrors.user.videoQuotaDaily }}</div>
248 </div> 248 </div>
249 <div class="form-group">
250 <ng-container formGroupName="history">
251 <ng-container formGroupName="videos">
252 <my-peertube-checkbox
253 inputName="videosHistoryEnabled" formControlName="enabled"
254 i18n-labelText labelText="Automatically enable video history for new users"
255 >
256 </my-peertube-checkbox>
257 </ng-container>
258 </ng-container>
259 </div>
249 </ng-container> 260 </ng-container>
250 261
251 </div> 262 </div>
diff --git a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts
index 2afe80a03..0526ed8f1 100644
--- a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts
+++ b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts
@@ -165,6 +165,11 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
165 enabled: null 165 enabled: null
166 }, 166 },
167 user: { 167 user: {
168 history: {
169 videos: {
170 enabled: null
171 }
172 },
168 videoQuota: USER_VIDEO_QUOTA_VALIDATOR, 173 videoQuota: USER_VIDEO_QUOTA_VALIDATOR,
169 videoQuotaDaily: USER_VIDEO_QUOTA_DAILY_VALIDATOR 174 videoQuotaDaily: USER_VIDEO_QUOTA_DAILY_VALIDATOR
170 }, 175 },
diff --git a/config/default.yaml b/config/default.yaml
index db014cc87..dfa43a0aa 100644
--- a/config/default.yaml
+++ b/config/default.yaml
@@ -408,6 +408,10 @@ signup:
408 blacklist: [] 408 blacklist: []
409 409
410user: 410user:
411 history:
412 videos:
413 # Enable or disable video history by default for new users.
414 enabled: true
411 # Default value of maximum video bytes the user can upload (does not take into account transcoded files) 415 # Default value of maximum video bytes the user can upload (does not take into account transcoded files)
412 # Byte format is supported ("1GB" etc) 416 # Byte format is supported ("1GB" etc)
413 # -1 == unlimited 417 # -1 == unlimited
diff --git a/config/production.yaml.example b/config/production.yaml.example
index 9cb8add1f..744a14e91 100644
--- a/config/production.yaml.example
+++ b/config/production.yaml.example
@@ -417,7 +417,11 @@ signup:
417 whitelist: [] 417 whitelist: []
418 blacklist: [] 418 blacklist: []
419 419
420user: 420user:
421 history:
422 videos:
423 # Enable or disable video history by default for new users.
424 enabled: true
421 # Default value of maximum video bytes the user can upload (does not take into account transcoded files) 425 # Default value of maximum video bytes the user can upload (does not take into account transcoded files)
422 # Byte format is supported ("1GB" etc) 426 # Byte format is supported ("1GB" etc)
423 # -1 == unlimited 427 # -1 == unlimited
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 },
diff --git a/shared/models/server/custom-config.model.ts b/shared/models/server/custom-config.model.ts
index 846bf6159..6ffe3a676 100644
--- a/shared/models/server/custom-config.model.ts
+++ b/shared/models/server/custom-config.model.ts
@@ -97,6 +97,11 @@ export interface CustomConfig {
97 } 97 }
98 98
99 user: { 99 user: {
100 history: {
101 videos: {
102 enabled: boolean
103 }
104 }
100 videoQuota: number 105 videoQuota: number
101 videoQuotaDaily: number 106 videoQuotaDaily: number
102 } 107 }
@@ -229,4 +234,5 @@ export interface CustomConfig {
229 isDefaultSearch: boolean 234 isDefaultSearch: boolean
230 } 235 }
231 } 236 }
237
232} 238}
diff --git a/shared/server-commands/server/config-command.ts b/shared/server-commands/server/config-command.ts
index eb6bb95a5..303fcab88 100644
--- a/shared/server-commands/server/config-command.ts
+++ b/shared/server-commands/server/config-command.ts
@@ -350,6 +350,11 @@ export class ConfigCommand extends AbstractCommand {
350 enabled: true 350 enabled: true
351 }, 351 },
352 user: { 352 user: {
353 history: {
354 videos: {
355 enabled: true
356 }
357 },
353 videoQuota: 5242881, 358 videoQuota: 5242881,
354 videoQuotaDaily: 318742 359 videoQuotaDaily: 318742
355 }, 360 },
diff --git a/shared/server-commands/users/users-command.ts b/shared/server-commands/users/users-command.ts
index 8a42fafc8..5b39d3488 100644
--- a/shared/server-commands/users/users-command.ts
+++ b/shared/server-commands/users/users-command.ts
@@ -165,8 +165,8 @@ export class UsersCommand extends AbstractCommand {
165 username, 165 username,
166 adminFlags, 166 adminFlags,
167 password = 'password', 167 password = 'password',
168 videoQuota = 42000000, 168 videoQuota,
169 videoQuotaDaily = -1, 169 videoQuotaDaily,
170 role = UserRole.USER 170 role = UserRole.USER
171 } = options 171 } = options
172 172
diff --git a/support/doc/api/openapi.yaml b/support/doc/api/openapi.yaml
index 959a70438..046eec544 100644
--- a/support/doc/api/openapi.yaml
+++ b/support/doc/api/openapi.yaml
@@ -7894,8 +7894,6 @@ components:
7894 - username 7894 - username
7895 - password 7895 - password
7896 - email 7896 - email
7897 - videoQuota
7898 - videoQuotaDaily
7899 - role 7897 - role
7900 UpdateUser: 7898 UpdateUser:
7901 properties: 7899 properties: