From 865df1e14365b436a275a9fdd3bebde26a227e90 Mon Sep 17 00:00:00 2001 From: naz Date: Wed, 19 Apr 2023 14:25:25 +0200 Subject: [PATCH] Added announcement fields to settings table (#16654) refs https://github.com/TryGhost/Team/issues/3011 - This is a data structure needed to support Announcement Bar feature - allows to create custom site-wide announcements tailored to the audience. - The `announcement_content` is meant to hold displayed HTML content of the announcement and will be exposed through unauthenticated Content Site API - The `announcement_visibility` sets the target audience to display the Announcement Bart to: - `public` - Everyone - `visitors` - Logged out visitors only - `members` - Members only - `paid` - Paid members only - The `announcement_background` sets the CSS class that should be applied to the Announcement Bar. and will be exposed through unauthenticated Content Site API. Three styles are available: - `accent` - matches the color of the site accent - `dark` - dark style - `light` - light style --- ...3-04-18-12-56-add-announcement-settings.js | 24 ++++++ .../default-settings/default-settings.json | 27 ++++++ .../admin/__snapshots__/settings.test.js.snap | 86 ++++++++++++++++++- .../core/test/e2e-api/admin/settings.test.js | 2 +- .../regression/models/model_settings.test.js | 2 +- .../unit/server/data/exporter/index.test.js | 2 +- .../unit/server/data/schema/integrity.test.js | 2 +- .../test/utils/fixtures/default-settings.json | 27 ++++++ 8 files changed, 167 insertions(+), 5 deletions(-) create mode 100644 ghost/core/core/server/data/migrations/versions/5.45/2023-04-18-12-56-add-announcement-settings.js diff --git a/ghost/core/core/server/data/migrations/versions/5.45/2023-04-18-12-56-add-announcement-settings.js b/ghost/core/core/server/data/migrations/versions/5.45/2023-04-18-12-56-add-announcement-settings.js new file mode 100644 index 0000000000..8cc727ba6e --- /dev/null +++ b/ghost/core/core/server/data/migrations/versions/5.45/2023-04-18-12-56-add-announcement-settings.js @@ -0,0 +1,24 @@ +const {combineTransactionalMigrations, addSetting} = require('../../utils'); + +module.exports = combineTransactionalMigrations( + addSetting({ + key: 'announcement_content', + value: null, + type: 'string', + flags: 'PUBLIC', + group: 'announcement' + }), + addSetting({ + key: 'announcement_visibility', + value: 'public', + type: 'string', + group: 'announcement' + }), + addSetting({ + key: 'announcement_background', + value: 'dark', + type: 'string', + flags: 'PUBLIC', + group: 'announcement' + }) +); diff --git a/ghost/core/core/server/data/schema/default-settings/default-settings.json b/ghost/core/core/server/data/schema/default-settings/default-settings.json index b9974cdcf8..afdccaf3cd 100644 --- a/ghost/core/core/server/data/schema/default-settings/default-settings.json +++ b/ghost/core/core/server/data/schema/default-settings/default-settings.json @@ -483,6 +483,33 @@ "type": "string" } }, + "announcement": { + "announcement_content": { + "defaultValue": null, + "type": "string", + "flags": "PUBLIC" + }, + "announcement_visibility": { + "defaultValue": "public", + "type": "string", + "isIn": [[ + "public", + "visitors", + "members", + "paid" + ]] + }, + "announcement_background": { + "defaultValue": "dark", + "type": "string", + "isIn": [[ + "accent", + "dark", + "light" + ]], + "flags": "PUBLIC" + } + }, "comments": { "comments_enabled": { "type": "string", diff --git a/ghost/core/test/e2e-api/admin/__snapshots__/settings.test.js.snap b/ghost/core/test/e2e-api/admin/__snapshots__/settings.test.js.snap index e2c42cb30e..d7a4c218cf 100644 --- a/ghost/core/test/e2e-api/admin/__snapshots__/settings.test.js.snap +++ b/ghost/core/test/e2e-api/admin/__snapshots__/settings.test.js.snap @@ -272,6 +272,18 @@ Object { "key": "editor_default_email_recipients_filter", "value": "all", }, + Object { + "key": "announcement_content", + "value": null, + }, + Object { + "key": "announcement_visibility", + "value": "public", + }, + Object { + "key": "announcement_background", + "value": "dark", + }, Object { "key": "comments_enabled", "value": "off", @@ -638,6 +650,18 @@ Object { "key": "editor_default_email_recipients_filter", "value": "all", }, + Object { + "key": "announcement_content", + "value": null, + }, + Object { + "key": "announcement_visibility", + "value": "public", + }, + Object { + "key": "announcement_background", + "value": "dark", + }, Object { "key": "comments_enabled", "value": "off", @@ -670,7 +694,7 @@ exports[`Settings API Edit Can edit a setting 2: [headers] 1`] = ` Object { "access-control-allow-origin": "http://127.0.0.1:2369", "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0", - "content-length": "3762", + "content-length": "3906", "content-type": "application/json; charset=utf-8", "content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/, "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, @@ -952,6 +976,18 @@ Object { "key": "editor_default_email_recipients_filter", "value": "all", }, + Object { + "key": "announcement_content", + "value": null, + }, + Object { + "key": "announcement_visibility", + "value": "public", + }, + Object { + "key": "announcement_background", + "value": "dark", + }, Object { "key": "comments_enabled", "value": "off", @@ -1265,6 +1301,18 @@ Object { "key": "editor_default_email_recipients_filter", "value": "all", }, + Object { + "key": "announcement_content", + "value": null, + }, + Object { + "key": "announcement_visibility", + "value": "public", + }, + Object { + "key": "announcement_background", + "value": "dark", + }, Object { "key": "comments_enabled", "value": "off", @@ -1583,6 +1631,18 @@ Object { "key": "editor_default_email_recipients_filter", "value": "all", }, + Object { + "key": "announcement_content", + "value": null, + }, + Object { + "key": "announcement_visibility", + "value": "public", + }, + Object { + "key": "announcement_background", + "value": "dark", + }, Object { "key": "comments_enabled", "value": "off", @@ -1896,6 +1956,18 @@ Object { "key": "editor_default_email_recipients_filter", "value": "all", }, + Object { + "key": "announcement_content", + "value": null, + }, + Object { + "key": "announcement_visibility", + "value": "public", + }, + Object { + "key": "announcement_background", + "value": "dark", + }, Object { "key": "comments_enabled", "value": "off", @@ -2274,6 +2346,18 @@ Object { "key": "editor_default_email_recipients_filter", "value": "all", }, + Object { + "key": "announcement_content", + "value": null, + }, + Object { + "key": "announcement_visibility", + "value": "public", + }, + Object { + "key": "announcement_background", + "value": "dark", + }, Object { "key": "comments_enabled", "value": "off", diff --git a/ghost/core/test/e2e-api/admin/settings.test.js b/ghost/core/test/e2e-api/admin/settings.test.js index c573b655df..17714d3482 100644 --- a/ghost/core/test/e2e-api/admin/settings.test.js +++ b/ghost/core/test/e2e-api/admin/settings.test.js @@ -6,7 +6,7 @@ const {stringMatching, anyEtag, anyUuid, anyContentLength, anyContentVersion} = const models = require('../../../core/server/models'); const {anyErrorId} = matchers; -const CURRENT_SETTINGS_COUNT = 73; +const CURRENT_SETTINGS_COUNT = 76; const settingsMatcher = {}; diff --git a/ghost/core/test/regression/models/model_settings.test.js b/ghost/core/test/regression/models/model_settings.test.js index b5d8c1757b..56119e703d 100644 --- a/ghost/core/test/regression/models/model_settings.test.js +++ b/ghost/core/test/regression/models/model_settings.test.js @@ -5,7 +5,7 @@ const db = require('../../../core/server/data/db'); // Stuff we are testing const models = require('../../../core/server/models'); -const SETTINGS_LENGTH = 84; +const SETTINGS_LENGTH = 87; describe('Settings Model', function () { before(models.init); diff --git a/ghost/core/test/unit/server/data/exporter/index.test.js b/ghost/core/test/unit/server/data/exporter/index.test.js index a00e9c6f91..7726f0bccc 100644 --- a/ghost/core/test/unit/server/data/exporter/index.test.js +++ b/ghost/core/test/unit/server/data/exporter/index.test.js @@ -236,7 +236,7 @@ describe('Exporter', function () { // NOTE: if default settings changed either modify the settings keys blocklist or increase allowedKeysLength // This is a reminder to think about the importer/exporter scenarios ;) - const allowedKeysLength = 76; + const allowedKeysLength = 79; totalKeysLength.should.eql(SETTING_KEYS_BLOCKLIST.length + allowedKeysLength); }); }); diff --git a/ghost/core/test/unit/server/data/schema/integrity.test.js b/ghost/core/test/unit/server/data/schema/integrity.test.js index 66f05301cc..680adc5a92 100644 --- a/ghost/core/test/unit/server/data/schema/integrity.test.js +++ b/ghost/core/test/unit/server/data/schema/integrity.test.js @@ -37,7 +37,7 @@ describe('DB version integrity', function () { // Only these variables should need updating const currentSchemaHash = '00c8616470de50a6716369511a39eca9'; const currentFixturesHash = '869ceb3302303494c645f4201540ead3'; - const currentSettingsHash = 'e2fc04c37fe89e972b063ee8fd1d4bec'; + const currentSettingsHash = '7b80d26ccced791da70ca5c753959689'; const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01'; // If this test is failing, then it is likely a change has been made that requires a DB version bump, diff --git a/ghost/core/test/utils/fixtures/default-settings.json b/ghost/core/test/utils/fixtures/default-settings.json index 7b28305695..31053d6717 100644 --- a/ghost/core/test/utils/fixtures/default-settings.json +++ b/ghost/core/test/utils/fixtures/default-settings.json @@ -491,6 +491,33 @@ "type": "string" } }, + "announcement": { + "announcement_content": { + "defaultValue": null, + "type": "string", + "flags": "PUBLIC" + }, + "announcement_visibility": { + "defaultValue": "public", + "type": "string", + "isIn": [[ + "public", + "visitors", + "members", + "paid" + ]] + }, + "announcement_background": { + "defaultValue": "dark", + "type": "string", + "isIn": [[ + "accent", + "dark", + "light" + ]], + "flags": "PUBLIC" + } + }, "comments": { "comments_enabled": { "type": "string",