mirror of https://github.com/Chocobozzz/PeerTube
fix(server/plugins): avoid duplicate settings
Filter settings so that the name property is unique. closes #6356pull/6346/head
parent
5dfa07adb5
commit
1eb8fc2c06
|
@ -1,5 +1,24 @@
|
||||||
async function register ({ registerHook, registerSetting, settingsManager, storageManager, peertubeHelpers }) {
|
async function register ({ registerHook, registerSetting, settingsManager, storageManager, peertubeHelpers }) {
|
||||||
{
|
{
|
||||||
|
registerSetting({
|
||||||
|
name: 'unique-setting',
|
||||||
|
label: 'Unique setting',
|
||||||
|
type: 'select',
|
||||||
|
options: []
|
||||||
|
})
|
||||||
|
|
||||||
|
registerSetting({
|
||||||
|
name: 'unique-setting',
|
||||||
|
label: 'Unique setting',
|
||||||
|
type: 'select',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
value: 1,
|
||||||
|
label: 'One'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
const actionHooks = [
|
const actionHooks = [
|
||||||
'action:application.listening',
|
'action:application.listening',
|
||||||
'action:notifier.notification.created',
|
'action:notifier.notification.created',
|
||||||
|
|
|
@ -5,6 +5,7 @@ import './html-injection'
|
||||||
import './id-and-pass-auth'
|
import './id-and-pass-auth'
|
||||||
import './plugin-helpers'
|
import './plugin-helpers'
|
||||||
import './plugin-router'
|
import './plugin-router'
|
||||||
|
import './plugin-settings'
|
||||||
import './plugin-storage'
|
import './plugin-storage'
|
||||||
import './plugin-transcoding'
|
import './plugin-transcoding'
|
||||||
import './plugin-unloading'
|
import './plugin-unloading'
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
||||||
|
|
||||||
|
import { expect } from 'chai'
|
||||||
|
import {
|
||||||
|
cleanupTests,
|
||||||
|
createSingleServer,
|
||||||
|
PeerTubeServer,
|
||||||
|
PluginsCommand,
|
||||||
|
setAccessTokensToServers
|
||||||
|
} from '@peertube/peertube-server-commands'
|
||||||
|
|
||||||
|
describe('Test plugin settings', function () {
|
||||||
|
let server: PeerTubeServer
|
||||||
|
let command: PluginsCommand
|
||||||
|
|
||||||
|
before(async function () {
|
||||||
|
this.timeout(30000)
|
||||||
|
|
||||||
|
server = await createSingleServer(1)
|
||||||
|
await setAccessTokensToServers([ server ])
|
||||||
|
|
||||||
|
command = server.plugins
|
||||||
|
|
||||||
|
await command.install({
|
||||||
|
path: PluginsCommand.getPluginTestPath()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should not have duplicate settings', async function () {
|
||||||
|
const { registeredSettings } = await command.getRegisteredSettings({
|
||||||
|
npmName: 'peertube-plugin-test'
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(registeredSettings.length).to.equal(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should return the latest registered settings', async function () {
|
||||||
|
const { registeredSettings } = await command.getRegisteredSettings({
|
||||||
|
npmName: 'peertube-plugin-test'
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(registeredSettings[0].options.length).length.to.equal(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
after(async function () {
|
||||||
|
await cleanupTests([ server ])
|
||||||
|
})
|
||||||
|
})
|
|
@ -44,7 +44,7 @@ export class RegisterHelpers {
|
||||||
}[]
|
}[]
|
||||||
} = {}
|
} = {}
|
||||||
|
|
||||||
private readonly settings: RegisterServerSettingOptions[] = []
|
private settings: RegisterServerSettingOptions[] = []
|
||||||
|
|
||||||
private idAndPassAuths: RegisterServerAuthPassOptions[] = []
|
private idAndPassAuths: RegisterServerAuthPassOptions[] = []
|
||||||
private externalAuths: RegisterServerAuthExternalOptions[] = []
|
private externalAuths: RegisterServerAuthExternalOptions[] = []
|
||||||
|
@ -203,7 +203,10 @@ export class RegisterHelpers {
|
||||||
|
|
||||||
private buildRegisterSetting () {
|
private buildRegisterSetting () {
|
||||||
return (options: RegisterServerSettingOptions) => {
|
return (options: RegisterServerSettingOptions) => {
|
||||||
this.settings.push(options)
|
this.settings = [
|
||||||
|
...this.settings.filter((s) => s.name !== options.name),
|
||||||
|
options
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue