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

[Feature] support return err in GetPermissionsForUser #1357

Closed
dacongda opened this issue Jan 27, 2024 · 3 comments · Fixed by #1358
Closed

[Feature] support return err in GetPermissionsForUser #1357

dacongda opened this issue Jan 27, 2024 · 3 comments · Fixed by #1358

Comments

@dacongda
Copy link
Contributor

Want to prioritize this issue? Try:

issuehunt-to-marktext


Is your feature request related to a problem? Please describe.

func main() {
	e, err := casbin.NewEnforcer("example/policy.conf", "example/policy.csv")

	if err != nil {
		log.Fatalf("err :adapter: %s", err)
	}

	// e.SetFieldIndex("p", "app", 2)
	e.SetFieldIndex("p", "dom", 1)

	res := e.GetPermissionsForUser("invoice", "app")

	println(len(res))
}
[request_definition]
r = RoleId, domain, TypeQuery, operationName

[policy_definition]
p = RoleId, domain, TypeQuery, operationName, eft, scope

[role_definition]
g = _, _, _

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

[matchers]
m = g(r.RoleId, p.RoleId, r.domain) && r.domain == p.domain && r.TypeQuery == p.TypeQuery && r.operationName == p.operationName

When I use above code and model conf , if have't e.SetFieldIndex("p", "dom", 1) ,the programme will not report any error , and just return an empty result , by the way, it seems that func GetNamedPermissionsForUser only use the first elment of domain list.

Describe the solution you'd like
Throw an error like "dom index is not set, please use enforcer.SetFieldIndex() to set index" or support use dynamic domainIndex

Describe alternatives you've considered
Create a new func that support return err msg or just rewrite this func

Additional context

@casbin-bot
Copy link
Member

@tangyang9464 @JalinWang

@dacongda dacongda changed the title [Feature] [Feature] support return err in GetPermissionsForUser Jan 27, 2024
@hsluoyz hsluoyz removed the question label Jan 28, 2024
@hsluoyz
Copy link
Member

hsluoyz commented Jan 28, 2024

@dacongda can you make a PR?

@ankan20
Copy link

ankan20 commented Feb 6, 2024

Is it assigned to anyone or is it closed?

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

Successfully merging a pull request may close this issue.

4 participants