Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom strategy function enhancement #86

Open
yd021976 opened this issue Oct 19, 2018 · 5 comments
Open

Custom strategy function enhancement #86

yd021976 opened this issue Oct 19, 2018 · 5 comments

Comments

@yd021976
Copy link

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
Copy link
Owner

@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
Copy link
Author

@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
Copy link
Author

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
Copy link
Owner

AlexKhymenko commented Oct 29, 2018

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

@yd021976
Copy link
Author

yd021976 commented Nov 4, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants