disable all module routes if not permission

This commit is contained in:
Daniel Herrero 2017-11-09 12:51:46 +01:00
parent 5c8e997738
commit 563c49b785
2 changed files with 27 additions and 19 deletions

View File

@ -11,8 +11,8 @@ function loader(moduleName, validations) {
return load;
}
config.$inject = ['$stateProvider', '$urlRouterProvider', 'aclServiceProvider'];
function config($stateProvider, $urlRouterProvider, aclServiceProvider) {
config.$inject = ['$stateProvider', '$urlRouterProvider', 'aclServiceProvider', 'modulesFactoryProvider'];
function config($stateProvider, $urlRouterProvider, aclServiceProvider, modulesFactory) {
splitingRegister.registerGraph(deps);
let aclService = aclServiceProvider.$get();
@ -41,7 +41,11 @@ function config($stateProvider, $urlRouterProvider, aclServiceProvider) {
let fileRoutes = window.routes[file].routes;
let moduleName = window.routes[file].module;
let validations = window.routes[file].validations || false;
fileRoutes.forEach(function(route) {
let mainModule = modulesFactory.$get().getMainRoute(fileRoutes);
if (mainModule) {
let count = fileRoutes.length;
for (let i = 0; i < count; i++) {
let route = fileRoutes[i];
if (aclService.routeHasPermission(route)) {
$stateProvider.state(route.state, {
url: route.url,
@ -54,8 +58,11 @@ function config($stateProvider, $urlRouterProvider, aclServiceProvider) {
routes: fileRoutes
}
});
} else if (route.state === mainModule.state) {
break;
}
}
}
});
}
}
ngModule.config(config);

View File

@ -1,7 +1,7 @@
import ngModule from './module';
function modulesFactory(aclService) {
function _getMainRoute(routeCollection) {
function getMainRoute(routeCollection) {
let cant = routeCollection.length;
for (let i = 0; i < cant; i++) {
if (!routeCollection[i].abstract) {
@ -18,7 +18,7 @@ function modulesFactory(aclService) {
name: routes[file].name || routes[file].module,
icon: routes[file].icon || ''
};
let mainRoute = _getMainRoute(window.routes[file].routes);
let mainRoute = getMainRoute(window.routes[file].routes);
if (mainRoute && aclService.routeHasPermission(mainRoute)) {
card.route = mainRoute;
modules.push(card);
@ -28,7 +28,8 @@ function modulesFactory(aclService) {
}
return {
getModules: getModules
getModules: getModules,
getMainRoute: getMainRoute
};
}
modulesFactory.$inject = ['aclService'];