Move to 404 page if specified navigation not found

When refresh or link directly to ngdetails without correct navigation
to be set, ngdetails view can not reproduce navigations, i.e. sidebar
and breadcrumb.
e.g. when the ordinary user try to open the URL specified as admin side.

In this situation, ngdetails view should show 404 page.
So this patch move to 404 page if the navigation does not exist.

Change-Id: I7aeeddf838923d110703bfd7a04699b056c2abd5
Closes-Bug: #1761036
This commit is contained in:
Shu Muto 2018-07-04 16:29:36 +09:00 committed by Ivan Kolodyazhny
parent 872ae60c76
commit 8c03ce0bcc
3 changed files with 23 additions and 1 deletions

View File

@ -24,7 +24,8 @@
getActivePanelUrl: getActivePanelUrl,
collapseAllNavigation: collapseAllNavigation,
expandNavigationByUrl: expandNavigationByUrl,
setBreadcrumb: setBreadcrumb
setBreadcrumb: setBreadcrumb,
isNavigationExists: isNavigationExists
};
/* get URL for active panel on navigation side bar */
@ -105,5 +106,10 @@
breadcrumb.append(newItem);
});
}
/* check whether navigation exists from url */
function isNavigationExists(url) {
return angular.element("a.openstack-panel[href='" + url + "']").length ? true : false;
}
}
})();

View File

@ -158,6 +158,18 @@
});
});
describe('isNavigationExists', function() {
it('returns true if navigation for specified URL exists', function() {
var result = service.isNavigationExists('/project/images/');
expect(result).toEqual(true);
});
it('returns false if navigation for specified URL does not exist', function() {
var result = service.isNavigationExists('/not/found/');
expect(result).toEqual(false);
});
});
});
})();

View File

@ -74,6 +74,10 @@
if (query.hasOwnProperty("nav")) {
url = query.nav;
}
// check navigation from url
if (!navigationsService.isNavigationExists(url)) {
pageNotFound();
}
// set navigations (side bar and breadcrumb)
var labels = navigationsService.expandNavigationByUrl(url);
navigationsService.setBreadcrumb(labels);