Skip to content

Commit

Permalink
Changed default format from html to mobiledoc for Admin API v2
Browse files Browse the repository at this point in the history
no issue

- Ghost-Admin needs mobiledoc only
- Ghost-Android needs mobiledoc only
- any other client can fetch other formats using the query param
  • Loading branch information
kirrg001 committed Feb 25, 2019
1 parent f558b58 commit e65a828
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
14 changes: 14 additions & 0 deletions core/server/api/v2/utils/serializers/input/pages.js
Expand Up @@ -25,6 +25,14 @@ function setDefaultOrder(frame) {
}
}

function defaultFormat(frame) {
if (frame.options.formats) {
return;
}

frame.options.formats = 'mobiledoc';
}

/**
* CASE:
*
Expand Down Expand Up @@ -62,6 +70,7 @@ module.exports = {

if (!localUtils.isContentAPI(frame)) {
forceStatusFilter(frame);
defaultFormat(frame);
}

debug(frame.options);
Expand All @@ -79,6 +88,7 @@ module.exports = {

if (!localUtils.isContentAPI(frame)) {
forceStatusFilter(frame);
defaultFormat(frame);
}

debug(frame.options);
Expand Down Expand Up @@ -122,6 +132,8 @@ module.exports = {
}
});
}

defaultFormat(frame);
},

edit(apiConfig, frame) {
Expand All @@ -138,5 +150,7 @@ module.exports = {
id: frame.options.id,
page: true
};

defaultFormat(frame);
}
};
14 changes: 14 additions & 0 deletions core/server/api/v2/utils/serializers/input/posts.js
Expand Up @@ -34,6 +34,14 @@ function setDefaultOrder(frame) {
}
}

function defaultFormat(frame) {
if (frame.options.formats) {
return;
}

frame.options.formats = 'mobiledoc';
}

/**
* CASE:
*
Expand Down Expand Up @@ -84,6 +92,7 @@ module.exports = {

if (!localUtils.isContentAPI(frame)) {
forceStatusFilter(frame);
defaultFormat(frame);
}

debug(frame.options);
Expand Down Expand Up @@ -114,6 +123,7 @@ module.exports = {

if (!localUtils.isContentAPI(frame)) {
forceStatusFilter(frame);
defaultFormat(frame);
}

debug(frame.options);
Expand Down Expand Up @@ -157,6 +167,8 @@ module.exports = {
}
});
}

defaultFormat(frame);
},

edit(apiConfig, frame) {
Expand All @@ -171,5 +183,7 @@ module.exports = {
id: frame.options.id,
page: false
};

defaultFormat(frame);
}
};
2 changes: 1 addition & 1 deletion core/test/acceptance/old/admin/posts_spec.js
Expand Up @@ -77,7 +77,7 @@ describe('Posts API', function () {
should.exist(jsonResponse.posts);
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(3);
localUtils.API.checkResponse(jsonResponse.posts[0], 'post', ['mobiledoc', 'plaintext'], ['html', 'primary_tag', 'primary_author']);
localUtils.API.checkResponse(jsonResponse.posts[0], 'post', ['mobiledoc', 'plaintext'], ['primary_tag', 'primary_author']);
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);

Expand Down
8 changes: 4 additions & 4 deletions core/test/acceptance/old/admin/utils.js
Expand Up @@ -24,8 +24,8 @@ const expectedProperties = {

post: _(schema.posts)
.keys()
// by default we only return html
.without('mobiledoc', 'plaintext')
// by default we only return mobildoc
.without('html', 'plaintext')
.without('visibility')
.without('locale')
.without('page')
Expand All @@ -35,8 +35,8 @@ const expectedProperties = {

page: _(schema.posts)
.keys()
// by default we only return html
.without('mobiledoc', 'plaintext')
// by default we only return mobildoc
.without('html', 'plaintext')
.without('visibility')
.without('locale')
.without('page')
Expand Down
4 changes: 2 additions & 2 deletions core/test/regression/api/v2/admin/utils.js
Expand Up @@ -20,8 +20,8 @@ const expectedProperties = {

post: _(schema.posts)
.keys()
// by default we only return html
.without('mobiledoc', 'plaintext')
// by default we only return mobiledoc
.without('html', 'plaintext')
.without('visibility')
.without('locale')
.without('page')
Expand Down

0 comments on commit e65a828

Please sign in to comment.