fix(server/plugins): avoid duplicate settings

Filter settings so that the name property is unique.

closes #6356
pull/6346/head
kontrollanten 2024-04-26 09:16:54 +02:00 committed by Chocobozzz
parent 5dfa07adb5
commit 1eb8fc2c06
4 changed files with 73 additions and 2 deletions

View File

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

View File

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

View 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 ])
})
})

View File

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