this.pluginService.getPlugin(npmName)
.pipe(switchMap(plugin => {
return this.pluginService.getPluginRegisteredSettings(plugin.name, plugin.type)
- .pipe(map(data => ({ plugin, registeredSettings: data.settings })))
+ .pipe(map(data => ({ plugin, registeredSettings: data.registeredSettings })))
}))
.subscribe(
({ plugin, registeredSettings }) => {
import { ManagePlugin } from '@shared/models/plugins/manage-plugin.model'
import { InstallOrUpdatePlugin } from '@shared/models/plugins/install-plugin.model'
import { PeerTubePluginIndex } from '@shared/models/plugins/peertube-plugin-index.model'
-import { RegisterServerSettingOptions } from '@shared/models/plugins/register-server-setting.model'
+import { RegisteredServerSettings, RegisterServerSettingOptions } from '@shared/models/plugins/register-server-setting.model'
import { PluginService } from '@app/core/plugins/plugin.service'
@Injectable()
const npmName = this.pluginService.nameToNpmName(pluginName, pluginType)
const path = PluginApiService.BASE_PLUGIN_URL + '/' + npmName + '/registered-settings'
- return this.authHttp.get<{ settings: RegisterServerSettingOptions[] }>(path)
+ return this.authHttp.get<RegisteredServerSettings>(path)
.pipe(catchError(res => this.restExtractor.handleError(res)))
}
import { HttpClient } from '@angular/common/http'
import { RestExtractor } from '@app/shared/rest'
import { PluginType } from '@shared/models/plugins/plugin.type'
+import { PublicServerSetting } from '@shared/models/plugins/public-server.setting'
interface HookStructValue extends RegisterClientHookOptions {
plugin: ServerConfigPlugin
getSettings: () => {
const npmName = this.nameToNpmName(pluginInfo.plugin.name, pluginInfo.pluginType)
- const path = PluginService.BASE_PLUGIN_URL + '/' + npmName
+ const path = PluginService.BASE_PLUGIN_URL + '/' + npmName + '/public-settings'
- return this.authHttp.get<PeerTubePlugin>(path)
+ return this.authHttp.get<PublicServerSetting>(path)
.pipe(
- map(p => p.settings),
+ map(p => p.publicSettings),
catchError(res => this.restExtractor.handleError(res))
)
.toPromise()
import { listAvailablePluginsFromIndex } from '../../lib/plugins/plugin-index'
import { PeertubePluginIndexList } from '../../../shared/models/plugins/peertube-plugin-index-list.model'
import { RegisteredServerSettings } from '../../../shared/models/plugins/register-server-setting.model'
+import { PublicServerSetting } from '../../../shared/models/plugins/public-server.setting'
const pluginRouter = express.Router()
asyncMiddleware(listPlugins)
)
-pluginRouter.get('/:npmName',
+pluginRouter.get('/:npmName/registered-settings',
authenticate,
ensureUserHasRight(UserRight.MANAGE_PLUGINS),
asyncMiddleware(existingPluginValidator),
- getPlugin
+ getPluginRegisteredSettings
)
-pluginRouter.get('/:npmName/registered-settings',
- authenticate,
- ensureUserHasRight(UserRight.MANAGE_PLUGINS),
+pluginRouter.get('/:npmName/public-settings',
asyncMiddleware(existingPluginValidator),
- getPluginRegisteredSettings
+ getPublicPluginSettings
)
pluginRouter.put('/:npmName/settings',
asyncMiddleware(updatePluginSettings)
)
+pluginRouter.get('/:npmName',
+ authenticate,
+ ensureUserHasRight(UserRight.MANAGE_PLUGINS),
+ asyncMiddleware(existingPluginValidator),
+ getPlugin
+)
+
pluginRouter.post('/install',
authenticate,
ensureUserHasRight(UserRight.MANAGE_PLUGINS),
return res.sendStatus(204)
}
+function getPublicPluginSettings (req: express.Request, res: express.Response) {
+ const plugin = res.locals.plugin
+ const registeredSettings = PluginManager.Instance.getRegisteredSettings(req.params.npmName)
+ const publicSettings = plugin.getPublicSettings(registeredSettings)
+
+ const json: PublicServerSetting = { publicSettings }
+
+ return res.json(json)
+}
+
function getPluginRegisteredSettings (req: express.Request, res: express.Response) {
- const settings = PluginManager.Instance.getRegisteredSettings(req.params.npmName)
+ const registeredSettings = PluginManager.Instance.getRegisteredSettings(req.params.npmName)
- const json: RegisteredServerSettings = { settings }
+ const json: RegisteredServerSettings = { registeredSettings }
return res.json(json)
}
import { PluginType } from '../../../shared/models/plugins/plugin.type'
import { PeerTubePlugin } from '../../../shared/models/plugins/peertube-plugin.model'
import { FindAndCountOptions, json } from 'sequelize'
-import { PeerTubePluginIndex } from '../../../shared/models/plugins/peertube-plugin-index.model'
+import { RegisterServerSettingOptions } from '../../../shared/models/plugins/register-server-setting.model'
@DefaultScope(() => ({
attributes: {
return 'peertube-plugin-' + name
}
+ getPublicSettings (registeredSettings: RegisterServerSettingOptions[]) {
+ const result: { [ name: string ]: string } = {}
+ const settings = this.settings || {}
+
+ for (const r of registeredSettings) {
+ if (r.private !== false) continue
+
+ result[r.name] = settings[r.name] || r.default || null
+ }
+
+ return result
+ }
+
toFormattedJSON (): PeerTubePlugin {
return {
name: this.name,
})
})
- describe('When getting a plugin or the registered settings', function () {
+ describe('When getting a plugin or the registered settings or public settings', function () {
const path = '/api/v1/plugins/'
it('Should fail with an invalid token', async function () {
})
it('Should fail with an invalid npm name', async function () {
- for (const suffix of [ 'toto', 'toto/registered-settings' ]) {
+ for (const suffix of [ 'toto', 'toto/registered-settings', 'toto/public-settings' ]) {
await makeGetRequest({
url: server.url,
path: path + suffix,
})
}
- for (const suffix of [ 'peertube-plugin-TOTO', 'peertube-plugin-TOTO/registered-settings' ]) {
+ for (const suffix of [ 'peertube-plugin-TOTO', 'peertube-plugin-TOTO/registered-settings', 'peertube-plugin-TOTO/public-settings' ]) {
await makeGetRequest({
url: server.url,
path: path + suffix,
})
it('Should fail with an unknown plugin', async function () {
- for (const suffix of [ 'peertube-plugin-toto', 'peertube-plugin-toto/registered-settings' ]) {
+ for (const suffix of [ 'peertube-plugin-toto', 'peertube-plugin-toto/registered-settings', 'peertube-plugin-toto/public-settings' ]) {
await makeGetRequest({
url: server.url,
path: path + suffix,
})
it('Should succeed with the correct parameters', async function () {
- for (const suffix of [ npmPlugin, `${npmPlugin}/registered-settings` ]) {
+ for (const suffix of [ npmPlugin, `${npmPlugin}/registered-settings`, `${npmPlugin}/public-settings` ]) {
await makeGetRequest({
url: server.url,
path: path + suffix,
setPluginVersion, uninstallPlugin,
updateCustomSubConfig, updateMyUser, updatePluginPackageJSON, updatePlugin,
updatePluginSettings,
- wait
+ wait, getPublicSettings
} from '../../../../shared/extra-utils'
import { PluginType } from '../../../../shared/models/plugins/plugin.type'
import { PeerTubePluginIndex } from '../../../../shared/models/plugins/peertube-plugin-index.model'
import { User } from '../../../../shared/models/users'
import { PluginPackageJson } from '../../../../shared/models/plugins/plugin-package-json.model'
import { RegisteredServerSettings } from '../../../../shared/models/plugins/register-server-setting.model'
+import { PublicServerSetting } from '../../../../shared/models/plugins/public-server.setting'
const expect = chai.expect
npmName: 'peertube-plugin-hello-world'
})
- const settings = (res.body as RegisteredServerSettings).settings
+ const registeredSettings = (res.body as RegisteredServerSettings).registeredSettings
- expect(settings).to.have.length.at.least(1)
+ expect(registeredSettings).to.have.length.at.least(1)
- const adminNameSettings = settings.find(s => s.name === 'admin-name')
+ const adminNameSettings = registeredSettings.find(s => s.name === 'admin-name')
expect(adminNameSettings).to.not.be.undefined
})
+ it('Should get public settings', async function () {
+ const res = await getPublicSettings({ url: server.url, npmName: 'peertube-plugin-hello-world' })
+
+ const publicSettings = (res.body as PublicServerSetting).publicSettings
+
+ expect(Object.keys(publicSettings)).to.have.lengthOf(1)
+ expect(Object.keys(publicSettings)).to.deep.equal([ 'user-name' ])
+ expect(publicSettings['user-name']).to.be.null
+ })
+
it('Should update the settings', async function () {
const settings = {
'admin-name': 'Cid'
})
}
+function getPublicSettings (parameters: {
+ url: string,
+ npmName: string,
+ expectedStatus?: number
+}) {
+ const { url, npmName, expectedStatus = 200 } = parameters
+ const path = '/api/v1/plugins/' + npmName + '/public-settings'
+
+ return makeGetRequest({
+ url,
+ path,
+ statusCodeExpected: expectedStatus
+ })
+}
+
function installPlugin (parameters: {
url: string,
accessToken: string,
getPackageJSONPath,
updatePluginPackageJSON,
getPluginPackageJSON,
- getPluginTestPath
+ getPluginTestPath,
+ getPublicSettings
}
--- /dev/null
+export interface PublicServerSetting {
+ publicSettings: { [ name: string ]: string }
+}
name: string
label: string
type: 'input'
+
+ // If the setting is not private, anyone can view its value
+ // Mainly used by the PeerTube client to get admin config
+ private: boolean
+
+ // Default setting value
default?: string
}
export interface RegisteredServerSettings {
- settings: RegisterServerSettingOptions[]
+ registeredSettings: RegisterServerSettingOptions[]
}