Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

state.$$permissionState is not a function #352

Closed
random-one opened this issue Nov 22, 2016 · 5 comments
Closed

state.$$permissionState is not a function #352

random-one opened this issue Nov 22, 2016 · 5 comments

Comments

@random-one
Copy link

random-one commented Nov 22, 2016

I get this error using the unminified version of angular-permission but only in one particular state in my app. It appears to me that for some reason angular-permission does not decorate it with this $$permissionState property as it does on the other states.
Here is a sample of it's state definition:

$stateProvider.state('activation', {
  url: '/activate',
  templateUrl: 'activation.html',
  controller: 'LicenseCtrl as vm',
  data: {
    permissions: {
      only: 'canActivate',
      redirectTo: 'root.home'
    }
  }
});

The canActivate permission is always returning true so that we can always access this state. The other states I am redirecting to activation have following definition:

.state('root.home.settings.offices', {
  url: '/offices',
  controller: 'OfficeBrowserCtrl as vm',
  templateUrl: 'offices.html',
  data: {
    permissions: {
      only: 'isActivated',
      redirectTo: 'activation'
    }
  }
});

Here is the isActivated permission:

PermPermissionStore
    .definePermission('isActivated', function() {
        return License.isActivated().then(function(isActivated) {
            return !!isActivated;
        });
   });

In the case that the isActivated permission is rejected I receive an error code from server that is intercepted and invalidates the License service. When first received the error code is caught by the interceptor that emits a signal. In the run method of the module is the handling:

.run(function(License, $rootScope, $state) {
  $rootScope.$on('not_activated', function(event) {
     License.invalidate();
     $state.go('activation');
   });
})

The $state.go statement is causing the error. Any clues why is it happening? The redirect is happening on the second attempt to access the offices state for example. I tried also to inherit a base abstract state and then use activation but no luck again..

@masterspambot
Copy link
Collaborator

As I see activation state is not inheriting from your root state, so it may not have DI module dependency to angular-permissions when loaded. So of solutions will be changing your state to root.activation (if that won't mess with your views) to properly handle module dependencies.

@random-one
Copy link
Author

random-one commented Nov 22, 2016

My root state has already the isActivated permission. So if I make activation to inherit it I should add except permisssion for it and it didn't look very logic to me so I left it separate. Can't I just declare in the license/activation module(because it's another module) too that it depends on angular-permission?

@masterspambot
Copy link
Collaborator

Yes you can of course :)

@random-one
Copy link
Author

@masterspambot I just tried and adding angular-permission to the DI of the module stopped the error from happening. But does that mean I should add it to all my submodules just to be sure that it's decorating all substates?

@masterspambot
Copy link
Collaborator

masterspambot commented Nov 22, 2016

No you don't need to. The case is that activation is ui-router's root state the same way your root state is. All deps are inherited down from from the root itself. You just need assure you have properly set deps only for those.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants