Removed backwards compatibility for ghost_head and ghost_foot settings

refs https://github.com/TryGhost/Toolbox/issues/308

- these two settings are deprecated and we're removing all the code in
  v5 that kept supporting them
This commit is contained in:
Daniel Lockyer 2022-04-27 11:16:10 +01:00
parent 3b6cdc2bc5
commit ae13b61cb0
No known key found for this signature in database
GPG Key ID: D21186F0B47295AD
6 changed files with 4 additions and 82 deletions

View File

@ -71,14 +71,6 @@ module.exports = {
},
read(apiConfig, frame) {
if (frame.options.key === 'ghost_head') {
frame.options.key = 'codeinjection_head';
}
if (frame.options.key === 'ghost_foot') {
frame.options.key = 'codeinjection_foot';
}
if (frame.options.key === 'active_timezone') {
frame.options.key = 'timezone';
}
@ -141,14 +133,6 @@ module.exports = {
setting.value = setting.value === 'true';
}
if (setting.key === 'ghost_head') {
setting.key = 'codeinjection_head';
}
if (setting.key === 'ghost_foot') {
setting.key = 'codeinjection_foot';
}
if (setting.key === 'active_timezone') {
setting.key = 'timezone';
}

View File

@ -12,7 +12,7 @@ module.exports = (attrs, frame) => {
// `forSettings` step. This logic can be rewritten once we get rid of deprecated
// fields completely.
if (_.isArray(attrs)) {
const keysToFilter = ['ghost_head', 'ghost_foot'];
const keysToFilter = [];
// NOTE: to support edits of deprecated 'slack' setting artificial 'slack_url' and 'slack_username'
// were added to the request body in the input serializer. These should not be returned in response

View File

@ -40,16 +40,6 @@ module.exports.forSettings = (attrs, frame) => {
if (_.isArray(attrs)) {
// CASE: read single setting
if (frame.original.params && frame.original.params.key) {
if (frame.original.params.key === 'ghost_head') {
attrs[0].key = 'ghost_head';
return;
}
if (frame.original.params.key === 'ghost_foot') {
attrs[0].key = 'ghost_foot';
return;
}
if (frame.original.params.key === 'active_timezone') {
attrs[0].key = 'active_timezone';
return;
@ -76,13 +66,7 @@ module.exports.forSettings = (attrs, frame) => {
// CASE: edit
if (frame.original.body && frame.original.body.settings) {
frame.original.body.settings.forEach((setting) => {
if (setting.key === 'ghost_head') {
const target = _.find(attrs, {key: 'codeinjection_head'});
target.key = 'ghost_head';
} else if (setting.key === 'ghost_foot') {
const target = _.find(attrs, {key: 'codeinjection_foot'});
target.key = 'ghost_foot';
} else if (setting.key === 'active_timezone') {
if (setting.key === 'active_timezone') {
const target = _.find(attrs, {key: 'timezone'});
target.key = 'active_timezone';
} else if (setting.key === 'default_locale') {
@ -112,24 +96,12 @@ module.exports.forSettings = (attrs, frame) => {
}
// CASE: browse all settings, add extra keys and keep deprecated
const ghostHead = _.cloneDeep(_.find(attrs, {key: 'codeinjection_head'}));
const ghostFoot = _.cloneDeep(_.find(attrs, {key: 'codeinjection_foot'}));
const timezone = _.cloneDeep(_.find(attrs, {key: 'timezone'}));
const lang = _.cloneDeep(_.find(attrs, {key: 'lang'}));
const slackURL = _.cloneDeep(_.find(attrs, {key: 'slack_url'}));
const slackUsername = _.cloneDeep(_.find(attrs, {key: 'slack_username'}));
const locale = _.cloneDeep(_.find(attrs, {key: 'lang'}));
if (ghostHead) {
ghostHead.key = 'ghost_head';
attrs.push(ghostHead);
}
if (ghostFoot) {
ghostFoot.key = 'ghost_foot';
attrs.push(ghostFoot);
}
if (timezone) {
timezone.key = 'active_timezone';
attrs.push(timezone);

View File

@ -1,7 +1,6 @@
const Promise = require('bluebird');
const _ = require('lodash');
const tpl = require('@tryghost/tpl');
const {NotFoundError, ValidationError, BadRequestError} = require('@tryghost/errors');
const {ValidationError, BadRequestError} = require('@tryghost/errors');
const validator = require('@tryghost/validator');
const messages = {
@ -11,30 +10,10 @@ const messages = {
};
module.exports = {
read(apiConfig, frame) {
// @NOTE: was removed https://github.com/TryGhost/Ghost/issues/10373
if (frame.options.key === 'ghost_head' || frame.options.key === 'ghost_foot') {
return Promise.reject(new NotFoundError({
message: tpl(messages.problemFindingSetting, {
key: frame.options.key
})
}));
}
},
edit(apiConfig, frame) {
const errors = [];
_.each(frame.data.settings, (setting) => {
if (setting.key === 'ghost_head' || setting.key === 'ghost_foot') {
// @NOTE: was removed https://github.com/TryGhost/Ghost/issues/10373
errors.push(new NotFoundError({
message: tpl(messages.problemFindingSetting, {
key: setting.key
})
}));
}
// TODO: the below array is INCOMPLETE
// it should include all setting values that have array as a type
const arrayTypeSettings = [

View File

@ -15,9 +15,7 @@ const ignoredSettings = ['slack_url', 'members_from_address', 'members_support_a
// NOTE: drop support in Ghost 5.0
const deprecatedSupportedSettingsMap = {
default_locale: 'lang',
active_timezone: 'timezone',
ghost_head: 'codeinjection_head',
ghost_foot: 'codeinjection_foot'
active_timezone: 'timezone'
};
const deprecatedSupportedSettingsOneToManyMap = {
// NOTE: intentionally ignoring slack_url setting

View File

@ -908,11 +908,6 @@ describe('Importer', function () {
value: 'Pacific/Auckland'
});
exportData.data.settings[2] = testUtils.DataGenerator.forKnex.createSetting({
key: 'ghost_foot',
value: 'AVADA KEDAVRA'
});
return dataImporter.doImport(exportData, importOptions)
.then(function (imported) {
imported.problems.length.should.eql(0);
@ -926,12 +921,6 @@ describe('Importer', function () {
})
.then(function (result) {
result.attributes.value.should.eql('Pacific/Auckland');
})
.then(function () {
return models.Settings.findOne(_.merge({key: 'codeinjection_foot'}, testUtils.context.internal));
})
.then(function (result) {
result.attributes.value.should.eql('AVADA KEDAVRA');
});
});