Add public settings endpoint

This commit is contained in:
Chocobozzz
2019-07-26 09:35:43 +02:00
parent 23bdacf8ec
commit ba211e7386
10 changed files with 94 additions and 28 deletions

View File

@@ -281,7 +281,7 @@ describe('Test server plugins API validators', function () {
})
})
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 () {
@@ -307,7 +307,7 @@ describe('Test server plugins API validators', 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,
@@ -316,7 +316,7 @@ describe('Test server plugins API validators', 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,
@@ -327,7 +327,7 @@ describe('Test server plugins API validators', function () {
})
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,
@@ -338,7 +338,7 @@ describe('Test server plugins API validators', function () {
})
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,

View File

@@ -18,7 +18,7 @@ import {
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'
@@ -27,6 +27,7 @@ import { PeerTubePlugin } from '../../../../shared/models/plugins/peertube-plugi
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
@@ -217,14 +218,24 @@ describe('Test plugins', function () {
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'