diff options
Diffstat (limited to 'server/initializers')
-rw-r--r-- | server/initializers/checker.ts | 11 | ||||
-rw-r--r-- | server/initializers/constants.ts | 11 | ||||
-rw-r--r-- | server/initializers/installer.ts | 1 | ||||
-rw-r--r-- | server/initializers/migrations/0205-user-nsfw-policy.ts | 46 |
4 files changed, 63 insertions, 6 deletions
diff --git a/server/initializers/checker.ts b/server/initializers/checker.ts index 71f303963..739f623c6 100644 --- a/server/initializers/checker.ts +++ b/server/initializers/checker.ts | |||
@@ -5,12 +5,12 @@ import { ApplicationModel } from '../models/application/application' | |||
5 | import { OAuthClientModel } from '../models/oauth/oauth-client' | 5 | import { OAuthClientModel } from '../models/oauth/oauth-client' |
6 | 6 | ||
7 | // Some checks on configuration files | 7 | // Some checks on configuration files |
8 | // Return an error message, or null if everything is okay | ||
8 | function checkConfig () { | 9 | function checkConfig () { |
9 | if (config.has('webserver.host')) { | 10 | const defaultNSFWPolicy = config.get<string>('instance.default_nsfw_policy') |
10 | let errorMessage = '`host` config key was renamed to `hostname` but it seems you still have a `host` key in your configuration files!' | ||
11 | errorMessage += ' Please ensure to rename your `host` configuration to `hostname`.' | ||
12 | 11 | ||
13 | return errorMessage | 12 | if ([ 'do_not_list', 'blur', 'display' ].indexOf(defaultNSFWPolicy) === -1) { |
13 | return 'NSFW policy setting should be "do_not_list" or "blur" or "display" instead of ' + defaultNSFWPolicy | ||
14 | } | 14 | } |
15 | 15 | ||
16 | return null | 16 | return null |
@@ -28,7 +28,8 @@ function checkMissedConfig () { | |||
28 | 'log.level', | 28 | 'log.level', |
29 | 'user.video_quota', | 29 | 'user.video_quota', |
30 | 'cache.previews.size', 'admin.email', 'signup.enabled', 'signup.limit', 'transcoding.enabled', 'transcoding.threads', | 30 | 'cache.previews.size', 'admin.email', 'signup.enabled', 'signup.limit', 'transcoding.enabled', 'transcoding.threads', |
31 | 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route' | 31 | 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route', |
32 | 'instance.default_nsfw_policy' | ||
32 | ] | 33 | ] |
33 | const miss: string[] = [] | 34 | const miss: string[] = [] |
34 | 35 | ||
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 5ee13389d..d1915586a 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -6,13 +6,14 @@ import { FollowState } from '../../shared/models/actors' | |||
6 | import { VideoPrivacy } from '../../shared/models/videos' | 6 | import { VideoPrivacy } from '../../shared/models/videos' |
7 | // Do not use barrels, remain constants as independent as possible | 7 | // Do not use barrels, remain constants as independent as possible |
8 | import { buildPath, isTestInstance, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' | 8 | import { buildPath, isTestInstance, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' |
9 | import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' | ||
9 | 10 | ||
10 | // Use a variable to reload the configuration if we need | 11 | // Use a variable to reload the configuration if we need |
11 | let config: IConfig = require('config') | 12 | let config: IConfig = require('config') |
12 | 13 | ||
13 | // --------------------------------------------------------------------------- | 14 | // --------------------------------------------------------------------------- |
14 | 15 | ||
15 | const LAST_MIGRATION_VERSION = 200 | 16 | const LAST_MIGRATION_VERSION = 205 |
16 | 17 | ||
17 | // --------------------------------------------------------------------------- | 18 | // --------------------------------------------------------------------------- |
18 | 19 | ||
@@ -167,6 +168,7 @@ const CONFIG = { | |||
167 | get DESCRIPTION () { return config.get<string>('instance.description') }, | 168 | get DESCRIPTION () { return config.get<string>('instance.description') }, |
168 | get TERMS () { return config.get<string>('instance.terms') }, | 169 | get TERMS () { return config.get<string>('instance.terms') }, |
169 | get DEFAULT_CLIENT_ROUTE () { return config.get<string>('instance.default_client_route') }, | 170 | get DEFAULT_CLIENT_ROUTE () { return config.get<string>('instance.default_client_route') }, |
171 | get DEFAULT_NSFW_POLICY () { return config.get<NSFWPolicyType>('instance.default_nsfw_policy') }, | ||
170 | CUSTOMIZATIONS: { | 172 | CUSTOMIZATIONS: { |
171 | get JAVASCRIPT () { return config.get<string>('instance.customizations.javascript') }, | 173 | get JAVASCRIPT () { return config.get<string>('instance.customizations.javascript') }, |
172 | get CSS () { return config.get<string>('instance.customizations.css') } | 174 | get CSS () { return config.get<string>('instance.customizations.css') } |
@@ -378,6 +380,12 @@ const BCRYPT_SALT_SIZE = 10 | |||
378 | 380 | ||
379 | const USER_PASSWORD_RESET_LIFETIME = 60000 * 5 // 5 minutes | 381 | const USER_PASSWORD_RESET_LIFETIME = 60000 * 5 // 5 minutes |
380 | 382 | ||
383 | const NSFW_POLICY_TYPES: { [ id: string]: NSFWPolicyType } = { | ||
384 | DO_NOT_LIST: 'do_not_list', | ||
385 | BLUR: 'blur', | ||
386 | DISPLAY: 'display' | ||
387 | } | ||
388 | |||
381 | // --------------------------------------------------------------------------- | 389 | // --------------------------------------------------------------------------- |
382 | 390 | ||
383 | // Express static paths (router) | 391 | // Express static paths (router) |
@@ -474,6 +482,7 @@ export { | |||
474 | PRIVATE_RSA_KEY_SIZE, | 482 | PRIVATE_RSA_KEY_SIZE, |
475 | SORTABLE_COLUMNS, | 483 | SORTABLE_COLUMNS, |
476 | FEEDS, | 484 | FEEDS, |
485 | NSFW_POLICY_TYPES, | ||
477 | STATIC_MAX_AGE, | 486 | STATIC_MAX_AGE, |
478 | STATIC_PATHS, | 487 | STATIC_PATHS, |
479 | ACTIVITY_PUB, | 488 | ACTIVITY_PUB, |
diff --git a/server/initializers/installer.ts b/server/initializers/installer.ts index 09c6d5473..b0084b368 100644 --- a/server/initializers/installer.ts +++ b/server/initializers/installer.ts | |||
@@ -120,6 +120,7 @@ async function createOAuthAdminIfNotExist () { | |||
120 | email, | 120 | email, |
121 | password, | 121 | password, |
122 | role, | 122 | role, |
123 | nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, | ||
123 | videoQuota: -1 | 124 | videoQuota: -1 |
124 | } | 125 | } |
125 | const user = new UserModel(userData) | 126 | const user = new UserModel(userData) |
diff --git a/server/initializers/migrations/0205-user-nsfw-policy.ts b/server/initializers/migrations/0205-user-nsfw-policy.ts new file mode 100644 index 000000000..d0f6e8962 --- /dev/null +++ b/server/initializers/migrations/0205-user-nsfw-policy.ts | |||
@@ -0,0 +1,46 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | |||
3 | async function up (utils: { | ||
4 | transaction: Sequelize.Transaction, | ||
5 | queryInterface: Sequelize.QueryInterface, | ||
6 | sequelize: Sequelize.Sequelize | ||
7 | }): Promise<void> { | ||
8 | |||
9 | { | ||
10 | const data = { | ||
11 | type: Sequelize.ENUM('do_not_list', 'blur', 'display'), | ||
12 | allowNull: true, | ||
13 | defaultValue: null | ||
14 | } | ||
15 | await utils.queryInterface.addColumn('user', 'nsfwPolicy', data) | ||
16 | } | ||
17 | |||
18 | { | ||
19 | const query = 'UPDATE "user" SET "nsfwPolicy" = \'do_not_list\'' | ||
20 | await utils.sequelize.query(query) | ||
21 | } | ||
22 | |||
23 | { | ||
24 | const query = 'UPDATE "user" SET "nsfwPolicy" = \'display\' WHERE "displayNSFW" = true' | ||
25 | await utils.sequelize.query(query) | ||
26 | } | ||
27 | |||
28 | { | ||
29 | const query = 'ALTER TABLE "user" ALTER COLUMN "nsfwPolicy" SET NOT NULL' | ||
30 | await utils.sequelize.query(query) | ||
31 | } | ||
32 | |||
33 | { | ||
34 | await utils.queryInterface.removeColumn('user', 'displayNSFW') | ||
35 | } | ||
36 | |||
37 | } | ||
38 | |||
39 | function down (options) { | ||
40 | throw new Error('Not implemented.') | ||
41 | } | ||
42 | |||
43 | export { | ||
44 | up, | ||
45 | down | ||
46 | } | ||