mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2024-08-17 17:30:32 +03:00
fix(server/plugins): avoid duplicate settings
Filter settings so that the name property is unique. closes #6356
This commit is contained in:
parent
5dfa07adb5
commit
1eb8fc2c06
@ -1,5 +1,24 @@
|
||||
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 = [
|
||||
'action:application.listening',
|
||||
'action:notifier.notification.created',
|
||||
|
@ -5,6 +5,7 @@ import './html-injection'
|
||||
import './id-and-pass-auth'
|
||||
import './plugin-helpers'
|
||||
import './plugin-router'
|
||||
import './plugin-settings'
|
||||
import './plugin-storage'
|
||||
import './plugin-transcoding'
|
||||
import './plugin-unloading'
|
||||
|
48
packages/tests/src/plugins/plugin-settings.ts
Normal file
48
packages/tests/src/plugins/plugin-settings.ts
Normal file
@ -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 externalAuths: RegisterServerAuthExternalOptions[] = []
|
||||
@ -203,7 +203,10 @@ export class RegisterHelpers {
|
||||
|
||||
private buildRegisterSetting () {
|
||||
return (options: RegisterServerSettingOptions) => {
|
||||
this.settings.push(options)
|
||||
this.settings = [
|
||||
...this.settings.filter((s) => s.name !== options.name),
|
||||
options
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user