mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
ensure static page edit route redirects to editor (#7169)
closes #7168 - double check that page matches the page format in post-lookup - add tests
This commit is contained in:
parent
03d4137b86
commit
58bb111c56
3 changed files with 36 additions and 14 deletions
|
@ -66,11 +66,6 @@ frontendControllers = {
|
|||
return next();
|
||||
}
|
||||
|
||||
// CASE: we only support /:slug format for pages
|
||||
if (post.page && post.url !== req.path) {
|
||||
return next();
|
||||
}
|
||||
|
||||
// CASE: last param is of url is /edit, redirect to admin
|
||||
if (lookup.isEditURL) {
|
||||
return res.redirect(config.paths.subdir + '/ghost/editor/' + post.id + '/');
|
||||
|
|
|
@ -19,27 +19,23 @@ function postLookup(postUrl) {
|
|||
matchFuncPost,
|
||||
matchFuncPage,
|
||||
postParams,
|
||||
pageParams,
|
||||
params;
|
||||
|
||||
// Convert saved permalink into a path-match function
|
||||
matchFuncPost = routeMatch(getEditFormat(postPermalink));
|
||||
matchFuncPage = routeMatch(getEditFormat(pagePermalink));
|
||||
|
||||
postParams = matchFuncPost(postPath);
|
||||
|
||||
// Check if the path matches the permalink structure.
|
||||
// If there are no matches found, test to see if this is a page instead
|
||||
if (postParams === false) {
|
||||
matchFuncPage = routeMatch(getEditFormat(pagePermalink));
|
||||
pageParams = matchFuncPage(postPath);
|
||||
}
|
||||
params = postParams || matchFuncPage(postPath);
|
||||
|
||||
// If there are still no matches then return empty.
|
||||
if (pageParams === false) {
|
||||
// if there are no matches for either then return empty
|
||||
if (params === false) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
params = postParams || pageParams;
|
||||
|
||||
// If params contains edit, and it is equal to 'edit' this is an edit URL
|
||||
if (params.edit && params.edit.toLowerCase() === 'edit') {
|
||||
isEditURL = true;
|
||||
|
@ -66,6 +62,11 @@ function postLookup(postUrl) {
|
|||
return Promise.resolve();
|
||||
}
|
||||
|
||||
// CASE: we only support /:slug format for pages
|
||||
if (post.page && matchFuncPage(postPath) === false) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
return {
|
||||
post: post,
|
||||
isEditURL: isEditURL
|
||||
|
|
|
@ -240,6 +240,32 @@ describe('Frontend Routing', function () {
|
|||
.expect(200)
|
||||
.end(doEnd(done));
|
||||
});
|
||||
|
||||
describe('edit', function () {
|
||||
it('should redirect without slash', function (done) {
|
||||
request.get('/static-page-test/edit')
|
||||
.expect('Location', '/static-page-test/edit/')
|
||||
.expect('Cache-Control', testUtils.cacheRules.year)
|
||||
.expect(301)
|
||||
.end(doEnd(done));
|
||||
});
|
||||
|
||||
it('should redirect to editor', function (done) {
|
||||
request.get('/static-page-test/edit/')
|
||||
.expect('Location', /^\/ghost\/editor\/[0-9]\/$/)
|
||||
.expect('Cache-Control', testUtils.cacheRules.public)
|
||||
.expect(302)
|
||||
.end(doEnd(done));
|
||||
});
|
||||
|
||||
it('should 404 for non-edit parameter', function (done) {
|
||||
request.get('/static-page-test/notedit/')
|
||||
.expect('Cache-Control', testUtils.cacheRules.private)
|
||||
.expect(404)
|
||||
.expect(/Page not found/)
|
||||
.end(doEnd(done));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Post preview', function () {
|
||||
|
|
Loading…
Add table
Reference in a new issue