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] how to getPermissionByRoleInDomain and getAllRolesInDomain #1036
Comments
@tangyang9464 @closetool @sagilio |
after I try to get both with policy per below
I can getPermissionsForRoleInDomain by this code func getPermissionsForRoleInDomain(e *casbin.Enforcer, role string, domain string) []string {
ps := e.GetPermissionsForUserInDomain(role, domain)
var p []string
for i := range ps {
p = append(p, ps[i][2])
}
return p
}
permissions := getPermissionsForRoleInDomain(e, "admin", "domain1") // output : [data1 data1-1]
permissions = getPermissionsForRoleInDomain(e, "admin2", "domain1") // output : [data2 data2-1 data2-2]
permissions = getPermissionsForRoleInDomain(e, "admin", "domain2") // output : [data3 data3-1 data3-2 data3-3] and getAllRolesInDomain by this code func getRolesInDomain(e *casbin.Enforcer, domain string) []string {
rs := e.GetFilteredPolicy(0, "", domain, "")
var r []string
mapRoles := map[string]struct{}{}
for i := range rs {
roleNames := rs[i][0]
if _, ok := mapRoles[roleNames]; !ok {
mapRoles[roleNames] = struct{}{}
r = append(r, roleNames)
}
}
return r
}
roles := getRolesInDomain(e, "domain1") // output : [admin admin2]
roles = getRolesInDomain(e, "domain2") // output : [admin] |
I think it is reasonable to add the However, for
, the permissions should be be like |
thanks, @JalinWang, and @hsluoyz do you think this is good or not? thanks for your suggestion again :) Edited |
Hi, guys
I read document and didn't see getAllPermissionsByRoleInDomain and getAllRolesInDomain
Do you have way to get this one?
The text was updated successfully, but these errors were encountered: