🦄 Added /edit/ redirect to admin for post previews (#8836)

no issue

- This already works for posts and channels
- It always felt like a bug that it didn't work for previews
- Now it does 😬
This commit is contained in:
Hannah Wolfe 2017-08-08 08:32:55 +01:00 committed by Katharina Irrgang
parent fddabde2fc
commit dbd7060e69
3 changed files with 31 additions and 1 deletions

View File

@ -25,7 +25,7 @@ frontendRoutes = function frontendRoutes() {
});
// Post Live Preview
router.get(utils.url.urlJoin('/', routeKeywords.preview, ':uuid'), frontend.preview);
router.get(utils.url.urlJoin('/', routeKeywords.preview, ':uuid', ':options?'), frontend.preview);
// Channels
router.use(channels.router());

View File

@ -50,6 +50,14 @@ frontendControllers = {
return next();
}
if (req.params.options && req.params.options.toLowerCase() === 'edit') {
// CASE: last param is of url is /edit, redirect to admin
return res.redirect(utils.url.urlJoin(utils.url.urlFor('admin'), 'editor', post.id, '/'));
} else if (req.params.options) {
// CASE: unknown options param detected. Ignore and end in 404.
return next();
}
if (post.status === 'published') {
return res.redirect(301, utils.url.urlFor('post', {post: post}));
}

View File

@ -801,5 +801,27 @@ describe('Frontend Controller', function () {
frontend.preview(req, res, failTest(done));
});
it('should call redirect if /edit/ (options param) is detected', function (done) {
req.params = {uuid: 'abc-1234-01', options: 'edit'};
res.redirect = function (url) {
res.render.called.should.be.false();
url.should.eql('/ghost/editor/1/');
done();
};
frontend.preview(req, res, failTest(done));
});
it('should call next for unknown options param detected', function (done) {
req.params = {uuid: 'abc-1234-01', options: 'asdsad'};
frontend.preview(req, res, function (err) {
should.not.exist(err);
res.render.called.should.be.false();
res.redirect.called.should.be.false();
done();
});
});
});
});