🐛 Fixed /edit url redirecting to wrong admin client url

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
This commit is contained in:
kirrg001 2019-03-11 15:04:52 +01:00
parent 0a846002f8
commit 160d50a258
4 changed files with 14 additions and 6 deletions

View File

@ -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}`);
}
/**

View File

@ -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();

View File

@ -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) {

View File

@ -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;