aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-10-14 11:35:43 +0200
committerChocobozzz <me@florianbigard.com>2021-10-14 11:35:43 +0200
commitcf0c8ee588e37809d85ec1deec1e4fdfa0f122a5 (patch)
tree1692868027592d2a300988643fdd96e5fdfe2091
parente1a570abff3ebf375433e58e7362d56bd32d4cd8 (diff)
downloadPeerTube-cf0c8ee588e37809d85ec1deec1e4fdfa0f122a5.tar.gz
PeerTube-cf0c8ee588e37809d85ec1deec1e4fdfa0f122a5.tar.zst
PeerTube-cf0c8ee588e37809d85ec1deec1e4fdfa0f122a5.zip
Fix admin edition disabling feature
-rw-r--r--client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.html14
-rw-r--r--client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts7
-rw-r--r--client/src/app/shared/shared-forms/markdown-textarea.component.html2
-rw-r--r--config/default.yaml2
-rw-r--r--config/production.yaml.example2
-rw-r--r--scripts/benchmark.ts2
-rw-r--r--server/initializers/config.ts6
-rw-r--r--server/lib/server-config-manager.ts10
-rw-r--r--server/middlewares/validators/config.ts3
-rw-r--r--server/tests/api/server/auto-follows.ts4
-rw-r--r--server/tests/api/server/config.ts4
-rw-r--r--shared/extra-utils/mock-servers/mock-instances-index.ts10
-rw-r--r--shared/models/server/server-config.model.ts9
-rw-r--r--support/docker/production/config/custom-environment-variables.yaml6
14 files changed, 61 insertions, 20 deletions
diff --git a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.html b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.html
index 6ae7b1b79..8fef39b79 100644
--- a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.html
+++ b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.html
@@ -1,4 +1,9 @@
1<h1 class="sr-only" i18n>Configuration</h1> 1<h1 class="sr-only" i18n>Configuration</h1>
2
3<div class="alert alert-warning" *ngIf="!isUpdateAllowed()" i18n>
4 Updating instance configuration from the web interface is disabled by the system administrator.
5</div>
6
2<form role="form" [formGroup]="form"> 7<form role="form" [formGroup]="form">
3 8
4 <div ngbNav #nav="ngbNav" [activeId]="activeNav" (activeIdChange)="onNavChange($event)" class="nav-tabs"> 9 <div ngbNav #nav="ngbNav" [activeId]="activeNav" (activeIdChange)="onNavChange($event)" class="nav-tabs">
@@ -63,7 +68,7 @@
63 <div class="col-md-7 col-xl-5"></div> 68 <div class="col-md-7 col-xl-5"></div>
64 <div class="col-md-5 col-xl-5"> 69 <div class="col-md-5 col-xl-5">
65 70
66 <div class="form-error submit-error" i18n *ngIf="!form.valid && serverConfig.allowEdits"> 71 <div class="form-error submit-error" i18n *ngIf="!form.valid && isUpdateAllowed()">
67 There are errors in the form: 72 There are errors in the form:
68 73
69 <ul> 74 <ul>
@@ -77,11 +82,14 @@
77 You cannot allow live replay if you don't enable transcoding. 82 You cannot allow live replay if you don't enable transcoding.
78 </span> 83 </span>
79 84
80 <span i18n *ngIf="!serverConfig.allowEdits"> 85 <span i18n *ngIf="!isUpdateAllowed()">
81 You cannot change the server configuration because it's managed externally. 86 You cannot change the server configuration because it's managed externally.
82 </span> 87 </span>
83 88
84 <input (click)="formValidated()" type="submit" i18n-value value="Update configuration" [disabled]="!form.valid || !hasConsistentOptions() || !serverConfig.allowEdits"> 89 <input
90 (click)="formValidated()" type="submit" i18n-value value="Update configuration"
91 [disabled]="!form.valid || !hasConsistentOptions() || !isUpdateAllowed()"
92 >
85 </div> 93 </div>
86 </div> 94 </div>
87</form> 95</form>
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 04b0175a7..96c67fac7 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
@@ -258,7 +258,8 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
258 258
259 this.loadConfigAndUpdateForm() 259 this.loadConfigAndUpdateForm()
260 this.loadCategoriesAndLanguages() 260 this.loadCategoriesAndLanguages()
261 if (!this.serverConfig.allowEdits) { 261
262 if (!this.isUpdateAllowed()) {
262 this.form.disable() 263 this.form.disable()
263 } 264 }
264 } 265 }
@@ -293,6 +294,10 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
293 }) 294 })
294 } 295 }
295 296
297 isUpdateAllowed () {
298 return this.serverConfig.webadmin.configuration.edition.allowed === true
299 }
300
296 hasConsistentOptions () { 301 hasConsistentOptions () {
297 if (this.hasLiveAllowReplayConsistentOptions()) return true 302 if (this.hasLiveAllowReplayConsistentOptions()) return true
298 303
diff --git a/client/src/app/shared/shared-forms/markdown-textarea.component.html b/client/src/app/shared/shared-forms/markdown-textarea.component.html
index a460cb9b7..7c2a42791 100644
--- a/client/src/app/shared/shared-forms/markdown-textarea.component.html
+++ b/client/src/app/shared/shared-forms/markdown-textarea.component.html
@@ -2,7 +2,7 @@
2 <textarea #textarea 2 <textarea #textarea
3 [(ngModel)]="content" (ngModelChange)="onModelChange()" 3 [(ngModel)]="content" (ngModelChange)="onModelChange()"
4 class="form-control" [ngClass]="classes" 4 class="form-control" [ngClass]="classes"
5 [attr.disabled]="disabled" 5 [attr.disabled]="disabled || null"
6 [ngStyle]="{ height: textareaHeight }" 6 [ngStyle]="{ height: textareaHeight }"
7 [id]="name" [name]="name"> 7 [id]="name" [name]="name">
8 </textarea> 8 </textarea>
diff --git a/config/default.yaml b/config/default.yaml
index 99f00a9ec..a8d070cc8 100644
--- a/config/default.yaml
+++ b/config/default.yaml
@@ -258,7 +258,7 @@ peertube:
258 258
259webadmin: 259webadmin:
260 configuration: 260 configuration:
261 edit: 261 edition:
262 # Set this to false if you don't want to allow config edition in the web interface by instance admins 262 # Set this to false if you don't want to allow config edition in the web interface by instance admins
263 allowed: true 263 allowed: true
264 264
diff --git a/config/production.yaml.example b/config/production.yaml.example
index c3cda52b5..bc9f28e95 100644
--- a/config/production.yaml.example
+++ b/config/production.yaml.example
@@ -256,7 +256,7 @@ peertube:
256 256
257webadmin: 257webadmin:
258 configuration: 258 configuration:
259 edit: 259 edition:
260 # Set this to false if you don't want to allow config edition in the web interface by instance admins 260 # Set this to false if you don't want to allow config edition in the web interface by instance admins
261 allowed: true 261 allowed: true
262 262
diff --git a/scripts/benchmark.ts b/scripts/benchmark.ts
index 007e3c33b..788318313 100644
--- a/scripts/benchmark.ts
+++ b/scripts/benchmark.ts
@@ -135,7 +135,7 @@ async function run () {
135 title: 'API - config', 135 title: 'API - config',
136 path: '/api/v1/config', 136 path: '/api/v1/config',
137 expecter: (body, status) => { 137 expecter: (body, status) => {
138 return status === 200 && body.startsWith('{"allowEdits":') 138 return status === 200 && body.startsWith('{"client":')
139 } 139 }
140 } 140 }
141 ] 141 ]
diff --git a/server/initializers/config.ts b/server/initializers/config.ts
index a37aae551..48bb5ab8e 100644
--- a/server/initializers/config.ts
+++ b/server/initializers/config.ts
@@ -206,8 +206,8 @@ const CONFIG = {
206 }, 206 },
207 WEBADMIN: { 207 WEBADMIN: {
208 CONFIGURATION: { 208 CONFIGURATION: {
209 EDITS: { 209 EDITION: {
210 ALLOWED: config.get<boolean>('webadmin.configuration.edit.allowed') 210 ALLOWED: config.get<boolean>('webadmin.configuration.edition.allowed')
211 } 211 }
212 } 212 }
213 }, 213 },
@@ -463,7 +463,7 @@ export function reloadConfig () {
463 463
464 function getConfigDirectories () { 464 function getConfigDirectories () {
465 if (process.env.NODE_CONFIG_DIR) { 465 if (process.env.NODE_CONFIG_DIR) {
466 return process.env.NODE_CONFIG_DIR.split(":") 466 return process.env.NODE_CONFIG_DIR.split(':')
467 } 467 }
468 468
469 return [ join(root(), 'config') ] 469 return [ join(root(), 'config') ]
diff --git a/server/lib/server-config-manager.ts b/server/lib/server-config-manager.ts
index 58a37b56c..b78251e8c 100644
--- a/server/lib/server-config-manager.ts
+++ b/server/lib/server-config-manager.ts
@@ -42,7 +42,6 @@ class ServerConfigManager {
42 const defaultTheme = getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME) 42 const defaultTheme = getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME)
43 43
44 return { 44 return {
45 allowEdits: CONFIG.WEBADMIN.CONFIGURATION.EDITS.ALLOWED,
46 client: { 45 client: {
47 videos: { 46 videos: {
48 miniature: { 47 miniature: {
@@ -50,6 +49,15 @@ class ServerConfigManager {
50 } 49 }
51 } 50 }
52 }, 51 },
52
53 webadmin: {
54 configuration: {
55 edition: {
56 allowed: CONFIG.WEBADMIN.CONFIGURATION.EDITION.ALLOWED
57 }
58 }
59 },
60
53 instance: { 61 instance: {
54 name: CONFIG.INSTANCE.NAME, 62 name: CONFIG.INSTANCE.NAME,
55 shortDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION, 63 shortDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION,
diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts
index 5f1ac89bc..f0385ab44 100644
--- a/server/middlewares/validators/config.ts
+++ b/server/middlewares/validators/config.ts
@@ -106,12 +106,13 @@ const customConfigUpdateValidator = [
106] 106]
107 107
108function ensureConfigIsEditable (req: express.Request, res: express.Response, next: express.NextFunction) { 108function ensureConfigIsEditable (req: express.Request, res: express.Response, next: express.NextFunction) {
109 if (!CONFIG.WEBADMIN.CONFIGURATION.EDITS.ALLOWED) { 109 if (!CONFIG.WEBADMIN.CONFIGURATION.EDITION.ALLOWED) {
110 return res.fail({ 110 return res.fail({
111 status: HttpStatusCode.METHOD_NOT_ALLOWED_405, 111 status: HttpStatusCode.METHOD_NOT_ALLOWED_405,
112 message: 'Server configuration is static and cannot be edited' 112 message: 'Server configuration is static and cannot be edited'
113 }) 113 })
114 } 114 }
115
115 return next() 116 return next()
116} 117}
117 118
diff --git a/server/tests/api/server/auto-follows.ts b/server/tests/api/server/auto-follows.ts
index ca6475bd5..90a668edb 100644
--- a/server/tests/api/server/auto-follows.ts
+++ b/server/tests/api/server/auto-follows.ts
@@ -186,6 +186,10 @@ describe('Test auto follows', function () {
186 await checkFollow(servers[0], servers[1], false) 186 await checkFollow(servers[0], servers[1], false)
187 await checkFollow(servers[0], servers[2], true) 187 await checkFollow(servers[0], servers[2], true)
188 }) 188 })
189
190 after(async function () {
191 await instanceIndexServer.terminate()
192 })
189 }) 193 })
190 194
191 after(async function () { 195 after(async function () {
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts
index 8363318f6..1d996d454 100644
--- a/server/tests/api/server/config.ts
+++ b/server/tests/api/server/config.ts
@@ -379,14 +379,14 @@ describe('Test static config', function () {
379 before(async function () { 379 before(async function () {
380 this.timeout(30000) 380 this.timeout(30000)
381 381
382 server = await createSingleServer(1, { webadmin: { configuration: { edit: { allowed: false } } } }) 382 server = await createSingleServer(1, { webadmin: { configuration: { edition: { allowed: false } } } })
383 await setAccessTokensToServers([ server ]) 383 await setAccessTokensToServers([ server ])
384 }) 384 })
385 385
386 it('Should tell the client that edits are not allowed', async function () { 386 it('Should tell the client that edits are not allowed', async function () {
387 const data = await server.config.getConfig() 387 const data = await server.config.getConfig()
388 388
389 expect(data.allowEdits).to.be.false 389 expect(data.webadmin.configuration.edition.allowed).to.be.false
390 }) 390 })
391 391
392 it('Should error when client tries to update', async function () { 392 it('Should error when client tries to update', async function () {
diff --git a/shared/extra-utils/mock-servers/mock-instances-index.ts b/shared/extra-utils/mock-servers/mock-instances-index.ts
index 5baec00de..43c2e9f6e 100644
--- a/shared/extra-utils/mock-servers/mock-instances-index.ts
+++ b/shared/extra-utils/mock-servers/mock-instances-index.ts
@@ -1,7 +1,11 @@
1import express from 'express' 1import express from 'express'
2import { Server } from 'http'
2import { randomInt } from '@shared/core-utils' 3import { randomInt } from '@shared/core-utils'
4import { terminateServer } from './utils'
3 5
4export class MockInstancesIndex { 6export class MockInstancesIndex {
7 private server: Server
8
5 private readonly indexInstances: { host: string, createdAt: string }[] = [] 9 private readonly indexInstances: { host: string, createdAt: string }[] = []
6 10
7 initialize () { 11 initialize () {
@@ -30,11 +34,15 @@ export class MockInstancesIndex {
30 }) 34 })
31 35
32 const port = 42000 + randomInt(1, 1000) 36 const port = 42000 + randomInt(1, 1000)
33 app.listen(port, () => res(port)) 37 this.server = app.listen(port, () => res(port))
34 }) 38 })
35 } 39 }
36 40
37 addInstance (host: string) { 41 addInstance (host: string) {
38 this.indexInstances.push({ host, createdAt: new Date().toISOString() }) 42 this.indexInstances.push({ host, createdAt: new Date().toISOString() })
39 } 43 }
44
45 terminate () {
46 return terminateServer(this.server)
47 }
40} 48}
diff --git a/shared/models/server/server-config.model.ts b/shared/models/server/server-config.model.ts
index 4bd4b0cb4..5bbb61252 100644
--- a/shared/models/server/server-config.model.ts
+++ b/shared/models/server/server-config.model.ts
@@ -30,7 +30,6 @@ export interface RegisteredIdAndPassAuthConfig {
30} 30}
31 31
32export interface ServerConfig { 32export interface ServerConfig {
33 allowEdits: boolean
34 serverVersion: string 33 serverVersion: string
35 serverCommit?: string 34 serverCommit?: string
36 35
@@ -42,6 +41,14 @@ export interface ServerConfig {
42 } 41 }
43 } 42 }
44 43
44 webadmin: {
45 configuration: {
46 edition: {
47 allowed: boolean
48 }
49 }
50 },
51
45 instance: { 52 instance: {
46 name: string 53 name: string
47 shortDescription: string 54 shortDescription: string
diff --git a/support/docker/production/config/custom-environment-variables.yaml b/support/docker/production/config/custom-environment-variables.yaml
index 7c430a995..c7cd28e65 100644
--- a/support/docker/production/config/custom-environment-variables.yaml
+++ b/support/docker/production/config/custom-environment-variables.yaml
@@ -70,9 +70,9 @@ object_storage:
70 70
71webadmin: 71webadmin:
72 configuration: 72 configuration:
73 edit: 73 edition:
74 allowed: 74 allowed:
75 __name: "PEERTUBE_ALLOW_WEBADMIN_CONFIG" 75 __name: "PEERTUBE_WEBADMIN_CONFIGURATION_EDITION_ALLOWED"
76 __format: "json" 76 __format: "json"
77 77
78log: 78log: