1
0
Fork 0

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>
<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>

View file

@ -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

View file

@ -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>

View file

@ -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

View file

@ -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

View file

@ -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":')
}
}
]

View file

@ -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') ]

View file

@ -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,

View file

@ -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()
}

View file

@ -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 () {

View file

@ -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 () {

View file

@ -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)
}
}

View file

@ -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

View file

@ -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: