From 02be78854fd046f52c945deb57fcea34736accad Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Thu, 8 Dec 2022 11:14:22 -0600 Subject: [PATCH] Issue 221: Return to Safety, results in going back to 403. This is happening because of a double redirect. When going to the `/management` page, a browser is redirected to `/management/internal-metadata`. Then the last route ends up referring to the `/management` page, which is the route path of `/management/:tab`. The `:tab` is not a valid part of the URL because the `$scope.lastRoute` is expected to be a path rather than a route. Rather than rename `lastRoute` to `lastPath`: 1. Add a comment describing this behavior. 2. Wrap the assignment in a function that changes the path if any route parts are found. --- app/controllers/errorPageController.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/app/controllers/errorPageController.js b/app/controllers/errorPageController.js index f455cd6d..02ef85be 100644 --- a/app/controllers/errorPageController.js +++ b/app/controllers/errorPageController.js @@ -1,5 +1,25 @@ core.controller("ErrorPageController", function ($scope, AccessControlService) { - $scope.lastRoute = AccessControlService.getLastRoutePath(); + $scope.getPath = function (path) { + + if (!!path && path.length > 0) { + var paths = path.split('/'); + + for (var i in paths) { + // Return to top-level when previous path contains route variables. + if (paths[i][0] === ':') { + paths = []; + break; + } + } + + return paths.join('/'); + } + + return path; + }; + + // This is actually a URL path and not a route. + $scope.lastRoute = $scope.getPath(AccessControlService.getLastRoutePath()); });