mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Reworked preview controller output
refs https://github.com/TryGhost/Toolbox/issues/332 - With 'page' property being gone from page/post resources we need consistency across internal "preview API" too - the handling is still hacky as we are exposing the "type" property to the preview pages, which is not exposed through Content API. this a long outstanding issue will have to be handled separately
This commit is contained in:
parent
5cd9d97a07
commit
1cc3f66d5f
6 changed files with 25 additions and 5 deletions
|
@ -53,7 +53,8 @@ function formatResponse(post, context) {
|
|||
post: post
|
||||
};
|
||||
|
||||
if (context?.includes('page')) {
|
||||
// NOTE: preview context is a special case where the internal preview api returns the post model's type field
|
||||
if (context?.includes('page') || (context?.includes('preview') && post.type === 'page')) {
|
||||
entry.page = post;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ module.exports = function previewController(req, res, next) {
|
|||
// @TODO: we don't know which resource type it is, because it's a generic preview handler and the
|
||||
// preview API returns {previews: []}
|
||||
// @TODO: figure out how to solve better
|
||||
const resourceType = post.page ? 'page' : 'post';
|
||||
const resourceType = post.type;
|
||||
|
||||
// CASE: last param of the url is /edit, redirect to admin
|
||||
return urlUtils.redirectToAdmin(302, res, `/#/editor/${resourceType}/${post.id}`);
|
||||
|
|
|
@ -12,6 +12,6 @@ module.exports = {
|
|||
frame.response = {
|
||||
previews: [data]
|
||||
};
|
||||
frame.response.previews[0].page = model.get('type') === 'page';
|
||||
frame.response.previews[0].type = model.get('type');
|
||||
}
|
||||
};
|
||||
|
|
|
@ -60,6 +60,24 @@ describe('Frontend Routing: Preview Routes', function () {
|
|||
});
|
||||
});
|
||||
|
||||
it('should redirect draft posts accessed via uuid and edit to admin post edit screen', async function () {
|
||||
await request.get('/p/d52c42ae-2755-455c-80ec-70b2ec55c903/edit/')
|
||||
.expect('Content-Type', /text\/plain/)
|
||||
.expect(302)
|
||||
.expect('Location', /ghost\/#\/editor\/post\/\w+/)
|
||||
.expect('Cache-Control', testUtils.cacheRules.public)
|
||||
.expect(assertCorrectFrontendHeaders);
|
||||
});
|
||||
|
||||
it('should redirect draft page accessed via uuid and edit to admin page edit screen', async function () {
|
||||
await request.get('/p/d52c42ae-2755-455c-80ec-70b2ec55c904/edit/')
|
||||
.expect('Content-Type', /text\/plain/)
|
||||
.expect(302)
|
||||
.expect('Location', /ghost\/#\/editor\/page\/\w+/)
|
||||
.expect('Cache-Control', testUtils.cacheRules.public)
|
||||
.expect(assertCorrectFrontendHeaders);
|
||||
});
|
||||
|
||||
it('should redirect published posts to their live url', async function () {
|
||||
await request.get('/p/2ac6b4f6-e1f3-406c-9247-c94a0496d39d/')
|
||||
.expect(301)
|
||||
|
|
|
@ -51,6 +51,6 @@ describe('Unit: canary/utils/serializers/output/previews', function () {
|
|||
mappers.posts.callCount.should.equal(1);
|
||||
mappers.posts.getCall(0).args.should.eql([ctrlResponse, frame, {tiers: []}]);
|
||||
|
||||
frame.response.previews[0].page.should.equal(true);
|
||||
frame.response.previews[0].type.should.equal('page');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -80,7 +80,8 @@ DataGenerator.Content = {
|
|||
slug: 'static-page-draft',
|
||||
mobiledoc: DataGenerator.markdownToMobiledoc('<h1>Static page test is what this is for.</h1><p>Hopefully you don\'t find it a bore.</p>'),
|
||||
type: 'page',
|
||||
status: 'draft'
|
||||
status: 'draft',
|
||||
uuid: 'd52c42ae-2755-455c-80ec-70b2ec55c904'
|
||||
},
|
||||
{
|
||||
id: '618ba1ffbe2896088840a6ed',
|
||||
|
|
Loading…
Add table
Reference in a new issue