fix: field_index is incorrect in RBAC with domains mode (#345) #346
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.
Short description
get_all_named_{things}
functions (things can beactions
,subjects
,roles
) uses hard-coded index for getting "things" from policies, which causes wrong result when using RBAC with domains mode (which a new fielddomain
is inserted to the index 1).The PR does:
Model.get_field_index
for getting correct field index when getting the actions, subjectsDetails
The root cause
get_all_named_{things}
functions (things can beactions
,subjects
,roles
) use fixed field index 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 (field_index=1
) in other mode.Solution of this PR
To make
pycasbin
works correctly, thefield_index
of "things"(actions
,subjects
,roles
) should be determined from the config file (instead of hard-coded). TheModel.get_field_index
method is used in this PR for getting correct index from config.What's more
Changes to documentation
Now
pycasbin
can detect the position ofdom
andact
, there's no need to explicitly set the field index ofdom
usingset_field_index
API.Similar situation
Now
get_all_named_roles
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 #345