mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-26 20:34:02 +03:00
🦄 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:
parent
fddabde2fc
commit
dbd7060e69
@ -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());
|
||||
|
@ -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}));
|
||||
}
|
||||
|
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user