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

[Question] Is it possible to do a filtered deleteRolesForUser? #273

Closed
benmkramer opened this issue May 25, 2021 · 5 comments
Closed

[Question] Is it possible to do a filtered deleteRolesForUser? #273

benmkramer opened this issue May 25, 2021 · 5 comments
Assignees
Labels
question Further information is requested

Comments

@benmkramer
Copy link

What's your scenario? What do you want to achieve?
Clearing out some roles for a user and applying new ones.

Your policy:

g2, user_1, action1
g, user_1, thing1
g, user_1, thing2
g, user_2, thing1

What I want to do is clear out the g, user_1, * lines. Currently what I'm doing is something like the following...

const roles = e.getRolesForUser("user_1");
const filteredRoles = roles.filter(/* ... */); // filter to just the ones I care about
await Promise.all(
  filteredRoles.map(role => e.deleteRoleForUser("user_1", role);
)

What I'm not clear on is how I can avoid iterating over each role and deleting it. Is there an equivalent batch call, like deleteRolesForUser("user_1", roles) ? I only see support for deleteRolesForUser("user_1") which also clears out ones I don't want to include.

Thank you!

@hsluoyz hsluoyz transferred this issue from casbin/casbin May 25, 2021
@hsluoyz
Copy link
Member

hsluoyz commented May 25, 2021

@Zxilly

@hsluoyz hsluoyz added the question Further information is requested label May 25, 2021
@Zxilly
Copy link
Contributor

Zxilly commented May 25, 2021

I will later add this.

@MRGUOKING
Copy link
Member

@benmkramer you can use the API "RemoveFilteredGroupingPolicy()". the param is your roles filter .RemoveFilteredGroupingPolicy()
image

@Zxilly
Copy link
Contributor

Zxilly commented Jun 12, 2021

@MRGUOKING In fact, he wants to use match function in the RemoveFilteredGroupingPolicy.
To implement this, we must introduce a series of new API. I'm still finding any other way to implement this.

@Zxilly
Copy link
Contributor

Zxilly commented Jul 3, 2021

Close for stale

@Zxilly Zxilly closed this as completed Jul 3, 2021
@hsluoyz hsluoyz removed this from Node-Casbin Easy Tasks in Casbin Easy Tasks for Beginners/Student Applicants Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants