RafaelVidaurre / angular-permission

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

Customized condition on permission doesn't re-run after condition changes #421

Closed SimonSimCity closed 7 years ago

SimonSimCity commented 7 years ago

Today, I tried to create a permission, where the condition changes dynamically. When I now f.e. have a shared property I rely on, the condition isn't re-run if the property changes.

Here's the code I have on my controller:

    PermPermissionStore
      .definePermission(
        'seeProjects',
        () => !!Meteor.user() && !!Meteor.user().roles && !!Meteor.user().roles.find((r) => r._id === 'projects.view')
      );

    this.seeProjects = () => !!Meteor.user() && !!Meteor.user().roles && !!Meteor.user().roles.find((r) => r._id === 'projects.view');

And here's a snippet of my template, where the first button dynamically shows if the user has the role in my array Meteor.user().roles:

<md-button ui-sref="projects" ng-if="seeProjects()">
  {{ 'allProjects' | translate }}
</md-button>
<md-button ui-sref="projects" permission permission-only="'seeProjects'">
  {{ 'allProjects' | translate }}
</md-button>

I've tested it using angular-permission in v5.3.1 and ui-router in v0.3.2.

I saw you adviced others to call $state.reload() - well, that's what I tried. And I got the following exception:


Error: Cannot transition to abstract state '[object Object]'
    at Object.transitionTo (printer.js:170)
    at Object.reload (printer.js:170)
masterspambot commented 7 years ago

I think you have a problem with state tree structure... I can assume if you reload page in that state you will receive the same error.

Bear in mind that this issue is out of scope of this library, but is related to your business logic case and code.