Skip to content

Commit

Permalink
Removed mobiledoc format from Content API V2 response (#10098)
Browse files Browse the repository at this point in the history
closes #10097

- removed formats `mobiledoc` option directly in post input serializer for v2 Content API
  • Loading branch information
rishabhgrg authored and kirrg001 committed Nov 6, 2018
1 parent 46c8063 commit 7b38986
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 8 deletions.
10 changes: 10 additions & 0 deletions core/server/api/v2/utils/serializers/input/pages.js
@@ -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');
Expand All @@ -19,6 +27,7 @@ module.exports = {
} else {
frame.options.filter = 'page:true';
}
removeMobiledocFormat(frame);

debug(frame.options);
},
Expand All @@ -27,6 +36,7 @@ module.exports = {
debug('read');

frame.data.page = true;
removeMobiledocFormat(frame);

debug(frame.options);
}
Expand Down
17 changes: 15 additions & 2 deletions core/server/api/v2/utils/serializers/input/posts.js
@@ -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) {
Expand All @@ -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+\+?/)) {
Expand All @@ -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);
Expand All @@ -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);
Expand Down
55 changes: 49 additions & 6 deletions core/test/unit/api/v2/utils/serializers/input/pages_spec.js
Expand Up @@ -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);
Expand All @@ -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: {}
}
};

Expand All @@ -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: {}
}
};

Expand All @@ -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'
}
Expand 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
Expand All @@ -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');
});
});
});
31 changes: 31 additions & 0 deletions core/test/unit/api/v2/utils/serializers/input/posts_spec.js
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 () {
Expand Down

0 comments on commit 7b38986

Please sign in to comment.