feat: GetAllObjects has wrong result in RBAC with domains model #1411
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix: #1409
Short description
Details
The root cause
GetAll{things}
andGetAllNamed{things}
functions (things can beactions
,subjects
,roles
) use hard-codedfieldIndex
while fetching the corresponding resources, which causes incorrect behavior when the field indexes change.According to the documentation, the RBAC mode with domains have the convenient putting
domain
as the second param of a policy, while thesubject
is located at the second param (fieldIndex=1
) in other mode.Solution of this PR
To make
casbin
works correctly, thefieldIndex
of "things"(actions
,subjects
,roles
) should be determined from the config file (instead of hard-coded).For
GetAllNamed{things}
functions, theModel.get_field_index
method is used for getting correct index from config.For
GetAll{things}
, thefieldIndex
may be different in differentptype
. Thus, a new functionGetValuesForFieldInPolicyAllTypesByName
is defined to findfieldIndex
in differentptype
by field's name (e.g.obj
,act
).What's more
Changes to documentation
Now
casbin
can detect the position ofdom
andact
correctly with no extra configuration needed. Setting the field index ofdom
usingSetFieldIndex
API explicitly is no longer necessary. The document may need to be changed.Similar situation
Now
GetAllRoles
andGetAllNamedRoles
is still using hard-coded field index (but it won't fail in RBAC with domains mode), this can be optimized using similar API.Close #1409