Fix admin edition disabling feature
This commit is contained in:
parent
e1a570abff
commit
cf0c8ee588
|
@ -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>
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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":')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -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') ]
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 () {
|
||||||
|
|
|
@ -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 () {
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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:
|
||||||
|
|
Loading…
Reference in New Issue