mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Removed mobiledoc format from Content API V2 response (#10098)
closes #10097 - removed formats `mobiledoc` option directly in post input serializer for v2 Content API
This commit is contained in:
parent
46c806358b
commit
7b38986316
4 changed files with 105 additions and 8 deletions
|
@ -1,5 +1,13 @@
|
|||
const debug = require('ghost-ignition').debug('api:v2:utils:serializers:input:pages');
|
||||
|
||||
function removeMobiledocFormat(frame) {
|
||||
if (frame.options.formats && frame.options.formats.includes('mobiledoc')) {
|
||||
frame.options.formats = frame.options.formats.filter((format) => {
|
||||
return (format !== 'mobiledoc');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
browse(apiConfig, frame) {
|
||||
debug('browse');
|
||||
|
@ -19,6 +27,7 @@ module.exports = {
|
|||
} else {
|
||||
frame.options.filter = 'page:true';
|
||||
}
|
||||
removeMobiledocFormat(frame);
|
||||
|
||||
debug(frame.options);
|
||||
},
|
||||
|
@ -27,6 +36,7 @@ module.exports = {
|
|||
debug('read');
|
||||
|
||||
frame.data.page = true;
|
||||
removeMobiledocFormat(frame);
|
||||
|
||||
debug(frame.options);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,15 @@
|
|||
const _ = require('lodash');
|
||||
const debug = require('ghost-ignition').debug('api:v2:utils:serializers:input:posts');
|
||||
const url = require('./utils/url');
|
||||
const utils = require('../../index');
|
||||
|
||||
function removeMobiledocFormat(frame) {
|
||||
if (frame.options.formats && frame.options.formats.includes('mobiledoc')) {
|
||||
frame.options.formats = frame.options.formats.filter((format) => {
|
||||
return (format !== 'mobiledoc');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
browse(apiConfig, frame) {
|
||||
|
@ -13,7 +22,7 @@ module.exports = {
|
|||
* - api_key_id exists? content api access
|
||||
* - user exists? admin api access
|
||||
*/
|
||||
if (Object.keys(frame.options.context).length === 0 || (!frame.options.context.user && frame.options.context.api_key_id)) {
|
||||
if (utils.isContentAPI(frame)) {
|
||||
// CASE: the content api endpoints for posts should only return non page type resources
|
||||
if (frame.options.filter) {
|
||||
if (frame.options.filter.match(/page:\w+\+?/)) {
|
||||
|
@ -28,6 +37,8 @@ module.exports = {
|
|||
} else {
|
||||
frame.options.filter = 'page:false';
|
||||
}
|
||||
// CASE: the content api endpoint for posts should not return mobiledoc
|
||||
removeMobiledocFormat(frame);
|
||||
}
|
||||
|
||||
debug(frame.options);
|
||||
|
@ -43,8 +54,10 @@ module.exports = {
|
|||
* - api_key_id exists? content api access
|
||||
* - user exists? admin api access
|
||||
*/
|
||||
if (Object.keys(frame.options.context).length === 0 || (!frame.options.context.user && frame.options.context.api_key_id)) {
|
||||
if (utils.isContentAPI(frame)) {
|
||||
frame.data.page = false;
|
||||
// CASE: the content api endpoint for posts should not return mobiledoc
|
||||
removeMobiledocFormat(frame);
|
||||
}
|
||||
|
||||
debug(frame.options);
|
||||
|
|
|
@ -6,7 +6,9 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
|
|||
it('default', function () {
|
||||
const apiConfig = {};
|
||||
const frame = {
|
||||
options: {}
|
||||
options: {
|
||||
context: {}
|
||||
},
|
||||
};
|
||||
|
||||
serializers.input.pages.browse(apiConfig, frame);
|
||||
|
@ -17,7 +19,8 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
|
|||
const apiConfig = {};
|
||||
const frame = {
|
||||
options: {
|
||||
filter: 'status:published+tag:eins'
|
||||
filter: 'status:published+tag:eins',
|
||||
context: {}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -29,7 +32,8 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
|
|||
const apiConfig = {};
|
||||
const frame = {
|
||||
options: {
|
||||
filter: 'page:false+tag:eins'
|
||||
filter: 'page:false+tag:eins',
|
||||
context: {}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -41,20 +45,38 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
|
|||
const apiConfig = {};
|
||||
const frame = {
|
||||
options: {
|
||||
filter: 'page:false'
|
||||
filter: 'page:false',
|
||||
context: {}
|
||||
}
|
||||
};
|
||||
|
||||
serializers.input.pages.browse(apiConfig, frame);
|
||||
frame.options.filter.should.eql('page:true');
|
||||
});
|
||||
|
||||
it('remove mobiledoc option from formats', function () {
|
||||
const apiConfig = {};
|
||||
const frame = {
|
||||
options: {
|
||||
formats: ['html', 'mobiledoc', 'plaintext'],
|
||||
context: {}
|
||||
}
|
||||
};
|
||||
|
||||
serializers.input.pages.browse(apiConfig, frame);
|
||||
frame.options.formats.should.not.containEql('mobiledoc');
|
||||
frame.options.formats.should.containEql('html');
|
||||
frame.options.formats.should.containEql('plaintext');
|
||||
});
|
||||
});
|
||||
|
||||
describe('read', function () {
|
||||
it('default', function () {
|
||||
const apiConfig = {};
|
||||
const frame = {
|
||||
options: {},
|
||||
options: {
|
||||
context: {}
|
||||
},
|
||||
data: {
|
||||
status: 'all'
|
||||
}
|
||||
|
@ -68,7 +90,9 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
|
|||
it('overrides page', function () {
|
||||
const apiConfig = {};
|
||||
const frame = {
|
||||
options: {},
|
||||
options: {
|
||||
context: {}
|
||||
},
|
||||
data: {
|
||||
status: 'all',
|
||||
page: false
|
||||
|
@ -79,5 +103,24 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
|
|||
frame.data.status.should.eql('all');
|
||||
frame.data.page.should.eql(true);
|
||||
});
|
||||
|
||||
it('remove mobiledoc option from formats', function () {
|
||||
const apiConfig = {};
|
||||
const frame = {
|
||||
options: {
|
||||
formats: ['html', 'mobiledoc', 'plaintext'],
|
||||
context: {}
|
||||
},
|
||||
data: {
|
||||
status: 'all',
|
||||
page: false
|
||||
}
|
||||
};
|
||||
|
||||
serializers.input.pages.read(apiConfig, frame);
|
||||
frame.options.formats.should.not.containEql('mobiledoc');
|
||||
frame.options.formats.should.containEql('html');
|
||||
frame.options.formats.should.containEql('plaintext');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -80,6 +80,21 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
|
|||
serializers.input.posts.browse(apiConfig, frame);
|
||||
frame.options.filter.should.eql('page:false');
|
||||
});
|
||||
|
||||
it('remove mobiledoc option from formats', function () {
|
||||
const apiConfig = {};
|
||||
const frame = {
|
||||
options: {
|
||||
formats: ['html', 'mobiledoc', 'plaintext'],
|
||||
context: {}
|
||||
}
|
||||
};
|
||||
|
||||
serializers.input.posts.browse(apiConfig, frame);
|
||||
frame.options.formats.should.not.containEql('mobiledoc');
|
||||
frame.options.formats.should.containEql('html');
|
||||
frame.options.formats.should.containEql('plaintext');
|
||||
});
|
||||
});
|
||||
|
||||
describe('read', function () {
|
||||
|
@ -152,6 +167,22 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
|
|||
serializers.input.posts.read(apiConfig, frame);
|
||||
frame.data.page.should.eql(true);
|
||||
});
|
||||
|
||||
it('remove mobiledoc option from formats', function () {
|
||||
const apiConfig = {};
|
||||
const frame = {
|
||||
options: {
|
||||
formats: ['html', 'mobiledoc', 'plaintext'],
|
||||
context: {}
|
||||
},
|
||||
data: {}
|
||||
};
|
||||
|
||||
serializers.input.posts.read(apiConfig, frame);
|
||||
frame.options.formats.should.not.containEql('mobiledoc');
|
||||
frame.options.formats.should.containEql('html');
|
||||
frame.options.formats.should.containEql('plaintext');
|
||||
});
|
||||
});
|
||||
|
||||
describe('edit', function () {
|
||||
|
|
Loading…
Add table
Reference in a new issue