RafaelVidaurre / angular-permission

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

Permissions/roles parameters #407

Closed GabrielGil closed 7 years ago

GabrielGil commented 7 years ago

Hey! First at all I am not sure if this is a feature suggest, or just a question. I have searched the previous issued with no luck.

I am building a organization based app on which there are a set of permissions (i.e. listItems, viewDetails etc) but are linked to each organization the user can access (orgA, orgB). This is, it may be the case the user can listItems of one organization (orgA), but not from another (orgB).

The best way I've found so far is to define the permission, and on the handler check the transitiontoParams and put there my logic.

This approach works fine when accessing states, but when checking a from a directive like permission-only, the toParams is obviously empty. This is specially handful when certain actions are not performed in a separate state, like for example, creating a user within an organization may happen inside a dialog and the app should show the button to open this dialog.

What is the best approach to define a permission that is dependant of one (or more parameters)? Maybe the directives and/or states could send parameters, the same way angular events pass a data object to the handler.

i.e.

PermPermissionStore
  .definePermission('createUsersForOrg', (permissionName, transitionProperties, data) {
        if(data.organizationId == 1) {
          return true;
        } else {
          return false;
      });
  });
<div permission-only="createUsersForOrg" 
    permission-data="{ organizationId: $ctrl.organizationId }">
  <!-- Open new user dialog button -->
</div>
masterspambot commented 7 years ago

This not the scope of this lib. To persist data between state use angular service or factory patterns that are injectable and controlled independently.