From 36f9424ff192b0584a433bc196bced6fcf265808 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 31 Jan 2018 17:47:36 +0100 Subject: Add about page --- server/controllers/api/config.ts | 20 +++++++++++++++++++- server/tests/api/server/config.ts | 16 +++++++++++++++- server/tests/utils/server/config.ts | 22 ++++++++++++++++------ 3 files changed, 50 insertions(+), 8 deletions(-) (limited to 'server') diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index e4cb02820..89163edb3 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts @@ -1,19 +1,22 @@ import * as express from 'express' +import { omit } from 'lodash' import { ServerConfig, UserRight } from '../../../shared' +import { About } from '../../../shared/models/config/about.model' import { CustomConfig } from '../../../shared/models/config/custom-config.model' import { unlinkPromise, writeFilePromise } from '../../helpers/core-utils' import { isSignupAllowed } from '../../helpers/utils' import { CONFIG, CONSTRAINTS_FIELDS, reloadConfig } from '../../initializers' import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares' import { customConfigUpdateValidator } from '../../middlewares/validators/config' -import { omit } from 'lodash' const packageJSON = require('../../../../package.json') const configRouter = express.Router() +configRouter.get('/about', getAbout) configRouter.get('/', asyncMiddleware(getConfig) ) + configRouter.get('/custom', authenticate, ensureUserHasRight(UserRight.MANAGE_CONFIGURATION), @@ -39,6 +42,9 @@ async function getConfig (req: express.Request, res: express.Response, next: exp .map(r => parseInt(r, 10)) const json: ServerConfig = { + instance: { + name: CONFIG.INSTANCE.NAME + }, serverVersion: packageJSON.version, signup: { allowed @@ -64,6 +70,18 @@ async function getConfig (req: express.Request, res: express.Response, next: exp return res.json(json) } +function getAbout (req: express.Request, res: express.Response, next: express.NextFunction) { + const about: About = { + instance: { + name: CONFIG.INSTANCE.NAME, + description: CONFIG.INSTANCE.DESCRIPTION, + terms: CONFIG.INSTANCE.TERMS + } + } + + return res.json(about).end() +} + async function getCustomConfig (req: express.Request, res: express.Response, next: express.NextFunction) { const data = customConfig() diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index f83e21e82..35a5c430b 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts @@ -2,7 +2,8 @@ import 'mocha' import * as chai from 'chai' -import { deleteCustomConfig, killallServers, reRunServer } from '../../utils' +import { About } from '../../../../shared/models/config/about.model' +import { deleteCustomConfig, getAbout, killallServers, reRunServer } from '../../utils' const expect = chai.expect import { @@ -108,6 +109,7 @@ describe('Test config', function () { expect(data.instance.name).to.equal('PeerTube updated') expect(data.instance.description).to.equal('my super description') expect(data.instance.terms).to.equal('my super terms') + expect(data.cache.previews.size).to.equal(2) expect(data.signup.enabled).to.be.false expect(data.signup.limit).to.equal(5) expect(data.admin.email).to.equal('superadmin1@example.com') @@ -131,6 +133,9 @@ describe('Test config', function () { const res = await getCustomConfig(server.url, server.accessToken) const data = res.body + expect(data.instance.name).to.equal('PeerTube updated') + expect(data.instance.description).to.equal('my super description') + expect(data.instance.terms).to.equal('my super terms') expect(data.cache.previews.size).to.equal(2) expect(data.signup.enabled).to.be.false expect(data.signup.limit).to.equal(5) @@ -145,6 +150,15 @@ describe('Test config', function () { expect(data.transcoding.resolutions['1080p']).to.be.false }) + it('Should fetch the about information', async function () { + const res = await getAbout(server.url) + const data: About = res.body + + expect(data.instance.name).to.equal('PeerTube updated') + expect(data.instance.description).to.equal('my super description') + expect(data.instance.terms).to.equal('my super terms') + }) + it('Should remove the custom configuration', async function () { this.timeout(10000) diff --git a/server/tests/utils/server/config.ts b/server/tests/utils/server/config.ts index b6905757a..e5411117a 100644 --- a/server/tests/utils/server/config.ts +++ b/server/tests/utils/server/config.ts @@ -1,15 +1,24 @@ -import * as request from 'supertest' import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../' import { CustomConfig } from '../../../../shared/models/config/custom-config.model' function getConfig (url: string) { const path = '/api/v1/config' - return request(url) - .get(path) - .set('Accept', 'application/json') - .expect(200) - .expect('Content-Type', /json/) + return makeGetRequest({ + url, + path, + statusCodeExpected: 200 + }) +} + +function getAbout (url: string) { + const path = '/api/v1/config/about' + + return makeGetRequest({ + url, + path, + statusCodeExpected: 200 + }) } function getCustomConfig (url: string, token: string, statusCodeExpected = 200) { @@ -52,5 +61,6 @@ export { getConfig, getCustomConfig, updateCustomConfig, + getAbout, deleteCustomConfig } -- cgit v1.2.3