From 1f256e7d3cf056c2d999260155cdba58ae1b878b Mon Sep 17 00:00:00 2001 From: Poslovitch Date: Sat, 24 Apr 2021 09:57:01 +0000 Subject: Implemented configurable minimum signup age Implements https://github.com/Chocobozzz/PeerTube/issues/3612 Fixed lint and removed debug Fixed another lint error Apply suggestions from code review Co-authored-by: Chocobozzz Add tests for min signup age config --- server/controllers/api/config.ts | 3 ++- server/initializers/checker-before-init.ts | 2 +- server/initializers/config.ts | 1 + server/lib/server-config-manager.ts | 1 + server/middlewares/validators/config.ts | 1 + server/tests/api/check-params/config.ts | 3 ++- server/tests/api/server/config.ts | 5 ++++- 7 files changed, 12 insertions(+), 4 deletions(-) (limited to 'server') diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index c9b5c8047..1f2a5f2da 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts @@ -174,7 +174,8 @@ function customConfig (): CustomConfig { signup: { enabled: CONFIG.SIGNUP.ENABLED, limit: CONFIG.SIGNUP.LIMIT, - requiresEmailVerification: CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION + requiresEmailVerification: CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION, + minimumAge: CONFIG.SIGNUP.MINIMUM_AGE }, admin: { email: CONFIG.ADMIN.EMAIL diff --git a/server/initializers/checker-before-init.ts b/server/initializers/checker-before-init.ts index 2864b0287..93c019121 100644 --- a/server/initializers/checker-before-init.ts +++ b/server/initializers/checker-before-init.ts @@ -19,7 +19,7 @@ function checkMissedConfig () { 'csp.enabled', 'csp.report_only', 'csp.report_uri', 'security.frameguard.enabled', 'cache.previews.size', 'cache.captions.size', 'cache.torrents.size', 'admin.email', 'contact_form.enabled', - 'signup.enabled', 'signup.limit', 'signup.requires_email_verification', + 'signup.enabled', 'signup.limit', 'signup.requires_email_verification', 'signup.minimum_age', 'signup.filters.cidr.whitelist', 'signup.filters.cidr.blacklist', 'redundancy.videos.strategies', 'redundancy.videos.check_interval', 'transcoding.enabled', 'transcoding.threads', 'transcoding.allow_additional_extensions', 'transcoding.hls.enabled', diff --git a/server/initializers/config.ts b/server/initializers/config.ts index 5281d3a66..30a9823b9 100644 --- a/server/initializers/config.ts +++ b/server/initializers/config.ts @@ -185,6 +185,7 @@ const CONFIG = { get ENABLED () { return config.get('signup.enabled') }, get LIMIT () { return config.get('signup.limit') }, get REQUIRES_EMAIL_VERIFICATION () { return config.get('signup.requires_email_verification') }, + get MINIMUM_AGE () { return config.get('signup.minimum_age') }, FILTERS: { CIDR: { get WHITELIST () { return config.get('signup.filters.cidr.whitelist') }, diff --git a/server/lib/server-config-manager.ts b/server/lib/server-config-manager.ts index 1aff6f446..25a770c6b 100644 --- a/server/lib/server-config-manager.ts +++ b/server/lib/server-config-manager.ts @@ -216,6 +216,7 @@ class ServerConfigManager { const signup = { allowed, allowedForCurrentIP, + minimumAge: CONFIG.SIGNUP.MINIMUM_AGE, requiresEmailVerification: CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION } diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts index a85883b19..e3e0c2058 100644 --- a/server/middlewares/validators/config.ts +++ b/server/middlewares/validators/config.ts @@ -30,6 +30,7 @@ const customConfigUpdateValidator = [ body('signup.enabled').isBoolean().withMessage('Should have a valid signup enabled boolean'), body('signup.limit').isInt().withMessage('Should have a valid signup limit'), body('signup.requiresEmailVerification').isBoolean().withMessage('Should have a valid requiresEmailVerification boolean'), + body('signup.minimumAge').isInt().withMessage("Should have a valid minimum age required"), body('admin.email').isEmail().withMessage('Should have a valid administrator email'), body('contactForm.enabled').isBoolean().withMessage('Should have a valid contact form enabled boolean'), diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts index 004aa65b3..9549070ef 100644 --- a/server/tests/api/check-params/config.ts +++ b/server/tests/api/check-params/config.ts @@ -73,7 +73,8 @@ describe('Test config API validators', function () { signup: { enabled: false, limit: 5, - requiresEmailVerification: false + requiresEmailVerification: false, + minimumAge: 16 }, admin: { email: 'superadmin1@example.com' diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index 1d9ea31df..19bf9582c 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts @@ -60,6 +60,7 @@ function checkInitialConfig (server: ServerInfo, data: CustomConfig) { expect(data.signup.enabled).to.be.true expect(data.signup.limit).to.equal(4) + expect(data.signup.minimumAge).to.equal(16) expect(data.signup.requiresEmailVerification).to.be.false expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com') @@ -151,6 +152,7 @@ function checkUpdatedConfig (data: CustomConfig) { expect(data.signup.enabled).to.be.false expect(data.signup.limit).to.equal(5) expect(data.signup.requiresEmailVerification).to.be.false + expect(data.signup.minimumAge).to.equal(10) // We override admin email in parallel tests, so skip this exception if (parallelTests() === false) { @@ -316,7 +318,8 @@ describe('Test config', function () { signup: { enabled: false, limit: 5, - requiresEmailVerification: false + requiresEmailVerification: false, + minimumAge: 10 }, admin: { email: 'superadmin1@example.com' -- cgit v1.2.3