casbin icon indicating copy to clipboard operation
casbin copied to clipboard

[Feature] should we add paging feature for getRolesForUser or getPermissionsForUser API?

Open iyjian opened this issue 3 years ago • 14 comments

**Want to prioritize this issue? LOW

Is your feature request related to a problem? Please describe. when a user get a large scale of roles or permission, it is imposible to get all of the permissions or roles in one request.

Describe the solution you'd like I'd like to add a pagnation options for those API.

Describe alternatives you've considered I am not sure if we already have an alternative to cover this situation.

iyjian avatar May 26 '22 03:05 iyjian

@tangyang9464 @closetool @sagilio

casbin-bot avatar May 26 '22 03:05 casbin-bot

@iyjian how many objects do you query?

hsluoyz avatar May 26 '22 08:05 hsluoyz

for a user, there may be thousands of thousands of granted permission objects, and we have a portal to view this objects, so I was wondering if we have a way to paging this results on the server side.

iyjian avatar May 26 '22 09:05 iyjian

@hsluoyz

iyjian avatar May 26 '22 14:05 iyjian

@tangyang9464

hsluoyz avatar May 26 '22 15:05 hsluoyz

@iyjian We don't have this option. Could you make a PR for this?

tangyang9464 avatar May 27 '22 11:05 tangyang9464

I can try

iyjian avatar May 27 '22 12:05 iyjian

the proposal is add pagnation arguments for method getpermissionsforuser, just like:

getpermissionsforuser(user = 'user1', page = 1, limit = 1000000)

page and limit should with a default value for adopting old version.

is it ok?

iyjian avatar May 27 '22 12:05 iyjian

the proposal is add pagnation arguments for method getpermissionsforuser, just like:

getpermissionsforuser(user = 'user1', page = 1, limit = 1000000)

page and limit should with a default value for adopting old version.

is it ok?

@iyjian Because getpermissionsforuser traverses all policies and then filters out those that meet the requirements. If we query the second page, should we need to traverse from the beginning?

tangyang9464 avatar May 27 '22 12:05 tangyang9464

it depens on adapter implement. It can be a cursor.

iyjian avatar May 27 '22 12:05 iyjian

it depens on adapter implement. It can be a cursor.

In fact getpermissionsforuser queries the policies in memory instead of querying the database through the adapter

tangyang9464 avatar May 27 '22 13:05 tangyang9464

does getpermissionsforuser intended for searching permissions for management? if so, I think we should implement it in adapter.

iyjian avatar May 27 '22 13:05 iyjian

@iyjian what adapter do you use?

hsluoyz avatar May 28 '22 02:05 hsluoyz

does getpermissionsforuser intended for searching permissions for management? if so, I think we should implement it in adapter.

@iyjian The memory is consistent with the policies in the database. Can reading from adapter bring any changes?

tangyang9464 avatar May 28 '22 03:05 tangyang9464

@iyjian you can extend the role manager and its GetRoles() function to have pagination.

hsluoyz avatar Dec 08 '22 13:12 hsluoyz