mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Added announcement_* fields to Settings Admin API
refs https://github.com/TryGhost/Team/issues/3011 - Allows to edit and read following settings fields: - announcement_content - announcement_background - announcement_visibility
This commit is contained in:
parent
a0dbdfad6b
commit
388a625f37
4 changed files with 199 additions and 9 deletions
|
@ -62,7 +62,10 @@ const EDITABLE_SETTINGS = [
|
||||||
'editor_default_email_recipients_filter',
|
'editor_default_email_recipients_filter',
|
||||||
'labs',
|
'labs',
|
||||||
'comments_enabled',
|
'comments_enabled',
|
||||||
'outbound_link_tagging'
|
'outbound_link_tagging',
|
||||||
|
'announcement_content',
|
||||||
|
'announcement_background',
|
||||||
|
'announcement_visibility'
|
||||||
];
|
];
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
@ -7,7 +7,9 @@ const tpl = require('@tryghost/tpl');
|
||||||
const messages = {
|
const messages = {
|
||||||
invalidEmailReceived: 'Please send a valid email',
|
invalidEmailReceived: 'Please send a valid email',
|
||||||
invalidEmailValueReceived: 'Please enter a valid email address.',
|
invalidEmailValueReceived: 'Please enter a valid email address.',
|
||||||
invalidEmailTypeReceived: 'Invalid email type received'
|
invalidEmailTypeReceived: 'Invalid email type received',
|
||||||
|
invalidAnnouncementVisibilityValueReceived: 'Please enter a valid announcement visibility value',
|
||||||
|
invalidAnnouncementBackgroundValueReceived: 'Please enter a valid announcement background value'
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -60,6 +62,30 @@ module.exports = {
|
||||||
errors.push(typeError);
|
errors.push(typeError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (setting.key === 'announcement_visibility') {
|
||||||
|
const visibilityValue = setting.value;
|
||||||
|
|
||||||
|
if (!['public', 'visitors', 'members', 'paid'].includes(visibilityValue)) {
|
||||||
|
const visibilityError = new ValidationError({
|
||||||
|
message: tpl(messages.invalidAnnouncementVisibilityValueReceived),
|
||||||
|
property: setting.key
|
||||||
|
});
|
||||||
|
errors.push(visibilityError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (setting.key === 'announcement_background') {
|
||||||
|
const announcementBackgroundValue = setting.value;
|
||||||
|
|
||||||
|
if (!['accent', 'dark', 'light'].includes(announcementBackgroundValue)) {
|
||||||
|
const visibilityError = new ValidationError({
|
||||||
|
message: tpl(messages.invalidAnnouncementBackgroundValueReceived),
|
||||||
|
property: setting.key
|
||||||
|
});
|
||||||
|
errors.push(visibilityError);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Prevent setting icon to the resized one when sending all settings received from browse again in the edit endpoint
|
// Prevent setting icon to the resized one when sending all settings received from browse again in the edit endpoint
|
||||||
|
|
|
@ -652,7 +652,7 @@ Object {
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"key": "announcement_content",
|
"key": "announcement_content",
|
||||||
"value": null,
|
"value": "<p>Great news coming soon!</p>",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"key": "announcement_visibility",
|
"key": "announcement_visibility",
|
||||||
|
@ -694,7 +694,7 @@ exports[`Settings API Edit Can edit a setting 2: [headers] 1`] = `
|
||||||
Object {
|
Object {
|
||||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
"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",
|
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||||
"content-length": "3906",
|
"content-length": "3934",
|
||||||
"content-type": "application/json; charset=utf-8",
|
"content-type": "application/json; charset=utf-8",
|
||||||
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
|
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
|
||||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||||
|
@ -978,7 +978,7 @@ Object {
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"key": "announcement_content",
|
"key": "announcement_content",
|
||||||
"value": null,
|
"value": "<p>Great news coming soon!</p>",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"key": "announcement_visibility",
|
"key": "announcement_visibility",
|
||||||
|
@ -1303,7 +1303,7 @@ Object {
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"key": "announcement_content",
|
"key": "announcement_content",
|
||||||
"value": null,
|
"value": "<p>Great news coming soon!</p>",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"key": "announcement_visibility",
|
"key": "announcement_visibility",
|
||||||
|
@ -1633,7 +1633,7 @@ Object {
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"key": "announcement_content",
|
"key": "announcement_content",
|
||||||
"value": null,
|
"value": "<p>Great news coming soon!</p>",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"key": "announcement_visibility",
|
"key": "announcement_visibility",
|
||||||
|
@ -1684,6 +1684,99 @@ Object {
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`Settings API Edit fails to edit setting with unsupported announcement_background value 1: [body] 1`] = `
|
||||||
|
Object {
|
||||||
|
"errors": Array [
|
||||||
|
Object {
|
||||||
|
"code": null,
|
||||||
|
"context": "Please enter a valid announcement background value",
|
||||||
|
"details": null,
|
||||||
|
"ghostErrorCode": null,
|
||||||
|
"help": null,
|
||||||
|
"id": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/,
|
||||||
|
"message": "Validation error, cannot edit setting.",
|
||||||
|
"property": "announcement_background",
|
||||||
|
"type": "ValidationError",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`Settings API Edit fails to edit setting with unsupported announcement_background value 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": "295",
|
||||||
|
"content-type": "application/json; charset=utf-8",
|
||||||
|
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
|
||||||
|
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||||
|
"vary": "Accept-Version, Origin, Accept-Encoding",
|
||||||
|
"x-powered-by": "Express",
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`Settings API Edit fails to edit setting with unsupported announcement_visibility value 1: [body] 1`] = `
|
||||||
|
Object {
|
||||||
|
"errors": Array [
|
||||||
|
Object {
|
||||||
|
"code": null,
|
||||||
|
"context": "Please enter a valid announcement visibility value",
|
||||||
|
"details": null,
|
||||||
|
"ghostErrorCode": null,
|
||||||
|
"help": null,
|
||||||
|
"id": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/,
|
||||||
|
"message": "Validation error, cannot edit setting.",
|
||||||
|
"property": "announcement_visibility",
|
||||||
|
"type": "ValidationError",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`Settings API Edit fails to edit setting with unsupported announcement_visibility value 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": "295",
|
||||||
|
"content-type": "application/json; charset=utf-8",
|
||||||
|
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
|
||||||
|
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||||
|
"vary": "Accept-Version, Origin, Accept-Encoding",
|
||||||
|
"x-powered-by": "Express",
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`Settings API Edit fails to edit setting with unsupported value 1: [body] 1`] = `
|
||||||
|
Object {
|
||||||
|
"errors": Array [
|
||||||
|
Object {
|
||||||
|
"code": null,
|
||||||
|
"context": "Please enter a valid announcement visibility value",
|
||||||
|
"details": null,
|
||||||
|
"ghostErrorCode": null,
|
||||||
|
"help": null,
|
||||||
|
"id": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/,
|
||||||
|
"message": "Validation error, cannot edit setting.",
|
||||||
|
"property": "announcement_visibility",
|
||||||
|
"type": "ValidationError",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`Settings API Edit fails to edit setting with unsupported value 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": "295",
|
||||||
|
"content-type": "application/json; charset=utf-8",
|
||||||
|
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
|
||||||
|
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||||
|
"vary": "Accept-Version, Origin, Accept-Encoding",
|
||||||
|
"x-powered-by": "Express",
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`Settings API Edit removes image size prefixes when setting the icon 1: [body] 1`] = `
|
exports[`Settings API Edit removes image size prefixes when setting the icon 1: [body] 1`] = `
|
||||||
Object {
|
Object {
|
||||||
"meta": Object {},
|
"meta": Object {},
|
||||||
|
@ -1958,7 +2051,7 @@ Object {
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"key": "announcement_content",
|
"key": "announcement_content",
|
||||||
"value": null,
|
"value": "<p>Great news coming soon!</p>",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"key": "announcement_visibility",
|
"key": "announcement_visibility",
|
||||||
|
@ -2348,7 +2441,7 @@ Object {
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"key": "announcement_content",
|
"key": "announcement_content",
|
||||||
"value": null,
|
"value": "<p>Great news coming soon!</p>",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"key": "announcement_visibility",
|
"key": "announcement_visibility",
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
const sinon = require('sinon');
|
||||||
|
const logging = require('@tryghost/logging');
|
||||||
const SingleUseTokenProvider = require('../../../core/server/services/members/SingleUseTokenProvider');
|
const SingleUseTokenProvider = require('../../../core/server/services/members/SingleUseTokenProvider');
|
||||||
const settingsCache = require('../../../core/shared/settings-cache');
|
const settingsCache = require('../../../core/shared/settings-cache');
|
||||||
const {agentProvider, fixtureManager, mockManager, matchers} = require('../../utils/e2e-framework');
|
const {agentProvider, fixtureManager, mockManager, matchers} = require('../../utils/e2e-framework');
|
||||||
|
@ -51,6 +53,7 @@ describe('Settings API', function () {
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
mockManager.restore();
|
mockManager.restore();
|
||||||
|
sinon.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Browse', function () {
|
describe('Browse', function () {
|
||||||
|
@ -105,6 +108,10 @@ describe('Settings API', function () {
|
||||||
key: 'codeinjection_head',
|
key: 'codeinjection_head',
|
||||||
value: null
|
value: null
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: 'announcement_content',
|
||||||
|
value: '<p>Great news coming soon!</p>'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: 'navigation',
|
key: 'navigation',
|
||||||
value: JSON.stringify([{
|
value: JSON.stringify([{
|
||||||
|
@ -302,6 +309,64 @@ describe('Settings API', function () {
|
||||||
|
|
||||||
mockManager.assert.sentEmailCount(0);
|
mockManager.assert.sentEmailCount(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('fails to edit setting with unsupported announcement_visibility value', async function () {
|
||||||
|
const loggingStub = sinon.stub(logging, 'error');
|
||||||
|
const settingsToChange = [
|
||||||
|
{
|
||||||
|
key: 'announcement_visibility',
|
||||||
|
value: 'invalid value'
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
await agent.put('settings/')
|
||||||
|
.body({
|
||||||
|
settings: settingsToChange
|
||||||
|
})
|
||||||
|
.expectStatus(422)
|
||||||
|
.matchBodySnapshot({
|
||||||
|
errors: [
|
||||||
|
{
|
||||||
|
id: anyErrorId
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
.matchHeaderSnapshot({
|
||||||
|
'content-version': anyContentVersion,
|
||||||
|
etag: anyEtag
|
||||||
|
});
|
||||||
|
|
||||||
|
sinon.assert.calledOnce(loggingStub);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails to edit setting with unsupported announcement_background value', async function () {
|
||||||
|
const loggingStub = sinon.stub(logging, 'error');
|
||||||
|
const settingsToChange = [
|
||||||
|
{
|
||||||
|
key: 'announcement_background',
|
||||||
|
value: 'not a background value'
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
await agent.put('settings/')
|
||||||
|
.body({
|
||||||
|
settings: settingsToChange
|
||||||
|
})
|
||||||
|
.expectStatus(422)
|
||||||
|
.matchBodySnapshot({
|
||||||
|
errors: [
|
||||||
|
{
|
||||||
|
id: anyErrorId
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
.matchHeaderSnapshot({
|
||||||
|
'content-version': anyContentVersion,
|
||||||
|
etag: anyEtag
|
||||||
|
});
|
||||||
|
|
||||||
|
sinon.assert.calledOnce(loggingStub);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('verify key update', function () {
|
describe('verify key update', function () {
|
||||||
|
@ -335,6 +400,7 @@ describe('Settings API', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('cannot update invalid keys via token', async function () {
|
it('cannot update invalid keys via token', async function () {
|
||||||
|
const loggingStub = sinon.stub(logging, 'error');
|
||||||
const token = await (new SingleUseTokenProvider({
|
const token = await (new SingleUseTokenProvider({
|
||||||
SingleUseTokenModel: models.SingleUseToken,
|
SingleUseTokenModel: models.SingleUseToken,
|
||||||
validityPeriod: 24 * 60 * 60 * 1000,
|
validityPeriod: 24 * 60 * 60 * 1000,
|
||||||
|
@ -357,6 +423,8 @@ describe('Settings API', function () {
|
||||||
'content-version': anyContentVersion,
|
'content-version': anyContentVersion,
|
||||||
etag: anyEtag
|
etag: anyEtag
|
||||||
});
|
});
|
||||||
|
|
||||||
|
sinon.assert.calledOnce(loggingStub);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue