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

Custom strategy function enhancement #86

Open yd021976 opened 6 years ago

yd021976 commented 6 years ago

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

Hi, first, thank you for this great angular module !

Current behavior

Implement with success a authorizedStrategy and/or unauthorisedStrategy. So I can do whatever I want on the DOM element based on the authorized status (true or false).

Expected behavior

I want to do a little bit more complexe strategy behavior based on authorized/unauthorized permissions.

For example, I would know if the unauthorized permission was READ or UPDATE (or whatever...). In my strategy I then can apply multiple DOM manipulations like disable field, hide (or even salt) content, hide section completely ... So, I need a way to know what permissions were rejected or accepted when my strategy is called. After many tries, I can't find a way to get which permissions success/failed in the strategy function.

It would be great if you can add "authorisedPermissions" and "unauthorisedPermissions" in the strategy function signature in addition of "templateRef".

Environment


Angular version: 6.2.1
ngx-permissions version: 6.0.2

Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [X ] Safari (desktop) version 12
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX            
AlexKhymenko commented 6 years ago

@yd021976 Ohhhhhh didn't expect this one :-) Not sure how to implement it.... For now you can just nest directive in directive

<div  *ngxPermissionsOnly="'write'; authorisedStrategy: disabledFunc; unauthorisedStrategy:enableFunc">
            <div *ngxPermissionsOnly="'READ '; authorisedStrategy: something else; unauthorisedStrategy: 
                something ele">123</div>
         </div>`} 
yd021976 commented 6 years ago

@AlexKhymenko Humm... didn't get it right now :-) If I understand I should create as many strategy functions as permissions ? I'll give it a try, but I'm afraid the DOM manipulation will be tricky because of parsing nested DOM elements (parent, sibling, child etc...).

For example, how in strategy function should I know that I must get the parent element instead of sibling ?

Are you ok if I work on a PR and submit it to you ? Give me some weeks because it's just a hobby :-)

yd021976 commented 6 years ago

Hi @AlexKhymenko , i've forked your project and upgrade it to angular V7.0.1. So I've made many changes, more particularly in project structure and use the ng-packagr and angular library instead of your custom gulp to build library ==> This way, it is very simple to debug library with sourcemaps.

Note that I never use karma or other unit automated test tools, so I removed the root UT conf files and didn't update the new ones generated by Angular (says ng new library).

Do you want create a PR to upgrade your lib to angular V7 with my work ?

Thank you !

AlexKhymenko commented 6 years ago

@yd021976 Im always open to pull requests, just test should be working, cause they saved me so many times :-)

yd021976 commented 6 years ago

Great ! I've created PR #89 for this. I'd be happy if you validate it :-)