aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorPoslovitch <poslovitch@bentobox.world>2021-04-24 09:57:01 +0000
committerChocobozzz <me@florianbigard.com>2021-05-28 13:56:05 +0200
commit1f256e7d3cf056c2d999260155cdba58ae1b878b (patch)
treee33db698da50c329e1eea4122e190e6ef247d8e4 /server
parentf22e0e2c19b06edfc85429198f9e54a075f71ad3 (diff)
downloadPeerTube-1f256e7d3cf056c2d999260155cdba58ae1b878b.tar.gz
PeerTube-1f256e7d3cf056c2d999260155cdba58ae1b878b.tar.zst
PeerTube-1f256e7d3cf056c2d999260155cdba58ae1b878b.zip
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 <chocobozzz@cpy.re> Add tests for min signup age config
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/config.ts3
-rw-r--r--server/initializers/checker-before-init.ts2
-rw-r--r--server/initializers/config.ts1
-rw-r--r--server/lib/server-config-manager.ts1
-rw-r--r--server/middlewares/validators/config.ts1
-rw-r--r--server/tests/api/check-params/config.ts3
-rw-r--r--server/tests/api/server/config.ts5
7 files changed, 12 insertions, 4 deletions
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 {
174 signup: { 174 signup: {
175 enabled: CONFIG.SIGNUP.ENABLED, 175 enabled: CONFIG.SIGNUP.ENABLED,
176 limit: CONFIG.SIGNUP.LIMIT, 176 limit: CONFIG.SIGNUP.LIMIT,
177 requiresEmailVerification: CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION 177 requiresEmailVerification: CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION,
178 minimumAge: CONFIG.SIGNUP.MINIMUM_AGE
178 }, 179 },
179 admin: { 180 admin: {
180 email: CONFIG.ADMIN.EMAIL 181 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 () {
19 'csp.enabled', 'csp.report_only', 'csp.report_uri', 19 'csp.enabled', 'csp.report_only', 'csp.report_uri',
20 'security.frameguard.enabled', 20 'security.frameguard.enabled',
21 'cache.previews.size', 'cache.captions.size', 'cache.torrents.size', 'admin.email', 'contact_form.enabled', 21 'cache.previews.size', 'cache.captions.size', 'cache.torrents.size', 'admin.email', 'contact_form.enabled',
22 'signup.enabled', 'signup.limit', 'signup.requires_email_verification', 22 'signup.enabled', 'signup.limit', 'signup.requires_email_verification', 'signup.minimum_age',
23 'signup.filters.cidr.whitelist', 'signup.filters.cidr.blacklist', 23 'signup.filters.cidr.whitelist', 'signup.filters.cidr.blacklist',
24 'redundancy.videos.strategies', 'redundancy.videos.check_interval', 24 'redundancy.videos.strategies', 'redundancy.videos.check_interval',
25 'transcoding.enabled', 'transcoding.threads', 'transcoding.allow_additional_extensions', 'transcoding.hls.enabled', 25 '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 = {
185 get ENABLED () { return config.get<boolean>('signup.enabled') }, 185 get ENABLED () { return config.get<boolean>('signup.enabled') },
186 get LIMIT () { return config.get<number>('signup.limit') }, 186 get LIMIT () { return config.get<number>('signup.limit') },
187 get REQUIRES_EMAIL_VERIFICATION () { return config.get<boolean>('signup.requires_email_verification') }, 187 get REQUIRES_EMAIL_VERIFICATION () { return config.get<boolean>('signup.requires_email_verification') },
188 get MINIMUM_AGE () { return config.get<number>('signup.minimum_age') },
188 FILTERS: { 189 FILTERS: {
189 CIDR: { 190 CIDR: {
190 get WHITELIST () { return config.get<string[]>('signup.filters.cidr.whitelist') }, 191 get WHITELIST () { return config.get<string[]>('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 {
216 const signup = { 216 const signup = {
217 allowed, 217 allowed,
218 allowedForCurrentIP, 218 allowedForCurrentIP,
219 minimumAge: CONFIG.SIGNUP.MINIMUM_AGE,
219 requiresEmailVerification: CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION 220 requiresEmailVerification: CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION
220 } 221 }
221 222
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 = [
30 body('signup.enabled').isBoolean().withMessage('Should have a valid signup enabled boolean'), 30 body('signup.enabled').isBoolean().withMessage('Should have a valid signup enabled boolean'),
31 body('signup.limit').isInt().withMessage('Should have a valid signup limit'), 31 body('signup.limit').isInt().withMessage('Should have a valid signup limit'),
32 body('signup.requiresEmailVerification').isBoolean().withMessage('Should have a valid requiresEmailVerification boolean'), 32 body('signup.requiresEmailVerification').isBoolean().withMessage('Should have a valid requiresEmailVerification boolean'),
33 body('signup.minimumAge').isInt().withMessage("Should have a valid minimum age required"),
33 34
34 body('admin.email').isEmail().withMessage('Should have a valid administrator email'), 35 body('admin.email').isEmail().withMessage('Should have a valid administrator email'),
35 body('contactForm.enabled').isBoolean().withMessage('Should have a valid contact form enabled boolean'), 36 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 () {
73 signup: { 73 signup: {
74 enabled: false, 74 enabled: false,
75 limit: 5, 75 limit: 5,
76 requiresEmailVerification: false 76 requiresEmailVerification: false,
77 minimumAge: 16
77 }, 78 },
78 admin: { 79 admin: {
79 email: 'superadmin1@example.com' 80 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) {
60 60
61 expect(data.signup.enabled).to.be.true 61 expect(data.signup.enabled).to.be.true
62 expect(data.signup.limit).to.equal(4) 62 expect(data.signup.limit).to.equal(4)
63 expect(data.signup.minimumAge).to.equal(16)
63 expect(data.signup.requiresEmailVerification).to.be.false 64 expect(data.signup.requiresEmailVerification).to.be.false
64 65
65 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com') 66 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
@@ -151,6 +152,7 @@ function checkUpdatedConfig (data: CustomConfig) {
151 expect(data.signup.enabled).to.be.false 152 expect(data.signup.enabled).to.be.false
152 expect(data.signup.limit).to.equal(5) 153 expect(data.signup.limit).to.equal(5)
153 expect(data.signup.requiresEmailVerification).to.be.false 154 expect(data.signup.requiresEmailVerification).to.be.false
155 expect(data.signup.minimumAge).to.equal(10)
154 156
155 // We override admin email in parallel tests, so skip this exception 157 // We override admin email in parallel tests, so skip this exception
156 if (parallelTests() === false) { 158 if (parallelTests() === false) {
@@ -316,7 +318,8 @@ describe('Test config', function () {
316 signup: { 318 signup: {
317 enabled: false, 319 enabled: false,
318 limit: 5, 320 limit: 5,
319 requiresEmailVerification: false 321 requiresEmailVerification: false,
322 minimumAge: 10
320 }, 323 },
321 admin: { 324 admin: {
322 email: 'superadmin1@example.com' 325 email: 'superadmin1@example.com'