0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Removed output of "page" filter in Admin/Content APIs

closes https://github.com/TryGhost/Toolbox/issues/332
refs https://github.com/TryGhost/Ghost/issues/10922

- The "page" attirbute has been deprecated long time ago and was kept around in the output for back compatibility reasons. With Ghost 5.0 there's no longer need to return this field or keep around any of the code supporting "page" attribute processing
This commit is contained in:
Naz 2022-05-16 18:35:02 +08:00 committed by naz
parent f5f1221e14
commit 44c72ddd81
8 changed files with 14 additions and 173 deletions

View file

@ -1,26 +1,11 @@
const _ = require('lodash');
const debug = require('@tryghost/debug')('api:canary:utils:serializers:input:pages');
const mapNQLKeyValues = require('@tryghost/nql').utils.mapKeyValues;
const mobiledoc = require('../../../../../lib/mobiledoc');
const url = require('./utils/url');
const slugFilterOrder = require('./utils/slug-filter-order');
const localUtils = require('../../index');
const postsMetaSchema = require('../../../../../data/schema').tables.posts_meta;
const replacePageWithType = mapNQLKeyValues({
key: {
from: 'page',
to: 'type'
},
values: [{
from: false,
to: 'post'
}, {
from: true,
to: 'page'
}]
});
function removeMobiledocFormat(frame) {
if (frame.options.formats && frame.options.formats.includes('mobiledoc')) {
frame.options.formats = frame.options.formats.filter((format) => {
@ -119,8 +104,6 @@ module.exports = {
defaultFormat(frame);
defaultRelations(frame);
}
frame.options.mongoTransformer = replacePageWithType;
},
read(apiConfig, frame) {

View file

@ -1,26 +1,11 @@
const _ = require('lodash');
const debug = require('@tryghost/debug')('api:canary:utils:serializers:input:posts');
const mapNQLKeyValues = require('@tryghost/nql').utils.mapKeyValues;
const url = require('./utils/url');
const slugFilterOrder = require('./utils/slug-filter-order');
const localUtils = require('../../index');
const mobiledoc = require('../../../../../lib/mobiledoc');
const postsMetaSchema = require('../../../../../data/schema').tables.posts_meta;
const replacePageWithType = mapNQLKeyValues({
key: {
from: 'page',
to: 'type'
},
values: [{
from: false,
to: 'post'
}, {
from: true,
to: 'page'
}]
});
function removeMobiledocFormat(frame) {
if (frame.options.formats && frame.options.formats.includes('mobiledoc')) {
frame.options.formats = frame.options.formats.filter((format) => {
@ -127,8 +112,6 @@ module.exports = {
defaultFormat(frame);
defaultRelations(frame);
}
frame.options.mongoTransformer = replacePageWithType;
},
read(apiConfig, frame) {

View file

@ -133,18 +133,12 @@ describe('Posts API', function () {
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
});
it('Cannot receive pages', async function () {
const res = await request.get(localUtils.API.getApiQuery('posts/?filter=page:true'))
it('Returns a validation error when unknown filter key is used', async function () {
await request.get(localUtils.API.getApiQuery('posts/?filter=page:true'))
.set('Origin', config.get('url'))
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
.expect(200);
should.not.exist(res.headers['x-cache-invalidate']);
const jsonResponse = res.body;
should.exist(jsonResponse.posts);
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(0);
.expect(400);
});
it('Can paginate posts', async function () {

View file

@ -20,23 +20,12 @@ describe('api/canary/content/pages', function () {
configUtils.restore();
});
it('Can browse pages with page:false', function () {
it('Returns a validation error when unsupported "page" filter is used', function () {
return request.get(localUtils.API.getApiQuery(`pages/?key=${key}&filter=page:false`))
.set('Origin', testUtils.API.getURL())
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
.expect(200)
.then((res) => {
res.headers.vary.should.eql('Accept-Encoding');
should.exist(res.headers['access-control-allow-origin']);
should.not.exist(res.headers['x-cache-invalidate']);
const jsonResponse = res.body;
should.exist(jsonResponse.pages);
should.exist(jsonResponse.meta);
jsonResponse.pages.should.have.length(0);
});
.expect(400);
});
it('browse pages with slug filter, should order in slug order', function () {

View file

@ -1,9 +1,6 @@
const should = require('should');
const sinon = require('sinon');
const moment = require('moment');
const supertest = require('supertest');
const _ = require('lodash');
const labs = require('../../../../core/shared/labs');
const testUtils = require('../../../utils');
const localUtils = require('./utils');
const configUtils = require('../../../utils/configUtils');
@ -114,47 +111,11 @@ describe('api/canary/content/posts', function () {
});
});
it('browse posts with basic page filter should not return pages', function (done) {
request.get(localUtils.API.getApiQuery(`posts/?key=${validKey}&filter=page:true`))
it('browse posts with unsupported "page" filter returns a request validation error', function () {
return request.get(localUtils.API.getApiQuery(`posts/?key=${validKey}&filter=page:true,featured:true`))
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
.expect(200)
.end(function (err, res) {
if (err) {
return done(err);
}
const jsonResponse = res.body;
should.not.exist(res.headers['x-cache-invalidate']);
should.exist(jsonResponse.posts);
localUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
jsonResponse.posts.should.have.length(0);
done();
});
});
it('browse posts with basic page filter should not return pages', function (done) {
request.get(localUtils.API.getApiQuery(`posts/?key=${validKey}&filter=page:true,featured:true`))
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
.expect(200)
.end(function (err, res) {
if (err) {
return done(err);
}
const jsonResponse = res.body;
should.not.exist(res.headers['x-cache-invalidate']);
should.exist(jsonResponse.posts);
localUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
jsonResponse.posts.should.have.length(2);
jsonResponse.posts.filter(p => (p.page === true)).should.have.length(0);
done();
});
.expect(400);
});
it('browse posts with published and draft status, should not return drafts', function (done) {

View file

@ -35,27 +35,13 @@ describe('Unit: canary/utils/serializers/input/pages', function () {
const frame = {
apiType: 'content',
options: {
filter: 'page:false+tag:eins',
filter: 'tag:eins',
context: {}
}
};
serializers.input.pages.browse(apiConfig, frame);
frame.options.filter.should.eql('(page:false+tag:eins)+type:page');
});
it('combine filters', function () {
const apiConfig = {};
const frame = {
apiType: 'content',
options: {
filter: 'page:false',
context: {}
}
};
serializers.input.pages.browse(apiConfig, frame);
frame.options.filter.should.eql('(page:false)+type:page');
frame.options.filter.should.eql('(tag:eins)+type:page');
});
it('remove mobiledoc option from formats', function () {
@ -130,21 +116,6 @@ describe('Unit: canary/utils/serializers/input/pages', function () {
frame.options.filter.should.eql('(type:page)+status:[draft,published,scheduled]');
});
it('custom page filter', function () {
const apiConfig = {};
const frame = {
apiType: 'content',
options: {
filter: 'page:false',
context: {}
},
data: {}
};
serializers.input.pages.read(apiConfig, frame);
frame.options.filter.should.eql('(page:false)+type:page');
});
it('custom status filter', function () {
const apiConfig = {};
const frame = {

View file

@ -69,52 +69,12 @@ describe('Unit: canary/utils/serializers/input/posts', function () {
type: 'content'
}
},
filter: 'page:true+tag:eins'
filter: 'tag:eins'
}
};
serializers.input.posts.browse(apiConfig, frame);
frame.options.filter.should.eql('(page:true+tag:eins)+type:post');
});
it('combine filters', function () {
const apiConfig = {};
const frame = {
apiType: 'content',
options: {
context: {
user: 0,
api_key: {
id: 1,
type: 'content'
}
},
filter: 'page:true'
}
};
serializers.input.posts.browse(apiConfig, frame);
frame.options.filter.should.eql('(page:true)+type:post');
});
it('combine filters', function () {
const apiConfig = {};
const frame = {
apiType: 'content',
options: {
context: {
user: 0,
api_key: {
id: 1,
type: 'content'
}
},
filter: '(page:true,page:false)'
}
};
serializers.input.posts.browse(apiConfig, frame);
frame.options.filter.should.eql('((page:true,page:false))+type:post');
frame.options.filter.should.eql('(tag:eins)+type:post');
});
it('remove mobiledoc option from formats', function () {

View file

@ -21,7 +21,7 @@ describe('Unit: api/shared/frame', function () {
context: {user: 'id'},
body: {posts: []},
params: {id: 'id'},
query: {include: 'tags', filter: 'page:false', soup: 'yumyum'}
query: {include: 'tags', filter: 'type:post', soup: 'yumyum'}
};
const frame = new shared.Frame(original);
@ -42,7 +42,7 @@ describe('Unit: api/shared/frame', function () {
context: {user: 'id'},
body: {posts: []},
params: {id: 'id'},
query: {include: 'tags', filter: 'page:false', soup: 'yumyum'}
query: {include: 'tags', filter: 'type:post', soup: 'yumyum'}
};
const frame = new shared.Frame(original);