From f8802489bbc2c0363b5668e47de7c35f573342e1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 20 Feb 2019 15:36:43 +0100 Subject: [PATCH] Add isNSFW instance configuration key --- .../edit-custom-config.component.html | 9 +++++++++ .../edit-custom-config/edit-custom-config.component.ts | 1 + client/src/app/core/server/server.service.ts | 2 +- .../video-add-components/video-upload.component.ts | 2 +- config/default.yaml | 4 ++++ config/production.yaml.example | 4 ++++ 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 +++ shared/models/server/custom-config.model.ts | 1 + shared/models/server/server-config.model.ts | 1 + shared/utils/server/config.ts | 1 + 14 files changed, 35 insertions(+), 7 deletions(-) diff --git a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.html b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.html index 52eb00d93..b7d95bc22 100644 --- a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.html +++ b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.html @@ -44,6 +44,15 @@
{{ formErrors.instance.terms }}
+
+ +
+
diff --git a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts index 654a076b0..45605e0fe 100644 --- a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts +++ b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts @@ -66,6 +66,7 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { description: null, terms: null, defaultClientRoute: null, + isNSFW: false, defaultNSFWPolicy: null, customizations: { javascript: null, diff --git a/client/src/app/core/server/server.service.ts b/client/src/app/core/server/server.service.ts index c868ccdcc..10acf6e72 100644 --- a/client/src/app/core/server/server.service.ts +++ b/client/src/app/core/server/server.service.ts @@ -4,7 +4,6 @@ import { Inject, Injectable, LOCALE_ID } from '@angular/core' import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage' import { Observable, of, ReplaySubject } from 'rxjs' import { getCompleteLocale, ServerConfig } from '../../../../../shared' -import { About } from '../../../../../shared/models/server/about.model' import { environment } from '../../../environments/environment' import { VideoConstant, VideoPrivacy } from '../../../../../shared/models/videos' import { isDefaultLocale, peertubeTranslate } from '../../../../../shared/models/i18n' @@ -32,6 +31,7 @@ export class ServerService { shortDescription: 'PeerTube, a federated (ActivityPub) video streaming platform ' + 'using P2P (BitTorrent) directly in the web browser with WebTorrent and Angular.', defaultClientRoute: '', + isNSFW: false, defaultNSFWPolicy: 'do_not_list' as 'do_not_list', customizations: { javascript: '', diff --git a/client/src/app/videos/+video-edit/video-add-components/video-upload.component.ts b/client/src/app/videos/+video-edit/video-add-components/video-upload.component.ts index 9cadf52cb..7399f39ee 100644 --- a/client/src/app/videos/+video-edit/video-add-components/video-upload.component.ts +++ b/client/src/app/videos/+video-edit/video-add-components/video-upload.component.ts @@ -163,7 +163,7 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy } const privacy = this.firstStepPrivacyId.toString() - const nsfw = false + const nsfw = this.serverService.getConfig().instance.isNSFW const waitTranscoding = true const commentsEnabled = true const downloadEnabled = true diff --git a/config/default.yaml b/config/default.yaml index 7af615a82..1f6046a1b 100644 --- a/config/default.yaml +++ b/config/default.yaml @@ -163,6 +163,10 @@ instance: description: 'Welcome to this PeerTube instance!' # Support markdown terms: 'No terms for now.' # Support markdown default_client_route: '/videos/trending' + # Whether or not the instance is dedicated to NSFW content + # Enabling it will allow other administrators to know that you are mainly federating sensitive content + # Moreover, the NSFW checkbox on video upload will be automatically checked by default + is_nsfw: false # By default, "do_not_list" or "blur" or "display" NSFW videos # Could be overridden per user with a setting default_nsfw_policy: 'do_not_list' diff --git a/config/production.yaml.example b/config/production.yaml.example index 413e3c478..ae8fb2d51 100644 --- a/config/production.yaml.example +++ b/config/production.yaml.example @@ -177,6 +177,10 @@ instance: description: '' # Support markdown terms: '' # Support markdown default_client_route: '/videos/trending' + # Whether or not the instance is dedicated to NSFW content + # Enabling it will allow other administrators to know that you are mainly federating sensitive content + # Moreover, the NSFW checkbox on video upload will be automatically checked by default + is_nsfw: false # By default, "do_not_list" or "blur" or "display" NSFW videos # Could be overridden per user with a setting default_nsfw_policy: 'do_not_list' 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")', diff --git a/shared/models/server/custom-config.model.ts b/shared/models/server/custom-config.model.ts index b42ff90c6..20b261426 100644 --- a/shared/models/server/custom-config.model.ts +++ b/shared/models/server/custom-config.model.ts @@ -6,6 +6,7 @@ export interface CustomConfig { shortDescription: string description: string terms: string + isNSFW: boolean defaultClientRoute: string defaultNSFWPolicy: NSFWPolicyType customizations: { diff --git a/shared/models/server/server-config.model.ts b/shared/models/server/server-config.model.ts index baafed31f..0200d88ca 100644 --- a/shared/models/server/server-config.model.ts +++ b/shared/models/server/server-config.model.ts @@ -8,6 +8,7 @@ export interface ServerConfig { name: string shortDescription: string defaultClientRoute: string + isNSFW: boolean defaultNSFWPolicy: NSFWPolicyType customizations: { javascript: string diff --git a/shared/utils/server/config.ts b/shared/utils/server/config.ts index 29c24cff9..0e16af0f2 100644 --- a/shared/utils/server/config.ts +++ b/shared/utils/server/config.ts @@ -52,6 +52,7 @@ function updateCustomSubConfig (url: string, token: string, newConfig: any) { description: 'my super description', terms: 'my super terms', defaultClientRoute: '/videos/recently-added', + isNSFW: true, defaultNSFWPolicy: 'blur', customizations: { javascript: 'alert("coucou")', -- 2.25.1