mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Added missing read pages endpoint
refs #9866 - the endpoints were missing - the site app needs pages.read for v2
This commit is contained in:
parent
8caf8009ae
commit
cbf2817e39
4 changed files with 72 additions and 1 deletions
|
@ -1,4 +1,6 @@
|
|||
const common = require('../../lib/common');
|
||||
const models = require('../../models');
|
||||
const ALLOWED_INCLUDES = ['created_by', 'updated_by', 'published_by', 'author', 'tags', 'authors', 'authors.roles'];
|
||||
|
||||
module.exports = {
|
||||
docName: 'pages',
|
||||
|
@ -18,7 +20,7 @@ module.exports = {
|
|||
validation: {
|
||||
options: {
|
||||
include: {
|
||||
values: ['created_by', 'updated_by', 'published_by', 'author', 'tags', 'authors', 'authors.roles']
|
||||
values: ALLOWED_INCLUDES
|
||||
},
|
||||
formats: {
|
||||
values: models.Post.allowedFormats
|
||||
|
@ -29,5 +31,45 @@ module.exports = {
|
|||
query(frame) {
|
||||
return models.Post.findPage(frame.options);
|
||||
}
|
||||
},
|
||||
|
||||
read: {
|
||||
options: [
|
||||
'include',
|
||||
'filter',
|
||||
'fields',
|
||||
'status',
|
||||
'formats',
|
||||
'debug'
|
||||
],
|
||||
data: [
|
||||
'id',
|
||||
'slug',
|
||||
'status',
|
||||
'uuid'
|
||||
],
|
||||
validation: {
|
||||
options: {
|
||||
include: {
|
||||
values: ALLOWED_INCLUDES
|
||||
},
|
||||
formats: {
|
||||
values: models.Post.allowedFormats
|
||||
}
|
||||
}
|
||||
},
|
||||
permissions: true,
|
||||
query(frame) {
|
||||
return models.Post.findOne(frame.data, frame.options)
|
||||
.then((model) => {
|
||||
if (!model) {
|
||||
throw new common.errors.NotFoundError({
|
||||
message: common.i18n.t('errors.api.pages.pageNotFound')
|
||||
});
|
||||
}
|
||||
|
||||
return model;
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -349,6 +349,9 @@
|
|||
"posts": {
|
||||
"postNotFound": "Post not found."
|
||||
},
|
||||
"pages": {
|
||||
"pageNotFound": "Page not found."
|
||||
},
|
||||
"job": {
|
||||
"notFound": "Job not found.",
|
||||
"publishInThePast": "Use the force flag to publish a post in the past."
|
||||
|
|
|
@ -16,6 +16,8 @@ module.exports = function apiRoutes() {
|
|||
|
||||
// ## Pages
|
||||
router.get('/pages', mw.authenticatePublic, apiv2.http(apiv2.pages.browse));
|
||||
router.get('/pages/:id', mw.authenticatePublic, apiv2.http(apiv2.pages.read));
|
||||
router.get('/pages/slug/:slug', mw.authenticatePublic, apiv2.http(apiv2.pages.read));
|
||||
|
||||
// ## Users
|
||||
router.get('/users', mw.authenticatePublic, apiv2.http(apiv2.users.browse));
|
||||
|
|
|
@ -48,4 +48,28 @@ describe('Pages', function () {
|
|||
should.exist(urlParts.host);
|
||||
});
|
||||
});
|
||||
|
||||
it('read page', function () {
|
||||
const key = localUtils.getValidKey();
|
||||
return request.get(localUtils.API.getApiQuery(`pages/${testUtils.DataGenerator.Content.posts[4].id}/?key=${key}`))
|
||||
.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);
|
||||
jsonResponse.pages.should.have.length(1);
|
||||
|
||||
res.body.pages[0].slug.should.eql(testUtils.DataGenerator.Content.posts[4].slug);
|
||||
|
||||
const urlParts = url.parse(res.body.pages[0].url);
|
||||
should.exist(urlParts.protocol);
|
||||
should.exist(urlParts.host);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue