diff --git a/core/server/data/exporter/table-lists.js b/core/server/data/exporter/table-lists.js index 3288be9f6d..3db3b78944 100644 --- a/core/server/data/exporter/table-lists.js +++ b/core/server/data/exporter/table-lists.js @@ -63,7 +63,8 @@ const SETTING_KEYS_BLOCKLIST = [ 'members_stripe_webhook_id', 'members_stripe_webhook_secret', 'oauth_client_id', - 'oauth_client_secret' + 'oauth_client_secret', + 'email_verification_required' ]; module.exports = { diff --git a/core/server/data/migrations/versions/4.11/02-add-email-verification-required-setting.js b/core/server/data/migrations/versions/4.11/02-add-email-verification-required-setting.js new file mode 100644 index 0000000000..1114a80077 --- /dev/null +++ b/core/server/data/migrations/versions/4.11/02-add-email-verification-required-setting.js @@ -0,0 +1,43 @@ +const ObjectID = require('bson-objectid'); +const logging = require('@tryghost/logging'); +const {createTransactionalMigration} = require('../../utils.js'); + +const MIGRATION_USER = 1; + +module.exports = createTransactionalMigration( + async function up(knex) { + const settingExists = await knex('settings') + .where('key', '=', 'email_verification_required') + .first(); + + if (!settingExists) { + logging.info('Adding "email_verification_required" record to "settings" table'); + + const now = knex.raw('CURRENT_TIMESTAMP'); + + await knex('settings') + .insert({ + id: ObjectID().toHexString(), + key: 'email_verification_required', + value: 'false', + group: 'email', + type: 'boolean', + flags: 'RO', + created_at: now, + created_by: MIGRATION_USER, + updated_at: now, + updated_by: MIGRATION_USER + }); + } else { + logging.warn('Skipped adding "email_verification_required" record to "settings" table. Record already exists!'); + } + }, + + async function down(knex) { + logging.info('Removing "email_verification_required" record from "settings" table'); + + await knex('settings') + .where('key', '=', 'email_verification_required') + .del(); + } +); diff --git a/core/server/data/schema/default-settings.json b/core/server/data/schema/default-settings.json index f2d4ddee91..7c316ab059 100644 --- a/core/server/data/schema/default-settings.json +++ b/core/server/data/schema/default-settings.json @@ -384,6 +384,15 @@ "isIn": [["true", "false"]] }, "type": "boolean" + }, + "email_verification_required": { + "defaultValue": "false", + "validations": { + "isEmpty": false, + "isIn": [["true", "false"]] + }, + "type": "boolean", + "flags": "RO" } }, "amp": { diff --git a/test/regression/api/canary/admin/settings.test.js b/test/regression/api/canary/admin/settings.test.js index fb815f7b96..7b1d17a29a 100644 --- a/test/regression/api/canary/admin/settings.test.js +++ b/test/regression/api/canary/admin/settings.test.js @@ -295,6 +295,11 @@ const defaultSettingsKeyTypes = [ type: 'boolean', group: 'email' }, + { + key: 'email_verification_required', + type: 'boolean', + group: 'email' + }, { key: 'amp', type: 'boolean', diff --git a/test/regression/api/v2/admin/settings.test.js b/test/regression/api/v2/admin/settings.test.js index 5ef0032be9..0be1e42a28 100644 --- a/test/regression/api/v2/admin/settings.test.js +++ b/test/regression/api/v2/admin/settings.test.js @@ -86,7 +86,8 @@ const defaultSettingsKeyTypes = [ {key: 'oauth_client_secret', type: 'oauth'}, {key: 'editor_default_email_recipients', type: 'editor'}, {key: 'editor_default_email_recipients_filter', type: 'editor'}, - {key: 'labs', type: 'blog'} + {key: 'labs', type: 'blog'}, + {key: 'email_verification_required', type: 'bulk_email'} ]; describe('Settings API (v2)', function () { diff --git a/test/regression/api/v3/admin/settings.test.js b/test/regression/api/v3/admin/settings.test.js index 4b50b8b905..26e5c22be2 100644 --- a/test/regression/api/v3/admin/settings.test.js +++ b/test/regression/api/v3/admin/settings.test.js @@ -90,7 +90,8 @@ const defaultSettingsKeyTypes = [ {key: 'oauth_client_secret', type: 'oauth'}, {key: 'editor_default_email_recipients', type: 'editor'}, {key: 'editor_default_email_recipients_filter', type: 'editor'}, - {key: 'labs', type: 'blog'} + {key: 'labs', type: 'blog'}, + {key: 'email_verification_required', type: 'bulk_email'} ]; describe('Settings API (v3)', function () { diff --git a/test/unit/data/schema/integrity.test.js b/test/unit/data/schema/integrity.test.js index 10bb7c9dc6..61eaa269bb 100644 --- a/test/unit/data/schema/integrity.test.js +++ b/test/unit/data/schema/integrity.test.js @@ -34,7 +34,7 @@ describe('DB version integrity', function () { // Only these variables should need updating const currentSchemaHash = 'a2248eaa72a9d08c3753b90a9436dbe3'; const currentFixturesHash = '97283c575b1f6c84c27db6e1b1be21d4'; - const currentSettingsHash = 'dd0a0a08e66b252e7704bb7e346a8c20'; + const currentSettingsHash = 'aa3fcbc8ab119b630aeda7366ead5493'; const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01'; // If this test is failing, then it is likely a change has been made that requires a DB version bump,