mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
🔥 Removed 'staticPages' filter (#11135)
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
This commit is contained in:
parent
a30812cce1
commit
a2ebee3f4e
6 changed files with 5 additions and 104 deletions
|
@ -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';
|
||||
|
@ -657,7 +645,6 @@ Post = ghostBookshelf.Model.extend({
|
|||
}
|
||||
|
||||
delete options.status;
|
||||
delete options.staticPages;
|
||||
return filter;
|
||||
},
|
||||
|
||||
|
@ -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']
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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}`))
|
||||
|
|
|
@ -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}`))
|
||||
|
|
|
@ -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}`))
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue