0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Fixed /edit shortcut route for pages

refs https://github.com/TryGhost/Toolbox/issues/332
refs f5f1221e14

- Adding an `/edit/` post-fix to a static page URL broke when the `page: true` property support was dropped in the Content API
- The changeset adds tests covering the scenario for both page and post resources
This commit is contained in:
Naz 2022-05-17 14:31:31 +08:00
parent 5abd67809d
commit 3ff757fbad
2 changed files with 18 additions and 14 deletions

View file

@ -40,7 +40,7 @@ module.exports = function entryController(req, res, next) {
}
debug('redirect. is edit url');
const resourceType = entry.page ? 'page' : 'post';
const resourceType = res.routerOptions?.context?.includes('page') ? 'page' : 'post';
return urlUtils.redirectToAdmin(302, res, `/#/editor/${resourceType}/${entry.id}`);
}

View file

@ -156,28 +156,32 @@ describe('Frontend Routing', function () {
});
describe('edit', function () {
it('should redirect without slash', function (done) {
request.get('/static-page-test/edit')
it('should redirect without slash', async function () {
await request.get('/static-page-test/edit')
.expect('Location', '/static-page-test/edit/')
.expect('Cache-Control', testUtils.cacheRules.year)
.expect(301)
.end(doEnd(done));
.expect(301);
});
it('should redirect to editor', function (done) {
request.get('/static-page-test/edit/')
.expect('Location', /ghost\/#\/editor\/\w+/)
it('should redirect to editor for post resource', async function () {
await request.get('//welcome/edit/')
.expect('Location', /ghost\/#\/editor\/post\/\w+/)
.expect('Cache-Control', testUtils.cacheRules.public)
.expect(302)
.end(doEnd(done));
.expect(302);
});
it('should 404 for non-edit parameter', function (done) {
request.get('/static-page-test/notedit/')
it('should redirect to editor for page resource', async function () {
await request.get('/static-page-test/edit/')
.expect('Location', /ghost\/#\/editor\/page\/\w+/)
.expect('Cache-Control', testUtils.cacheRules.public)
.expect(302);
});
it('should 404 for non-edit parameter', async function () {
await request.get('/static-page-test/notedit/')
.expect('Cache-Control', testUtils.cacheRules.private)
.expect(404)
.expect(/Page not found/)
.end(doEnd(done));
.expect(/Page not found/);
});
});