Skip to content

Commit

Permalink
🔥 Removed 'staticPages' filter (#11135)
Browse files Browse the repository at this point in the history
refs #5151
refs #10737

- Removed all uses/references to post's "staticPages" filter
- It was only a feature specific to API v0.1 which doesn't have to take space in the codebase anymore
  • Loading branch information
naz authored Sep 17, 2019
1 parent a30812c commit a2ebee3
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 104 deletions.
23 changes: 5 additions & 18 deletions core/server/models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ Post = ghostBookshelf.Model.extend({
this.set('posts_meta', null);
}
}

this.handleAttachedModels(model);

ghostBookshelf.Model.prototype.onSaving.apply(this, arguments);
Expand Down Expand Up @@ -617,28 +617,16 @@ Post = ghostBookshelf.Model.extend({
},

/**
* You can pass an extra `status=VALUES` or "staticPages" field.
* You can pass an extra `status=VALUES` field.
* Long-Term: We should deprecate these short cuts and force users to use the filter param.
*/
extraFilters: function extraFilters(options) {
if (!options.staticPages && !options.status) {
if (!options.status) {
return null;
}

let filter = null;

// CASE: "staticPages" is passed
if (options.staticPages && options.staticPages !== 'all') {
// CASE: convert string true/false to boolean
if (!_.isBoolean(options.staticPages)) {
options.staticPages = _.includes(['true', '1'], options.staticPages);
}

filter = `page:${options.staticPages ? 'true' : 'false'}`;
} else if (options.staticPages === 'all') {
filter = 'page:[true, false]';
}

// CASE: "status" is passed, combine filters
if (options.status && options.status !== 'all') {
options.status = _.includes(ALL_STATUSES, options.status) ? options.status : 'published';
Expand All @@ -657,7 +645,6 @@ Post = ghostBookshelf.Model.extend({
}

delete options.status;
delete options.staticPages;
return filter;
},

Expand Down Expand Up @@ -724,7 +711,7 @@ Post = ghostBookshelf.Model.extend({
// these are the only options that can be passed to Bookshelf / Knex.
validOptions = {
findOne: ['columns', 'importing', 'withRelated', 'require', 'filter'],
findPage: ['status', 'staticPages'],
findPage: ['status'],
findAll: ['columns', 'filter'],
destroy: ['destroyAll', 'destroyBy'],
edit: ['filter']
Expand All @@ -745,7 +732,7 @@ Post = ghostBookshelf.Model.extend({
* receive all fields including relations. Otherwise you can't rely on a consistent flow. And we want to avoid
* that event listeners have to re-fetch a resource. This function is used in the context of inserting
* and updating resources. We won't return the relations by default for now.
*
*
* We also always fetch posts metadata to keep current behavior consistent
*/
defaultRelations: function defaultRelations(methodName, options) {
Expand Down
1 change: 0 additions & 1 deletion core/server/services/permissions/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ var _ = require('lodash'),
*
* - remove if we drop `extraFilters` (see e.g. post model)
* - we currently accept `?status={value}` in the API
* - we currently accept `?staticPages={value}` in the API
* - but instead people should use the `?filter=status:{value}`
*
* This function protects against:
Expand Down
23 changes: 0 additions & 23 deletions core/test/regression/api/canary/content/posts_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,29 +199,6 @@ describe('api/canary/content/posts', function () {
});
});

it('browse posts, ignores staticPages', function (done) {
request.get(localUtils.API.getApiQuery(`posts/?key=${validKey}&staticPages=true`))
.set('Origin', testUtils.API.getURL())
.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);
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(11);
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
done();
});
});

it('can\'t read page', function () {
return request
.get(localUtils.API.getApiQuery(`posts/${testUtils.DataGenerator.Content.posts[5].id}/?key=${validKey}`))
Expand Down
23 changes: 0 additions & 23 deletions core/test/regression/api/v2/content/posts_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,29 +111,6 @@ describe('api/v2/content/posts', function () {
});
});

it('browse posts, ignores staticPages', function (done) {
request.get(localUtils.API.getApiQuery(`posts/?key=${validKey}&staticPages=true`))
.set('Origin', testUtils.API.getURL())
.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);
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(11);
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
done();
});
});

it('can\'t read page', function () {
return request
.get(localUtils.API.getApiQuery(`posts/${testUtils.DataGenerator.Content.posts[5].id}/?key=${validKey}`))
Expand Down
23 changes: 0 additions & 23 deletions core/test/regression/api/v3/content/posts_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,29 +199,6 @@ describe('api/v3/content/posts', function () {
});
});

it('browse posts, ignores staticPages', function (done) {
request.get(localUtils.API.getApiQuery(`posts/?key=${validKey}&staticPages=true`))
.set('Origin', testUtils.API.getURL())
.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);
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(11);
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
done();
});
});

it('can\'t read page', function () {
return request
.get(localUtils.API.getApiQuery(`posts/${testUtils.DataGenerator.Content.posts[5].id}/?key=${validKey}`))
Expand Down
16 changes: 0 additions & 16 deletions core/test/regression/models/model_posts_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,6 @@ describe('Post Model', function () {
paginationResult.meta.pagination.pages.should.equal(2);
paginationResult.data.length.should.equal(30);

// Test both boolean formats
return models.Post.findPage({limit: 10, staticPages: true});
}).then(function (paginationResult) {
paginationResult.meta.pagination.page.should.equal(1);
paginationResult.meta.pagination.limit.should.equal(10);
paginationResult.meta.pagination.pages.should.equal(1);
paginationResult.data.length.should.equal(1);

// Test both boolean formats
return models.Post.findPage({limit: 10, staticPages: '1'});
}).then(function (paginationResult) {
paginationResult.meta.pagination.page.should.equal(1);
paginationResult.meta.pagination.limit.should.equal(10);
paginationResult.meta.pagination.pages.should.equal(1);
paginationResult.data.length.should.equal(1);

// Test featured pages
return models.Post.findPage({limit: 10, filter: 'featured:true'});
}).then(function (paginationResult) {
Expand Down

0 comments on commit a2ebee3

Please sign in to comment.