ngx-permissions
ngx-permissions copied to clipboard
Permission pipe
I'm submitting a...
[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
While the directive usage is fine, sometimes it's useful having attributes based on permissions. For example, disabling a link cannot be done using directives. A better option would be an impure pipe permission,, returning true/false
like so:
<button [disabled]="'changeSomethingPermission' | ngxPermission">Change</button>
I understand this might not be the most elegant design, but it would fit easily to any attribute, even component input ones.
@Nosfistis This is great idea the pipe will only return true or false.. In this case problem with angular material would be fixed. But i actually need to find time for this. Probably after New Year :-)
Great! If you need any help I can prep a PR.
@Nosfistis If You have PR please submit it :-)
@Nosfistis I actually started figuring out. But i have some problems with API. How You want to use it. For example i can create 2 pipes. ngxPermissionsOnly and ngxPermissionsExcept. But then i can't use them together.
I don't really see a case where both are needed. In the original directives, I also find the case of both [ngxPermissionsExcept]="['ADMIN', 'JOHNY']"
and [ngxPermissionsOnly]="['MANAGER']"
weird; doesn't it mean only 'MANAGER'
can view that div?
If need be, one can combine the 2 pipes using:
<button [disabled]="('changeSomethingPermission' | ngxPermissionOnly) && ('changeSomethingElsePermission' | ngxPermissionExcept)">Change</button>
Then there is another idea of having the permissions as pipe argument:
<button [disabled]="permissionService.permissions$ | async | ngxPermission:'changeSomethingPermission'">Change</button>
@AlexKhymenko hello, can you share your WIP version for now, please?
@tplk it was on old computer. Now its lost forever :-(
Any news on this?. I can create a pr, but please let me know where i have to start.