ngx-permissions icon indicating copy to clipboard operation
ngx-permissions copied to clipboard

Permission pipe

Open Nosfistis opened this issue 5 years ago • 8 comments

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 avatar Dec 22 '19 20:12 Nosfistis

@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 :-)

AlexKhymenko avatar Dec 23 '19 09:12 AlexKhymenko

Great! If you need any help I can prep a PR.

Nosfistis avatar Dec 23 '19 12:12 Nosfistis

@Nosfistis If You have PR please submit it :-)

AlexKhymenko avatar Dec 23 '19 12:12 AlexKhymenko

@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.

AlexKhymenko avatar Dec 26 '19 16:12 AlexKhymenko

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>

Nosfistis avatar Dec 29 '19 11:12 Nosfistis

@AlexKhymenko hello, can you share your WIP version for now, please?

tplk avatar May 27 '20 11:05 tplk

@tplk it was on old computer. Now its lost forever :-(

AlexKhymenko avatar May 30 '20 15:05 AlexKhymenko

Any news on this?. I can create a pr, but please let me know where i have to start.

denes16 avatar Apr 06 '22 15:04 denes16