From f8802489bbc2c0363b5668e47de7c35f573342e1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 20 Feb 2019 15:36:43 +0100 Subject: Add isNSFW instance configuration key --- server/controllers/api/config.ts | 10 ++++++---- server/initializers/checker-before-init.ts | 2 +- server/initializers/constants.ts | 1 + server/tests/api/check-params/config.ts | 1 + server/tests/api/server/config.ts | 3 +++ 5 files changed, 12 insertions(+), 5 deletions(-) (limited to 'server') diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index 1f3341bc0..6497cda3c 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts @@ -58,6 +58,7 @@ async function getConfig (req: express.Request, res: express.Response) { name: CONFIG.INSTANCE.NAME, shortDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION, defaultClientRoute: CONFIG.INSTANCE.DEFAULT_CLIENT_ROUTE, + isNSFW: CONFIG.INSTANCE.IS_NSFW, defaultNSFWPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, customizations: { javascript: CONFIG.INSTANCE.CUSTOMIZATIONS.JAVASCRIPT, @@ -134,7 +135,7 @@ async function getConfig (req: express.Request, res: express.Response) { return res.json(json) } -function getAbout (req: express.Request, res: express.Response, next: express.NextFunction) { +function getAbout (req: express.Request, res: express.Response) { const about: About = { instance: { name: CONFIG.INSTANCE.NAME, @@ -147,13 +148,13 @@ function getAbout (req: express.Request, res: express.Response, next: express.Ne return res.json(about).end() } -async function getCustomConfig (req: express.Request, res: express.Response, next: express.NextFunction) { +async function getCustomConfig (req: express.Request, res: express.Response) { const data = customConfig() return res.json(data).end() } -async function deleteCustomConfig (req: express.Request, res: express.Response, next: express.NextFunction) { +async function deleteCustomConfig (req: express.Request, res: express.Response) { await remove(CONFIG.CUSTOM_FILE) auditLogger.delete(getAuditIdFromRes(res), new CustomConfigAuditView(customConfig())) @@ -166,7 +167,7 @@ async function deleteCustomConfig (req: express.Request, res: express.Response, return res.json(data).end() } -async function updateCustomConfig (req: express.Request, res: express.Response, next: express.NextFunction) { +async function updateCustomConfig (req: express.Request, res: express.Response) { const oldCustomConfigAuditKeys = new CustomConfigAuditView(customConfig()) // camelCase to snake_case key + Force number conversion @@ -203,6 +204,7 @@ function customConfig (): CustomConfig { shortDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION, description: CONFIG.INSTANCE.DESCRIPTION, terms: CONFIG.INSTANCE.TERMS, + isNSFW: CONFIG.INSTANCE.IS_NSFW, defaultClientRoute: CONFIG.INSTANCE.DEFAULT_CLIENT_ROUTE, defaultNSFWPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, customizations: { diff --git a/server/initializers/checker-before-init.ts b/server/initializers/checker-before-init.ts index 29fdb263e..230fdd356 100644 --- a/server/initializers/checker-before-init.ts +++ b/server/initializers/checker-before-init.ts @@ -23,7 +23,7 @@ function checkMissedConfig () { 'import.videos.http.enabled', 'import.videos.torrent.enabled', 'trending.videos.interval_days', 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route', - 'instance.default_nsfw_policy', 'instance.robots', 'instance.securitytxt', + 'instance.is_nsfw', 'instance.default_nsfw_policy', 'instance.robots', 'instance.securitytxt', 'services.twitter.username', 'services.twitter.whitelisted' ] const requiredAlternatives = [ diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index c1be7f326..bb2c6765f 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -288,6 +288,7 @@ const CONFIG = { get SHORT_DESCRIPTION () { return config.get('instance.short_description') }, get DESCRIPTION () { return config.get('instance.description') }, get TERMS () { return config.get('instance.terms') }, + get IS_NSFW () { return config.get('instance.is_nsfw') }, get DEFAULT_CLIENT_ROUTE () { return config.get('instance.default_client_route') }, get DEFAULT_NSFW_POLICY () { return config.get('instance.default_nsfw_policy') }, CUSTOMIZATIONS: { diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts index 3895c4f9a..c6b460f23 100644 --- a/server/tests/api/check-params/config.ts +++ b/server/tests/api/check-params/config.ts @@ -19,6 +19,7 @@ describe('Test config API validators', function () { shortDescription: 'my short description', description: 'my super description', terms: 'my super terms', + isNSFW: true, defaultClientRoute: '/videos/recently-added', defaultNSFWPolicy: 'blur', customizations: { diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index 3be1c9431..42927605d 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts @@ -30,6 +30,7 @@ function checkInitialConfig (data: CustomConfig) { 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.isNSFW).to.be.false expect(data.instance.defaultNSFWPolicy).to.equal('display') expect(data.instance.customizations.css).to.be.empty expect(data.instance.customizations.javascript).to.be.empty @@ -69,6 +70,7 @@ function checkUpdatedConfig (data: CustomConfig) { 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.isNSFW).to.be.true expect(data.instance.defaultNSFWPolicy).to.equal('blur') expect(data.instance.customizations.javascript).to.equal('alert("coucou")') expect(data.instance.customizations.css).to.equal('body { background-color: red; }') @@ -163,6 +165,7 @@ describe('Test config', function () { description: 'my super description', terms: 'my super terms', defaultClientRoute: '/videos/recently-added', + isNSFW: true, defaultNSFWPolicy: 'blur' as 'blur', customizations: { javascript: 'alert("coucou")', -- cgit v1.2.3