From 901637bb87f5eb0518fb7ca69d98b53ed918339e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 1 Mar 2018 13:57:29 +0100 Subject: Add ability to change the homepage --- server/controllers/api/config.ts | 4 ++++ server/initializers/constants.ts | 1 + server/middlewares/validators/config.ts | 6 ++++++ server/tests/api/check-params/config.ts | 1 + server/tests/api/server/config.ts | 5 +++++ 5 files changed, 17 insertions(+) (limited to 'server') diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index 427125810..a25d7a157 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts @@ -44,6 +44,7 @@ async function getConfig (req: express.Request, res: express.Response, next: exp const json: ServerConfig = { instance: { name: CONFIG.INSTANCE.NAME, + defaultClientRoute: CONFIG.INSTANCE.DEFAULT_CLIENT_ROUTE, customizations: { javascript: CONFIG.INSTANCE.CUSTOMIZATIONS.JAVASCRIPT, css: CONFIG.INSTANCE.CUSTOMIZATIONS.CSS @@ -114,7 +115,9 @@ async function updateCustomConfig (req: express.Request, res: express.Response, // Need to change the videoQuota key a little bit const toUpdateJSON = omit(toUpdate, 'videoQuota') toUpdateJSON.user['video_quota'] = toUpdate.user.videoQuota + toUpdateJSON.instance['default_client_route'] = toUpdate.instance.defaultClientRoute delete toUpdate.user.videoQuota + delete toUpdate.instance.defaultClientRoute await writeFilePromise(CONFIG.CUSTOM_FILE, JSON.stringify(toUpdateJSON, undefined, 2)) @@ -138,6 +141,7 @@ function customConfig (): CustomConfig { name: CONFIG.INSTANCE.NAME, description: CONFIG.INSTANCE.DESCRIPTION, terms: CONFIG.INSTANCE.TERMS, + defaultClientRoute: CONFIG.INSTANCE.DEFAULT_CLIENT_ROUTE, customizations: { css: CONFIG.INSTANCE.CUSTOMIZATIONS.CSS, javascript: CONFIG.INSTANCE.CUSTOMIZATIONS.JAVASCRIPT diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 318df48bf..5946bcd11 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -159,6 +159,7 @@ const CONFIG = { get NAME () { return config.get('instance.name') }, get DESCRIPTION () { return config.get('instance.description') }, get TERMS () { return config.get('instance.terms') }, + get DEFAULT_CLIENT_ROUTE () { return config.get('instance.default_client_route') }, CUSTOMIZATIONS: { get JAVASCRIPT () { return config.get('instance.customizations.javascript') }, get CSS () { return config.get('instance.customizations.css') } diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts index 800aaf107..ee6f6efa4 100644 --- a/server/middlewares/validators/config.ts +++ b/server/middlewares/validators/config.ts @@ -5,6 +5,12 @@ import { logger } from '../../helpers/logger' import { areValidationErrors } from './utils' const customConfigUpdateValidator = [ + body('instance.name').exists().withMessage('Should have a valid instance name'), + body('instance.description').exists().withMessage('Should have a valid instance description'), + body('instance.terms').exists().withMessage('Should have a valid instance terms'), + body('instance.defaultClientRoute').exists().withMessage('Should have a valid instance default client route'), + body('instance.customizations.css').exists().withMessage('Should have a valid instance CSS customization'), + body('instance.customizations.javascript').exists().withMessage('Should have a valid instance JavaScript customization'), body('cache.previews.size').isInt().withMessage('Should have a valid previews size'), body('signup.enabled').isBoolean().withMessage('Should have a valid signup enabled boolean'), body('signup.limit').isInt().withMessage('Should have a valid signup limit'), diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts index a66e51a6a..ca8239270 100644 --- a/server/tests/api/check-params/config.ts +++ b/server/tests/api/check-params/config.ts @@ -18,6 +18,7 @@ describe('Test config API validators', function () { name: 'PeerTube updated', description: 'my super description', terms: 'my super terms', + defaultClientRoute: '/videos/recently-added', customizations: { javascript: 'alert("coucou")', css: 'body { background-color: red; }' diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index 3d90580d8..271a57275 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts @@ -54,6 +54,7 @@ describe('Test config', function () { expect(data.instance.name).to.equal('PeerTube') expect(data.instance.description).to.equal('Welcome to this PeerTube instance!') expect(data.instance.terms).to.equal('No terms for now.') + expect(data.instance.defaultClientRoute).to.equal('/videos/trending') expect(data.instance.customizations.css).to.be.empty expect(data.instance.customizations.javascript).to.be.empty expect(data.cache.previews.size).to.equal(1) @@ -76,6 +77,7 @@ describe('Test config', function () { name: 'PeerTube updated', description: 'my super description', terms: 'my super terms', + defaultClientRoute: '/videos/recently-added', customizations: { javascript: 'alert("coucou")', css: 'body { background-color: red; }' @@ -116,6 +118,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.instance.defaultClientRoute).to.equal('/videos/recently-added') expect(data.instance.customizations.javascript).to.equal('alert("coucou")') expect(data.instance.customizations.css).to.equal('body { background-color: red; }') expect(data.cache.previews.size).to.equal(2) @@ -145,6 +148,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.instance.defaultClientRoute).to.equal('/videos/recently-added') expect(data.instance.customizations.javascript).to.equal('alert("coucou")') expect(data.instance.customizations.css).to.equal('body { background-color: red; }') expect(data.cache.previews.size).to.equal(2) @@ -181,6 +185,7 @@ describe('Test config', function () { expect(data.instance.name).to.equal('PeerTube') expect(data.instance.description).to.equal('Welcome to this PeerTube instance!') expect(data.instance.terms).to.equal('No terms for now.') + expect(data.instance.defaultClientRoute).to.equal('/videos/trending') expect(data.instance.customizations.css).to.be.empty expect(data.instance.customizations.javascript).to.be.empty expect(data.cache.previews.size).to.equal(1) -- cgit v1.2.3