Fix admin edition disabling feature

This commit is contained in:
Chocobozzz 2021-10-14 11:35:43 +02:00
parent e1a570abff
commit cf0c8ee588
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
14 changed files with 61 additions and 20 deletions

View File

@ -1,4 +1,9 @@
<h1 class="sr-only" i18n>Configuration</h1> <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"> <form role="form" [formGroup]="form">
<div ngbNav #nav="ngbNav" [activeId]="activeNav" (activeIdChange)="onNavChange($event)" class="nav-tabs"> <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-7 col-xl-5"></div>
<div class="col-md-5 col-xl-5"> <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: There are errors in the form:
<ul> <ul>
@ -77,11 +82,14 @@
You cannot allow live replay if you don't enable transcoding. You cannot allow live replay if you don't enable transcoding.
</span> </span>
<span i18n *ngIf="!serverConfig.allowEdits"> <span i18n *ngIf="!isUpdateAllowed()">
You cannot change the server configuration because it's managed externally. You cannot change the server configuration because it's managed externally.
</span> </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>
</div> </div>
</form> </form>

View File

@ -258,7 +258,8 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
this.loadConfigAndUpdateForm() this.loadConfigAndUpdateForm()
this.loadCategoriesAndLanguages() this.loadCategoriesAndLanguages()
if (!this.serverConfig.allowEdits) {
if (!this.isUpdateAllowed()) {
this.form.disable() this.form.disable()
} }
} }
@ -293,6 +294,10 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
}) })
} }
isUpdateAllowed () {
return this.serverConfig.webadmin.configuration.edition.allowed === true
}
hasConsistentOptions () { hasConsistentOptions () {
if (this.hasLiveAllowReplayConsistentOptions()) return true if (this.hasLiveAllowReplayConsistentOptions()) return true

View File

@ -2,7 +2,7 @@
<textarea #textarea <textarea #textarea
[(ngModel)]="content" (ngModelChange)="onModelChange()" [(ngModel)]="content" (ngModelChange)="onModelChange()"
class="form-control" [ngClass]="classes" class="form-control" [ngClass]="classes"
[attr.disabled]="disabled" [attr.disabled]="disabled || null"
[ngStyle]="{ height: textareaHeight }" [ngStyle]="{ height: textareaHeight }"
[id]="name" [name]="name"> [id]="name" [name]="name">
</textarea> </textarea>

View File

@ -258,7 +258,7 @@ peertube:
webadmin: webadmin:
configuration: configuration:
edit: edition:
# Set this to false if you don't want to allow config edition in the web interface by instance admins # Set this to false if you don't want to allow config edition in the web interface by instance admins
allowed: true allowed: true

View File

@ -256,7 +256,7 @@ peertube:
webadmin: webadmin:
configuration: configuration:
edit: edition:
# Set this to false if you don't want to allow config edition in the web interface by instance admins # Set this to false if you don't want to allow config edition in the web interface by instance admins
allowed: true allowed: true

View File

@ -135,7 +135,7 @@ async function run () {
title: 'API - config', title: 'API - config',
path: '/api/v1/config', path: '/api/v1/config',
expecter: (body, status) => { expecter: (body, status) => {
return status === 200 && body.startsWith('{"allowEdits":') return status === 200 && body.startsWith('{"client":')
} }
} }
] ]

View File

