From 160d50a258cb64d517ebb212e35eb9883e0fb47f Mon Sep 17 00:00:00 2001 From: kirrg001 Date: Mon, 11 Mar 2019 15:04:52 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20/edit=20url=20redirectin?= =?UTF-8?q?g=20to=20wrong=20admin=20client=20url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit no issue - admin client has fixed showing a 500 - we now show a 404 if the url is wrong - server side has corrected the editor url --- core/server/services/routing/controllers/entry.js | 2 +- core/server/services/routing/controllers/preview.js | 6 +++++- .../unit/services/routing/controllers/entry_spec.js | 10 +++++++--- .../unit/services/routing/controllers/preview_spec.js | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/core/server/services/routing/controllers/entry.js b/core/server/services/routing/controllers/entry.js index bafc395b80..63ae7f1967 100644 --- a/core/server/services/routing/controllers/entry.js +++ b/core/server/services/routing/controllers/entry.js @@ -31,7 +31,7 @@ module.exports = function entryController(req, res, next) { // CASE: last param is of url is /edit, redirect to admin if (lookup.isEditURL) { debug('redirect. is edit url'); - return urlService.utils.redirectToAdmin(302, res, '/editor/' + entry.id); + return urlService.utils.redirectToAdmin(302, res, `/editor/${res.routerOptions.resourceType.replace(/s$/, '')}/${entry.id}`); } /** diff --git a/core/server/services/routing/controllers/preview.js b/core/server/services/routing/controllers/preview.js index b1f0a8f80d..27de5fa156 100644 --- a/core/server/services/routing/controllers/preview.js +++ b/core/server/services/routing/controllers/preview.js @@ -24,8 +24,12 @@ module.exports = function previewController(req, res, next) { } if (req.params.options && req.params.options.toLowerCase() === 'edit') { + // @TODO: we don't know which resource type it is, because it's a generic preview handler + // @TODO: figure out how to solve better + const resourceType = post.page ? 'page' : 'post'; + // CASE: last param of the url is /edit, redirect to admin - return urlService.utils.redirectToAdmin(302, res, '/editor/' + post.id); + return urlService.utils.redirectToAdmin(302, res, `/editor/${resourceType}/${post.id}`); } else if (req.params.options) { // CASE: unknown options param detected, ignore return next(); diff --git a/core/test/unit/services/routing/controllers/entry_spec.js b/core/test/unit/services/routing/controllers/entry_spec.js index 23951e709d..87fbf3923a 100644 --- a/core/test/unit/services/routing/controllers/entry_spec.js +++ b/core/test/unit/services/routing/controllers/entry_spec.js @@ -5,7 +5,7 @@ const should = require('should'), urlService = require('../../../../../server/services/url'), controllers = require('../../../../../server/services/routing/controllers'), helpers = require('../../../../../server/services/routing/helpers'), - EDITOR_URL = '/editor/'; + EDITOR_URL = `/editor/post/`; describe('Unit - services/routing/controllers/entry', function () { let req, res, entryLookUpStub, secureStub, renderStub, post, page; @@ -45,7 +45,9 @@ describe('Unit - services/routing/controllers/entry', function () { }; res = { - routerOptions: {}, + routerOptions: { + resourceType: 'posts' + }, render: sinon.spy(), redirect: sinon.spy() }; @@ -125,7 +127,9 @@ describe('Unit - services/routing/controllers/entry', function () { done(); }); - controllers.entry(req, res); + controllers.entry(req, res, (err) => { + done(err); + }); }); it('type of router !== type of resource', function (done) { diff --git a/core/test/unit/services/routing/controllers/preview_spec.js b/core/test/unit/services/routing/controllers/preview_spec.js index 323f6bc4e9..23aa31971a 100644 --- a/core/test/unit/services/routing/controllers/preview_spec.js +++ b/core/test/unit/services/routing/controllers/preview_spec.js @@ -8,7 +8,7 @@ const should = require('should'), controllers = require('../../../../../server/services/routing/controllers'), helpers = require('../../../../../server/services/routing/helpers'), urlService = require('../../../../../server/services/url'), - EDITOR_URL = '/editor/'; + EDITOR_URL = '/editor/post/'; describe('Unit - services/routing/controllers/preview', function () { let secureStub, renderStub;