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]update user roles failed #1388

Open
daijiezou opened this issue Apr 29, 2024 · 4 comments
Open

[Question]update user roles failed #1388

daijiezou opened this issue Apr 29, 2024 · 4 comments

Comments

@daijiezou
Copy link

Want to prioritize this issue? Try:

issuehunt-to-marktext


What's your scenario? What do you want to achieve?
Your answer here

Your model:

[request_definition]
r = sub, obj

[policy_definition]
p = sub, obj

[role_definition]
g = _, _


[policy_effect]
e = some(where (p.eft == allow))

[matchers]
m = g(r.sub,p.sub) && keyMatch2(r.obj,p.obj)
@casbin-bot
Copy link
Member

@tangyang9464 @JalinWang

@daijiezou
Copy link
Author

I set redis watcher for casbin,when redis service crash, casbin delete user report error,but the user is deleted successful
This is an operation to update a user role. Subsequent operations to add a role for the user cannot be performed properly, and the previous operations to delete the user cannot be rolled back. What should I do in this case

@hsluoyz
Copy link
Member

hsluoyz commented May 7, 2024

@daijiezou plz provide reproduce steps and code example

@daijiezou
Copy link
Author

daijiezou commented May 8, 2024

code example:

mycasbin.Casbin() is a enforcer instance

// step1: delete the role owned by the original user
if _, err := mycasbin.Casbin().DeleteRolesForUser(strconv.Itoa(roleId)); err != nil {
return
}

// step2: update the roles owned by the user
_, err = mycasbin.Casbin().AddRolesForUser(strconv.Itoa(roleId), req.PermissionList)
if err != nil {
return
}

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

No branches or pull requests

3 participants