Skip to content

Commit

Permalink
Fixed wrong handling of formats param (#9078)
Browse files Browse the repository at this point in the history
closes #9077

- because of our API layer refactoring, see #9068
- we can now see that code was written wrong because of this horrible API bug
- this fixes the formats parameter for querying a single post
  • Loading branch information
kirrg001 authored and kevinansfield committed Sep 28, 2017
1 parent e347163 commit d3d04a8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
12 changes: 8 additions & 4 deletions core/server/api/posts.js
Expand Up @@ -79,7 +79,9 @@ posts = {
* @return {Promise<Post>} Post
*/
read: function read(options) {
var attrs = ['id', 'slug', 'status', 'uuid', 'formats'],
var attrs = ['id', 'slug', 'status', 'uuid'],
// NOTE: the scheduler API uses the post API and forwards custom options
extraAllowedOptions = options.opts || ['formats'],
tasks;

/**
Expand All @@ -105,7 +107,7 @@ posts = {

// Push all of our tasks into a `tasks` array in the correct order
tasks = [
apiUtils.validate(docName, {attrs: attrs, opts: options.opts || []}),
apiUtils.validate(docName, {attrs: attrs, opts: extraAllowedOptions}),
apiUtils.handlePublicPermissions(docName, 'read', unsafeAttrs),
apiUtils.convertOptions(allowedIncludes, models.Post.allowedFormats),
modelQuery
Expand All @@ -125,7 +127,9 @@ posts = {
* @return {Promise(Post)} Edited Post
*/
edit: function edit(object, options) {
var tasks;
var tasks,
// NOTE: the scheduler API uses the post API and forwards custom options
extraAllowedOptions = options.opts || [];

/**
* ### Model Query
Expand Down Expand Up @@ -159,7 +163,7 @@ posts = {

// Push all of our tasks into a `tasks` array in the correct order
tasks = [
apiUtils.validate(docName, {opts: apiUtils.idDefaultOptions.concat(options.opts || [])}),
apiUtils.validate(docName, {opts: apiUtils.idDefaultOptions.concat(extraAllowedOptions)}),
apiUtils.handlePermissions(docName, 'edit', unsafeAttrs),
apiUtils.convertOptions(allowedIncludes),
modelQuery
Expand Down
24 changes: 24 additions & 0 deletions core/test/functional/routes/api/posts_spec.js
Expand Up @@ -360,6 +360,30 @@ describe('Post API', function () {
});
});

it('can retrieve multiple post formats', function (done) {
request
.get(testUtils.API.getApiQuery('posts/' + testUtils.DataGenerator.Content.posts[0].id + '/?formats=plaintext,mobiledoc,amp'))
.set('Authorization', 'Bearer ' + ownerAccessToken)
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
.expect(200)
.end(function (err, res) {
if (err) {
return done(err);
}

should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.posts);
jsonResponse.posts.should.have.length(1);
jsonResponse.posts[0].id.should.equal(testUtils.DataGenerator.Content.posts[0].id);

testUtils.API.checkResponse(jsonResponse.posts[0], 'post', ['mobiledoc', 'plaintext', 'amp'], ['html']);

done();
});
});

it('can retrieve a post by slug', function (done) {
request.get(testUtils.API.getApiQuery('posts/slug/welcome/'))
.set('Authorization', 'Bearer ' + ownerAccessToken)
Expand Down

0 comments on commit d3d04a8

Please sign in to comment.