RafaelVidaurre / angular-permission

Simple route authorization via roles/permissions
MIT License
1.13k stars 212 forks source link

resolve function in state provider problem #426

Closed rotemlevi closed 6 years ago

rotemlevi commented 7 years ago

hey, i got resolve functions on my router, for each state, i have app abstract state and all other state are his children, i expect that if user go into the parent state and does not have the right rule then he will be redirected to the expected state that i specified on the data.permissions.redirectTo but what happens is that all the resolve state on the first child are evaluated before the redirection happens.

      ` $stateProvider
        .state('app', {
            url: '/app',
            abstract: true,
            templateUrl: helper.views('app-h.html'),
            controller: 'AppController',

            resolve: {
                //deps: helper.resolveFor( 'modernizr', 'icons',  'classyloader',  'whirl').deps,
                //deps: helper.resolveFor('fastclick', 'modernizr', 'icons', 'screenfull', 'animo', 'slimscroll', 'classyloader', 'toaster', 'whirl').deps,
                deps: helper.resolveFor('app').deps,
                marketPlaces: ['UserManager', function(UserManager) {

                    return UserManager.getMarketPlaces().then(function(marketPlaces) {
                        return marketPlaces;
                    })
                }],
                timeZones: ['ResourceManager', function(ResourceManager) {

                    return ResourceManager.getTimeZones().then(function(timeZones) {
                        return timeZones;
                    })
                }],
                account: ['SeetingsManager', 'marketPlaces', 'timeZones', function(SeetingsManager, marketPlaces, timeZones) {

                    return SeetingsManager.getAccountSettings(false, marketPlaces, timeZones).then(function(account) {
                        return account;
                    })
                }]
            },
            data: {
                permissions: {
                    only: ['USER'],
                    redirectTo: {
                        isAuthorized: 'public.login',
                        isMWSAuthorized: 'auth.setup',
                        default: 'auth.setup',
                    }
                }
            }
        })

    .state('app.dashboard', {
            url: '/dashboard',
            title: 'Dashboard',
            controller: 'DashboardCtrl',
            templateUrl: helper.views('dashboard.html'),
            resolve: {
                //deps: helper.resolveFor('flot-chart',  'sparkline').deps,
                deps: helper.resolveFor('appDashboard').deps,
                dasboardData: ['DashBoardManager', function(DashBoardManager) {
                    var startDate = moment().subtract(29, 'day').startOf('day');
                    var endDate = moment().endOf('day');
                    console.log(resposne);
                    return DashBoardManager.getDashBoardData(startDate, endDate).then(function(dasboardData) {
                        return dasboardData;
                    })
                }],
            },
        })`
joeljeske commented 7 years ago

Also see https://github.com/Narzerus/angular-permission/pull/397

masterspambot commented 6 years ago

Resolved in v6.0.0