diff options
author | Chocobozzz <me@florianbigard.com> | 2019-02-20 15:36:43 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-02-20 15:36:43 +0100 |
commit | f8802489bbc2c0363b5668e47de7c35f573342e1 (patch) | |
tree | 526054fad5a7f944b008ac1a6e400dfbe66a1639 | |
parent | 1aabcae7e36bb113c2887bd7180dad2916ecaaf2 (diff) | |
download | PeerTube-f8802489bbc2c0363b5668e47de7c35f573342e1.tar.gz PeerTube-f8802489bbc2c0363b5668e47de7c35f573342e1.tar.zst PeerTube-f8802489bbc2c0363b5668e47de7c35f573342e1.zip |
Add isNSFW instance configuration key
-rw-r--r-- | client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.html | 9 | ||||
-rw-r--r-- | client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts | 1 | ||||
-rw-r--r-- | client/src/app/core/server/server.service.ts | 2 | ||||
-rw-r--r-- | client/src/app/videos/+video-edit/video-add-components/video-upload.component.ts | 2 | ||||
-rw-r--r-- | config/default.yaml | 4 | ||||
-rw-r--r-- | config/production.yaml.example | 4 | ||||
-rw-r--r-- | server/controllers/api/config.ts | 10 | ||||
-rw-r--r-- | server/initializers/checker-before-init.ts | 2 | ||||
-rw-r--r-- | server/initializers/constants.ts | 1 | ||||
-rw-r--r-- | server/tests/api/check-params/config.ts | 1 | ||||
-rw-r--r-- | server/tests/api/server/config.ts | 3 | ||||
-rw-r--r-- | shared/models/server/custom-config.model.ts | 1 | ||||
-rw-r--r-- | shared/models/server/server-config.model.ts | 1 | ||||
-rw-r--r-- | 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 | |||
@@ -45,6 +45,15 @@ | |||
45 | </div> | 45 | </div> |
46 | 46 | ||
47 | <div class="form-group"> | 47 | <div class="form-group"> |
48 | <my-peertube-checkbox | ||
49 | inputName="instanceIsNSFW" formControlName="isNSFW" | ||
50 | i18n-labelText labelText="Dedicated to sensitive or NSFW content" | ||
51 | i18n-helpHtml helpHtml="Enabling it will allow other administrators to know that you are mainly federating sensitive content.<br /><br /> | ||
52 | Moreover, the NSFW checkbox on video upload will be automatically checked by default." | ||
53 | ></my-peertube-checkbox> | ||
54 | </div> | ||
55 | |||
56 | <div class="form-group"> | ||
48 | <label i18n for="instanceDefaultClientRoute">Default client route</label> | 57 | <label i18n for="instanceDefaultClientRoute">Default client route</label> |
49 | <div class="peertube-select-container"> | 58 | <div class="peertube-select-container"> |
50 | <select id="instanceDefaultClientRoute" formControlName="defaultClientRoute"> | 59 | <select id="instanceDefaultClientRoute" formControlName="defaultClientRoute"> |
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 { | |||
66 | description: null, | 66 | description: null, |
67 | terms: null, | 67 | terms: null, |
68 | defaultClientRoute: null, | 68 | defaultClientRoute: null, |
69 | isNSFW: false, | ||
69 | defaultNSFWPolicy: null, | 70 | defaultNSFWPolicy: null, |
70 | customizations: { | 71 | customizations: { |
71 | javascript: null, | 72 | 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' | |||
4 | import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage' | 4 | import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage' |
5 | import { Observable, of, ReplaySubject } from 'rxjs' | 5 | import { Observable, of, ReplaySubject } from 'rxjs' |
6 | import { getCompleteLocale, ServerConfig } from '../../../../../shared' | 6 | import { getCompleteLocale, ServerConfig } from '../../../../../shared' |
7 | import { About } from '../../../../../shared/models/server/about.model' | ||
8 | import { environment } from '../../../environments/environment' | 7 | import { environment } from '../../../environments/environment' |
9 | import { VideoConstant, VideoPrivacy } from '../../../../../shared/models/videos' | 8 | import { VideoConstant, VideoPrivacy } from '../../../../../shared/models/videos' |
10 | import { isDefaultLocale, peertubeTranslate } from '../../../../../shared/models/i18n' | 9 | import { isDefaultLocale, peertubeTranslate } from '../../../../../shared/models/i18n' |
@@ -32,6 +31,7 @@ export class ServerService { | |||
32 | shortDescription: 'PeerTube, a federated (ActivityPub) video streaming platform ' + | 31 | shortDescription: 'PeerTube, a federated (ActivityPub) video streaming platform ' + |
33 | 'using P2P (BitTorrent) directly in the web browser with WebTorrent and Angular.', | 32 | 'using P2P (BitTorrent) directly in the web browser with WebTorrent and Angular.', |
34 | defaultClientRoute: '', | 33 | defaultClientRoute: '', |
34 | isNSFW: false, | ||
35 | defaultNSFWPolicy: 'do_not_list' as 'do_not_list', | 35 | defaultNSFWPolicy: 'do_not_list' as 'do_not_list', |
36 | customizations: { | 36 | customizations: { |
37 | javascript: '', | 37 | 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 | |||
163 | } | 163 | } |
164 | 164 | ||
165 | const privacy = this.firstStepPrivacyId.toString() | 165 | const privacy = this.firstStepPrivacyId.toString() |
166 | const nsfw = false | 166 | const nsfw = this.serverService.getConfig().instance.isNSFW |
167 | const waitTranscoding = true | 167 | const waitTranscoding = true |
168 | const commentsEnabled = true | 168 | const commentsEnabled = true |
169 | const downloadEnabled = true | 169 | 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: | |||
163 | description: 'Welcome to this PeerTube instance!' # Support markdown | 163 | description: 'Welcome to this PeerTube instance!' # Support markdown |
164 | terms: 'No terms for now.' # Support markdown | 164 | terms: 'No terms for now.' # Support markdown |
165 | default_client_route: '/videos/trending' | 165 | default_client_route: '/videos/trending' |
166 | # Whether or not the instance is dedicated to NSFW content | ||
167 | # Enabling it will allow other administrators to know that you are mainly federating sensitive content | ||
168 | # Moreover, the NSFW checkbox on video upload will be automatically checked by default | ||
169 | is_nsfw: false | ||
166 | # By default, "do_not_list" or "blur" or "display" NSFW videos | 170 | # By default, "do_not_list" or "blur" or "display" NSFW videos |
167 | # Could be overridden per user with a setting | 171 | # Could be overridden per user with a setting |
168 | default_nsfw_policy: 'do_not_list' | 172 | 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: | |||
177 | description: '' # Support markdown | 177 | description: '' # Support markdown |
178 | terms: '' # Support markdown | 178 | terms: '' # Support markdown |
179 | default_client_route: '/videos/trending' | 179 | default_client_route: '/videos/trending' |
180 | # Whether or not the instance is dedicated to NSFW content | ||
181 | # Enabling it will allow other administrators to know that you are mainly federating sensitive content | ||
182 | # Moreover, the NSFW checkbox on video upload will be automatically checked by default | ||
183 | is_nsfw: false | ||
180 | # By default, "do_not_list" or "blur" or "display" NSFW videos | 184 | # By default, "do_not_list" or "blur" or "display" NSFW videos |
181 | # Could be overridden per user with a setting | 185 | # Could be overridden per user with a setting |
182 | default_nsfw_policy: 'do_not_list' | 186 | 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) { | |||
58 | name: CONFIG.INSTANCE.NAME, | 58 | name: CONFIG.INSTANCE.NAME, |
59 | shortDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION, | 59 | shortDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION, |
60 | defaultClientRoute: CONFIG.INSTANCE.DEFAULT_CLIENT_ROUTE, | 60 | defaultClientRoute: CONFIG.INSTANCE.DEFAULT_CLIENT_ROUTE, |
61 | isNSFW: CONFIG.INSTANCE.IS_NSFW, | ||
61 | defaultNSFWPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, | 62 | defaultNSFWPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, |
62 | customizations: { | 63 | customizations: { |
63 | javascript: CONFIG.INSTANCE.CUSTOMIZATIONS.JAVASCRIPT, | 64 | javascript: CONFIG.INSTANCE.CUSTOMIZATIONS.JAVASCRIPT, |
@@ -134,7 +135,7 @@ async function getConfig (req: express.Request, res: express.Response) { | |||
134 | return res.json(json) | 135 | return res.json(json) |
135 | } | 136 | } |
136 | 137 | ||
137 | function getAbout (req: express.Request, res: express.Response, next: express.NextFunction) { | 138 | function getAbout (req: express.Request, res: express.Response) { |
138 | const about: About = { | 139 | const about: About = { |
139 | instance: { | 140 | instance: { |
140 | name: CONFIG.INSTANCE.NAME, | 141 | name: CONFIG.INSTANCE.NAME, |
@@ -147,13 +148,13 @@ function getAbout (req: express.Request, res: express.Response, next: express.Ne | |||
147 | return res.json(about).end() | 148 | return res.json(about).end() |
148 | } | 149 | } |
149 | 150 | ||
150 | async function getCustomConfig (req: express.Request, res: express.Response, next: express.NextFunction) { | 151 | async function getCustomConfig (req: express.Request, res: express.Response) { |
151 | const data = customConfig() | 152 | const data = customConfig() |
152 | 153 | ||
153 | return res.json(data).end() | 154 | return res.json(data).end() |
154 | } | 155 | } |
155 | 156 | ||
156 | async function deleteCustomConfig (req: express.Request, res: express.Response, next: express.NextFunction) { | 157 | async function deleteCustomConfig (req: express.Request, res: express.Response) { |
157 | await remove(CONFIG.CUSTOM_FILE) | 158 | await remove(CONFIG.CUSTOM_FILE) |
158 | 159 | ||
159 | auditLogger.delete(getAuditIdFromRes(res), new CustomConfigAuditView(customConfig())) | 160 | auditLogger.delete(getAuditIdFromRes(res), new CustomConfigAuditView(customConfig())) |
@@ -166,7 +167,7 @@ async function deleteCustomConfig (req: express.Request, res: express.Response, | |||
166 | return res.json(data).end() | 167 | return res.json(data).end() |
167 | } | 168 | } |
168 | 169 | ||
169 | async function updateCustomConfig (req: express.Request, res: express.Response, next: express.NextFunction) { | 170 | async function updateCustomConfig (req: express.Request, res: express.Response) { |
170 | const oldCustomConfigAuditKeys = new CustomConfigAuditView(customConfig()) | 171 | const oldCustomConfigAuditKeys = new CustomConfigAuditView(customConfig()) |
171 | 172 | ||
172 | // camelCase to snake_case key + Force number conversion | 173 | // camelCase to snake_case key + Force number conversion |
@@ -203,6 +204,7 @@ function customConfig (): CustomConfig { | |||
203 | shortDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION, | 204 | shortDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION, |
204 | description: CONFIG.INSTANCE.DESCRIPTION, | 205 | description: CONFIG.INSTANCE.DESCRIPTION, |
205 | terms: CONFIG.INSTANCE.TERMS, | 206 | terms: CONFIG.INSTANCE.TERMS, |
207 | isNSFW: CONFIG.INSTANCE.IS_NSFW, | ||
206 | defaultClientRoute: CONFIG.INSTANCE.DEFAULT_CLIENT_ROUTE, | 208 | defaultClientRoute: CONFIG.INSTANCE.DEFAULT_CLIENT_ROUTE, |
207 | defaultNSFWPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, | 209 | defaultNSFWPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, |
208 | customizations: { | 210 | 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 () { | |||
23 | 'import.videos.http.enabled', 'import.videos.torrent.enabled', | 23 | 'import.videos.http.enabled', 'import.videos.torrent.enabled', |
24 | 'trending.videos.interval_days', | 24 | 'trending.videos.interval_days', |
25 | 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route', | 25 | 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route', |
26 | 'instance.default_nsfw_policy', 'instance.robots', 'instance.securitytxt', | 26 | 'instance.is_nsfw', 'instance.default_nsfw_policy', 'instance.robots', 'instance.securitytxt', |
27 | 'services.twitter.username', 'services.twitter.whitelisted' | 27 | 'services.twitter.username', 'services.twitter.whitelisted' |
28 | ] | 28 | ] |
29 | const requiredAlternatives = [ | 29 | 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 = { | |||
288 | get SHORT_DESCRIPTION () { return config.get<string>('instance.short_description') }, | 288 | get SHORT_DESCRIPTION () { return config.get<string>('instance.short_description') }, |
289 | get DESCRIPTION () { return config.get<string>('instance.description') }, | 289 | get DESCRIPTION () { return config.get<string>('instance.description') }, |
290 | get TERMS () { return config.get<string>('instance.terms') }, | 290 | get TERMS () { return config.get<string>('instance.terms') }, |
291 | get IS_NSFW () { return config.get<boolean>('instance.is_nsfw') }, | ||
291 | get DEFAULT_CLIENT_ROUTE () { return config.get<string>('instance.default_client_route') }, | 292 | get DEFAULT_CLIENT_ROUTE () { return config.get<string>('instance.default_client_route') }, |
292 | get DEFAULT_NSFW_POLICY () { return config.get<NSFWPolicyType>('instance.default_nsfw_policy') }, | 293 | get DEFAULT_NSFW_POLICY () { return config.get<NSFWPolicyType>('instance.default_nsfw_policy') }, |
293 | CUSTOMIZATIONS: { | 294 | 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 () { | |||
19 | shortDescription: 'my short description', | 19 | shortDescription: 'my short description', |
20 | description: 'my super description', | 20 | description: 'my super description', |
21 | terms: 'my super terms', | 21 | terms: 'my super terms', |
22 | isNSFW: true, | ||
22 | defaultClientRoute: '/videos/recently-added', | 23 | defaultClientRoute: '/videos/recently-added', |
23 | defaultNSFWPolicy: 'blur', | 24 | defaultNSFWPolicy: 'blur', |
24 | customizations: { | 25 | 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) { | |||
30 | expect(data.instance.description).to.equal('Welcome to this PeerTube instance!') | 30 | expect(data.instance.description).to.equal('Welcome to this PeerTube instance!') |
31 | expect(data.instance.terms).to.equal('No terms for now.') | 31 | expect(data.instance.terms).to.equal('No terms for now.') |
32 | expect(data.instance.defaultClientRoute).to.equal('/videos/trending') | 32 | expect(data.instance.defaultClientRoute).to.equal('/videos/trending') |
33 | expect(data.instance.isNSFW).to.be.false | ||
33 | expect(data.instance.defaultNSFWPolicy).to.equal('display') | 34 | expect(data.instance.defaultNSFWPolicy).to.equal('display') |
34 | expect(data.instance.customizations.css).to.be.empty | 35 | expect(data.instance.customizations.css).to.be.empty |
35 | expect(data.instance.customizations.javascript).to.be.empty | 36 | expect(data.instance.customizations.javascript).to.be.empty |
@@ -69,6 +70,7 @@ function checkUpdatedConfig (data: CustomConfig) { | |||
69 | expect(data.instance.description).to.equal('my super description') | 70 | expect(data.instance.description).to.equal('my super description') |
70 | expect(data.instance.terms).to.equal('my super terms') | 71 | expect(data.instance.terms).to.equal('my super terms') |
71 | expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added') | 72 | expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added') |
73 | expect(data.instance.isNSFW).to.be.true | ||
72 | expect(data.instance.defaultNSFWPolicy).to.equal('blur') | 74 | expect(data.instance.defaultNSFWPolicy).to.equal('blur') |
73 | expect(data.instance.customizations.javascript).to.equal('alert("coucou")') | 75 | expect(data.instance.customizations.javascript).to.equal('alert("coucou")') |
74 | expect(data.instance.customizations.css).to.equal('body { background-color: red; }') | 76 | expect(data.instance.customizations.css).to.equal('body { background-color: red; }') |
@@ -163,6 +165,7 @@ describe('Test config', function () { | |||
163 | description: 'my super description', | 165 | description: 'my super description', |
164 | terms: 'my super terms', | 166 | terms: 'my super terms', |
165 | defaultClientRoute: '/videos/recently-added', | 167 | defaultClientRoute: '/videos/recently-added', |
168 | isNSFW: true, | ||
166 | defaultNSFWPolicy: 'blur' as 'blur', | 169 | defaultNSFWPolicy: 'blur' as 'blur', |
167 | customizations: { | 170 | customizations: { |
168 | javascript: 'alert("coucou")', | 171 | 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 { | |||
6 | shortDescription: string | 6 | shortDescription: string |
7 | description: string | 7 | description: string |
8 | terms: string | 8 | terms: string |
9 | isNSFW: boolean | ||
9 | defaultClientRoute: string | 10 | defaultClientRoute: string |
10 | defaultNSFWPolicy: NSFWPolicyType | 11 | defaultNSFWPolicy: NSFWPolicyType |
11 | customizations: { | 12 | 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 { | |||
8 | name: string | 8 | name: string |
9 | shortDescription: string | 9 | shortDescription: string |
10 | defaultClientRoute: string | 10 | defaultClientRoute: string |
11 | isNSFW: boolean | ||
11 | defaultNSFWPolicy: NSFWPolicyType | 12 | defaultNSFWPolicy: NSFWPolicyType |
12 | customizations: { | 13 | customizations: { |
13 | javascript: string | 14 | 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) { | |||
52 | description: 'my super description', | 52 | description: 'my super description', |
53 | terms: 'my super terms', | 53 | terms: 'my super terms', |
54 | defaultClientRoute: '/videos/recently-added', | 54 | defaultClientRoute: '/videos/recently-added', |
55 | isNSFW: true, | ||
55 | defaultNSFWPolicy: 'blur', | 56 | defaultNSFWPolicy: 'blur', |
56 | customizations: { | 57 | customizations: { |
57 | javascript: 'alert("coucou")', | 58 | javascript: 'alert("coucou")', |