0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

🔥 Removed deprecated ghost_head and ghost_foot properties from /settings responses (#11144)

no issue 

- Removed ghost_head/ghost_foot propeties from Content API `GET /setting` response
- Removed ghost_head/ghost_foot from the output in Admin API
- Added validation when requesting ghost_head/ghost_food fields
- Updated deprecation comments
This commit is contained in:
Naz Gargol 2019-09-23 12:59:00 +02:00 committed by GitHub
parent 2ea8c3e33b
commit 50546d8cba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 47 additions and 16 deletions

View file

@ -17,7 +17,6 @@ module.exports.forPost = (frame, model, attrs) => {
}
};
// @NOTE: ghost_head & ghost_foot are deprecated, remove in Ghost 3.0
module.exports.forSettings = (attrs, frame) => {
const _ = require('lodash');
@ -26,14 +25,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') {
return;
}
if (frame.original.params.key === 'ghost_foot') {
return;
}
if (frame.original.params.key === 'codeinjection_head') {
attrs[0].key = 'codeinjection_head';
return;

View file

@ -77,6 +77,20 @@ const mapPost = (model, frame) => {
const mapSettings = (attrs, frame) => {
url.forSettings(attrs);
extraAttrs.forSettings(attrs, frame);
// NOTE: The cleanup of deprecated ghost_head/ghost_foot has to happen here
// because codeinjection_head/codeinjection_foot are assigned on a previous
// `forSettings` step. This logic can be rewritten once we get rid of deprecated
// fields completely.
if (_.isArray(attrs)) {
attrs = _.filter(attrs, (o) => {
return o.key !== 'ghost_head' && o.key !== 'ghost_foot';
});
} else {
delete attrs.ghost_head;
delete attrs.ghost_foot;
}
return attrs;
};

View file

@ -7,7 +7,18 @@ module.exports = {
// @NOTE: was removed (https://github.com/TryGhost/Ghost/commit/8bb7088ba026efd4a1c9cf7d6f1a5e9b4fa82575)
if (frame.options.key === 'permalinks') {
return Promise.reject(new common.errors.NotFoundError({
message: common.i18n.t('errors.errors.resourceNotFound')
message: common.i18n.t('errors.api.settings.problemFindingSetting', {
key: frame.options.key
})
}));
}
// @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 common.errors.NotFoundError({
message: common.i18n.t('errors.api.settings.problemFindingSetting', {
key: frame.options.key
})
}));
}
},
@ -27,7 +38,16 @@ module.exports = {
} else if (setting.key === 'permalinks') {
// @NOTE: was removed (https://github.com/TryGhost/Ghost/commit/8bb7088ba026efd4a1c9cf7d6f1a5e9b4fa82575)
errors.push(new common.errors.NotFoundError({
message: common.i18n.t('errors.api.settings.problemFindingSetting', {key: setting.key})
message: common.i18n.t('errors.api.settings.problemFindingSetting', {
key: setting.key
})
}));
} else if (setting.key === 'ghost_head' || setting.key === 'ghost_foot') {
// @NOTE: was removed https://github.com/TryGhost/Ghost/issues/10373
errors.push(new common.errors.NotFoundError({
message: common.i18n.t('errors.api.settings.problemFindingSetting', {
key: setting.key
})
}));
}
});

View file

@ -17,7 +17,6 @@ module.exports.forPost = (frame, model, attrs) => {
}
};
// @NOTE: ghost_head & ghost_foot are deprecated, remove in Ghost 3.0
module.exports.forSettings = (attrs, frame) => {
const _ = require('lodash');

View file

@ -16,6 +16,7 @@ module.exports = {
twitter: 'twitter',
default_locale: 'lang',
active_timezone: 'timezone',
// TODO: substitute ghost_head and ghost_foot with codeinjection_* when we drop v2 (Ghost 4.0)
ghost_head: 'ghost_head',
ghost_foot: 'ghost_foot',
navigation: 'navigation',

View file

@ -47,6 +47,8 @@ describe('Settings API', function () {
JSON.parse(_.find(jsonResponse.settings, {key: 'unsplash'}).value).isActive.should.eql(true);
JSON.parse(_.find(jsonResponse.settings, {key: 'amp'}).value).should.eql(true);
should.not.exist(_.find(jsonResponse.settings, {key: 'permalinks'}));
should.not.exist(_.find(jsonResponse.settings, {key: 'ghost_head'}));
should.not.exist(_.find(jsonResponse.settings, {key: 'ghost_foot'}));
testUtils.API.isISO8601(jsonResponse.settings[0].created_at).should.be.true();
jsonResponse.settings[0].created_at.should.be.an.instanceof(String);
@ -60,7 +62,7 @@ describe('Settings API', function () {
});
it('Can read a setting', function (done) {
request.get(localUtils.API.getApiQuery('settings/ghost_head/'))
request.get(localUtils.API.getApiQuery('settings/codeinjection_head/'))
.set('Origin', config.get('url'))
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
@ -79,7 +81,7 @@ describe('Settings API', function () {
jsonResponse.settings.length.should.eql(1);
testUtils.API.checkResponseValue(jsonResponse.settings[0], ['id', 'key', 'value', 'type', 'created_at', 'updated_at']);
jsonResponse.settings[0].key.should.eql('ghost_head');
jsonResponse.settings[0].key.should.eql('codeinjection_head');
testUtils.API.isISO8601(jsonResponse.settings[0].created_at).should.be.true();
done();
});

View file

@ -42,8 +42,12 @@ describe('Settings Content API', function () {
const settings = jsonResponse.settings;
// Verify we have the right keys for settings
settings.should.have.properties(_.values(publicSettings));
Object.keys(settings).length.should.equal(23);
const publicProperties = _.filter(_.values(publicSettings), (o) => {
return (o !== 'ghost_head' && o !== 'ghost_foot');
});
publicProperties.push('codeinjection_head', 'codeinjection_foot');
settings.should.have.properties(publicProperties);
Object.keys(settings).length.should.equal(21);
// Verify that we are returning the defaults for each value
_.forEach(settings, (value, key) => {