Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Fix admin edition disabling feature

Chocobozzzcf0c8ee588e3
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 6ae7b1b796..8fef39b793 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 @@
<h1 class="sr-only" i18n>Configuration</h1>
+
+<div class="alert alert-warning" *ngIf="!isUpdateAllowed()" i18n>
+ Updating instance configuration from the web interface is disabled by the system administrator.
+</div>
+
<form role="form" [formGroup]="form">
<div ngbNav #nav="ngbNav" [activeId]="activeNav" (activeIdChange)="onNavChange($event)" class="nav-tabs">
@@ -63,7 +68,7 @@
<div class="col-md-7 col-xl-5"></div>
<div class="col-md-5 col-xl-5">
- <div class="form-error submit-error" i18n *ngIf="!form.valid && serverConfig.allowEdits">
+ <div class="form-error submit-error" i18n *ngIf="!form.valid && isUpdateAllowed()">
There are errors in the form:
<ul>
@@ -77,11 +82,14 @@
You cannot allow live replay if you don't enable transcoding.
</span>
- <span i18n *ngIf="!serverConfig.allowEdits">
+ <span i18n *ngIf="!isUpdateAllowed()">
You cannot change the server configuration because it's managed externally.
</span>
- <input (click)="formValidated()" type="submit" i18n-value value="Update configuration" [disabled]="!form.valid || !hasConsistentOptions() || !serverConfig.allowEdits">
+ <input
+ (click)="formValidated()" type="submit" i18n-value value="Update configuration"
+ [disabled]="!form.valid || !hasConsistentOptions() || !isUpdateAllowed()"
+ >
</div>
</div>
</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 04b0175a73..96c67fac7e 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 {
this.loadConfigAndUpdateForm()
this.loadCategoriesAndLanguages()
- if (!this.serverConfig.allowEdits) {
+
+ if (!this.isUpdateAllowed()) {
this.form.disable()
}
}
@@ -293,6 +294,10 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
})
}
+ isUpdateAllowed () {
+ return this.serverConfig.webadmin.configuration.edition.allowed === true
+ }
+
hasConsistentOptions () {
if (this.hasLiveAllowReplayConsistentOptions()) return true
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 a460cb9b7b..7c2a42791b 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 @@
<textarea #textarea
[(ngModel)]="content" (ngModelChange)="onModelChange()"
class="form-control" [ngClass]="classes"
- [attr.disabled]="disabled"
+ [attr.disabled]="disabled || null"
[ngStyle]="{ height: textareaHeight }"
[id]="name" [name]="name">
</textarea>
diff --git a/config/default.yaml b/config/default.yaml
index 99f00a9ec1..a8d070cc80 100644
--- a/config/default.yaml
+++ b/config/default.yaml
@@ -258,7 +258,7 @@ peertube:
webadmin:
configuration:
- edit:
+ edition:
# Set this to false if you don't want to allow config edition in the web interface by instance admins
allowed: true
diff --git a/config/production.yaml.example b/config/production.yaml.example
index c3cda52b5b..bc9f28e954 100644
--- a/config/production.yaml.example
+++ b/config/production.yaml.example
@@ -256,7 +256,7 @@ peertube:
webadmin:
configuration:
- edit:
+ edition:
# Set this to false if you don't want to allow config edition in the web interface by instance admins
allowed: true
diff --git a/scripts/benchmark.ts b/scripts/benchmark.ts
index 007e3c33b7..788318313f 100644
--- a/scripts/benchmark.ts
+++ b/scripts/benchmark.ts
@@ -135,7 +135,7 @@ async function run () {
title: 'API - config',
path: '/api/v1/config',
expecter: (body, status) => {
- return status === 200 && body.startsWith('{"allowEdits":')
+ return status === 200 && body.startsWith('{"client":')
}
}
]
diff --git a/server/initializers/config.ts b/server/initializers/config.ts
index a37aae5517..48bb5ab8ee 100644
--- a/server/initializers/config.ts
+++ b/server/initializers/config.ts
@@ -206,8 +206,8 @@ const CONFIG = {
},
WEBADMIN: {
CONFIGURATION: {
- EDITS: {
- ALLOWED: config.get<boolean>('webadmin.configuration.edit.allowed')
+ EDITION: {
+ ALLOWED: config.get<boolean>('webadmin.configuration.edition.allowed')
}
}
},
@@ -463,7 +463,7 @@ export function reloadConfig () {
function getConfigDirectories () {
if (process.env.NODE_CONFIG_DIR) {
- return process.env.NODE_CONFIG_DIR.split(":")
+ return process.env.NODE_CONFIG_DIR.split(':')
}
return [ join(root(), 'config') ]
diff --git a/server/lib/server-config-manager.ts b/server/lib/server-config-manager.ts
index 58a37b56c9..b78251e8ce 100644
--- a/server/lib/server-config-manager.ts
+++ b/server/lib/server-config-manager.ts
@@ -42,7 +42,6 @@ class ServerConfigManager {
const defaultTheme = getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME)
return {
- allowEdits: CONFIG.WEBADMIN.CONFIGURATION.EDITS.ALLOWED,
client: {
videos: {
miniature: {
@@ -50,6 +49,15 @@ class ServerConfigManager {
}
}
},
+
+ webadmin: {
+ configuration: {
+ edition: {
+ allowed: CONFIG.WEBADMIN.CONFIGURATION.EDITION.ALLOWED
+ }
+ }
+ },
+
instance: {
name: CONFIG.INSTANCE.NAME,
shortDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION,
diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts
index 5f1ac89bc9..f0385ab44b 100644
--- a/server/middlewares/validators/config.ts
+++ b/server/middlewares/validators/config.ts
@@ -106,12 +106,13 @@ const customConfigUpdateValidator = [
]
function ensureConfigIsEditable (req: express.Request, res: express.Response, next: express.NextFunction) {
- if (!CONFIG.WEBADMIN.CONFIGURATION.EDITS.ALLOWED) {
+ if (!CONFIG.WEBADMIN.CONFIGURATION.EDITION.ALLOWED) {
return res.fail({
status: HttpStatusCode.METHOD_NOT_ALLOWED_405,
message: 'Server configuration is static and cannot be edited'
})
}
+
return next()
}
diff --git a/server/tests/api/server/auto-follows.ts b/server/tests/api/server/auto-follows.ts
index ca6475bd52..90a668edb0 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 () {
await checkFollow(servers[0], servers[1], false)
await checkFollow(servers[0], servers[2], true)
})
+
+ after(async function () {
+ await instanceIndexServer.terminate()
+ })
})
after(async function () {
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts
index 8363318f61..1d996d4541 100644
--- a/server/tests/api/server/config.ts
+++ b/server/tests/api/server/config.ts
@@ -379,14 +379,14 @@ describe('Test static config', function () {
before(async function () {
this.timeout(30000)
- server = await createSingleServer(1, { webadmin: { configuration: { edit: { allowed: false } } } })
+ server = await createSingleServer(1, { webadmin: { configuration: { edition: { allowed: false } } } })
await setAccessTokensToServers([ server ])
})
it('Should tell the client that edits are not allowed', async function () {
const data = await server.config.getConfig()
- expect(data.allowEdits).to.be.false
+ expect(data.webadmin.configuration.edition.allowed).to.be.false
})
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 5baec00dee..43c2e9f6ec 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 @@
import express from 'express'
+import { Server } from 'http'
import { randomInt } from '@shared/core-utils'
+import { terminateServer } from './utils'
export class MockInstancesIndex {
+ private server: Server
+
private readonly indexInstances: { host: string, createdAt: string }[] = []
initialize () {
@@ -30,11 +34,15 @@ export class MockInstancesIndex {
})
const port = 42000 + randomInt(1, 1000)
- app.listen(port, () => res(port))
+ this.server = app.listen(port, () => res(port))
})
}
addInstance (host: string) {
this.indexInstances.push({ host, createdAt: new Date().toISOString() })
}
+
+ terminate () {
+ return terminateServer(this.server)
+ }
}
diff --git a/shared/models/server/server-config.model.ts b/shared/models/server/server-config.model.ts
index 4bd4b0cb45..5bbb612525 100644
--- a/shared/models/server/server-config.model.ts
+++ b/shared/models/server/server-config.model.ts
@@ -30,7 +30,6 @@ export interface RegisteredIdAndPassAuthConfig {
}
export interface ServerConfig {
- allowEdits: boolean
serverVersion: string
serverCommit?: string
@@ -42,6 +41,14 @@ export interface ServerConfig {
}
}
+ webadmin: {
+ configuration: {
+ edition: {
+ allowed: boolean
+ }
+ }
+ },
+
instance: {
name: string
shortDescription: string
diff --git a/support/docker/production/config/custom-environment-variables.yaml b/support/docker/production/config/custom-environment-variables.yaml
index 7c430a9955..c7cd28e652 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:
webadmin:
configuration:
- edit:
- allowed:
- __name: "PEERTUBE_ALLOW_WEBADMIN_CONFIG"
+ edition:
+ allowed:
+ __name: "PEERTUBE_WEBADMIN_CONFIGURATION_EDITION_ALLOWED"
__format: "json"
log: