AlexKhymenko / ngx-permissions

Permission and roles based access control for your angular(angular 2,4,5,6,7,9+) applications(AOT, lazy modules compatible
MIT License
941 stars 128 forks source link

Load permissions by list of roles #151

Closed Tumetsu closed 4 years ago

Tumetsu commented 4 years ago

We have a use case where we list of roles from server the user should have. For example:

ADMIN,
USER,
EDITOR

And we would like to define permissions for each role as such:

    this.roleService.addRole('USER', [
      'viewPost', 'editPost'
    ]);

The problem is that currently as far as I understand the loadPermissions loads the available permissions for the user and the role definitions just lets us to use role names in guards etc.

Would it be possible to use loadPermissions (or rather some other method, e.g. loadRoles) with role, so that it loads all permissions which have been defined for said role?

So for example:

this.roleService.loadRoles(['USER']); 
this.permissionsService.getPermissions(); // would return permissions ['viewPost', 'editPost']

This would make sense in situations where some auth server or whatever knows only the roles of the certain user, and its application's responsibility to know which permissions the said role has in the application (which views to access etc.)

AlexKhymenko commented 4 years ago

Hi @Tumetsu use NgxRolesService .addRoleWithPermissions('ADMIN', ['read', 'write']); added in latest version of the library

more information about roles here

https://github.com/AlexKhymenko/ngx-permissions/wiki/Managing-roles