@ -206,8 +206,8 @@ const CONFIG = {
}, },
WEBADMIN: { WEBADMIN: {
CONFIGURATION: { CONFIGURATION: {
EDITS: { EDITION: {
ALLOWED: config.get<boolean>('webadmin.configuration.edit.allowed') ALLOWED: config.get<boolean>('webadmin.configuration.edition.allowed')
} }
} }
}, },
@ -463,7 +463,7 @@ export function reloadConfig () {
function getConfigDirectories () { function getConfigDirectories () {
if (process.env.NODE_CONFIG_DIR) { if (process.env.NODE_CONFIG_DIR) {
return process.env.NODE_CONFIG_DIR.split(":") return process.env.NODE_CONFIG_DIR.split(':')
} }
return [ join(root(), 'config') ] return [ join(root(), 'config') ]

View File

@ -42,7 +42,6 @@ class ServerConfigManager {
const defaultTheme = getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME) const defaultTheme = getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME)
return { return {
allowEdits: CONFIG.WEBADMIN.CONFIGURATION.EDITS.ALLOWED,
client: { client: {
videos: { videos: {
miniature: { miniature: {
@ -50,6 +49,15 @@ class ServerConfigManager {
} }
} }
}, },
webadmin: {
configuration: {
edition: {
allowed: CONFIG.WEBADMIN.CONFIGURATION.EDITION.ALLOWED
}
}
},
instance: { instance: {
name: CONFIG.INSTANCE.NAME, name: CONFIG.INSTANCE.NAME,
shortDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION, shortDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION,

View File

@ -106,12 +106,13 @@ const customConfigUpdateValidator = [
] ]
function ensureConfigIsEditable (req: express.Request, res: express.Response, next: express.NextFunction) { 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({ return res.fail({
status: HttpStatusCode.METHOD_NOT_ALLOWED_405, status: HttpStatusCode.METHOD_NOT_ALLOWED_405,
message: 'Server configuration is static and cannot be edited' message: 'Server configuration is static and cannot be edited'
}) })
} }
return next() return next()
} }

View File

@ -186,6 +186,10 @@ describe('Test auto follows', function () {
await checkFollow(servers[0], servers[1], false) await checkFollow(servers[0], servers[1], false)
await checkFollow(servers[0], servers[2], true) await checkFollow(servers[0], servers[2], true)
}) })
after(async function () {
await instanceIndexServer.terminate()
})
}) })
after(async function () { after(async function () {

View File

@ -379,14 +379,14 @@ describe('Test static config', function () {
before(async function () { before(async function () {
this.timeout(30000) this.timeout(30000)
server = await createSingleServer(1, { webadmin: { configuration: { edit: { allowed: false } } } }) server = await createSingleServer(1, { webadmin: { configuration: { edition: { allowed: false } } } })
await setAccessTokensToServers([ server ]) await setAccessTokensToServers([ server ])
}) })
it('Should tell the client that edits are not allowed', async function () { it('Should tell the client that edits are not allowed', async function () {
const data = await server.config.getConfig() 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 () { it('Should error when client tries to update', async function () {

View File

@ -1,7 +1,11 @@
import express from 'express' import express from 'express'
import { Server } from 'http'
import { randomInt } from '@shared/core-utils' import { randomInt } from '@shared/core-utils'
import { terminateServer } from './utils'
export class MockInstancesIndex { export class MockInstancesIndex {
private server: Server
private readonly indexInstances: { host: string, createdAt: string }[] = [] private readonly indexInstances: { host: string, createdAt: string }[] = []
initialize () { initialize () {
@ -30,11 +34,15 @@ export class MockInstancesIndex {
}) })
const port = 42000 + randomInt(1, 1000) const port = 42000 + randomInt(1, 1000)
app.listen(port, () => res(port)) this.server = app.listen(port, () => res(port))
}) })
} }
addInstance (host: string) { addInstance (host: string) {
this.indexInstances.push({ host, createdAt: new Date().toISOString() }) this.indexInstances.push({ host, createdAt: new Date().toISOString() })
} }
terminate () {
return terminateServer(this.server)
}
} }

View File

@ -30,7 +30,6 @@ export interface RegisteredIdAndPassAuthConfig {
} }
export interface ServerConfig { export interface ServerConfig {
allowEdits: boolean
serverVersion: string serverVersion: string
serverCommit?: string serverCommit?: string
@ -42,6 +41,14 @@ export interface ServerConfig {
} }
} }
webadmin: {
configuration: {
edition: {
allowed: boolean
}
}
},
instance: { instance: {
name: string name: string
shortDescription: string shortDescription: string

View File

@ -70,9 +70,9 @@ object_storage:
webadmin: webadmin:
configuration: configuration:
edit: edition:
allowed: allowed:
__name: "PEERTUBE_ALLOW_WEBADMIN_CONFIG" __name: "PEERTUBE_WEBADMIN_CONFIGURATION_EDITION_ALLOWED"
__format: "json" __format: "json"
log: log: