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

As a developer, I can make permission object filtering chainable #2066

Open
fao89 opened this issue Jan 17, 2022 · 3 comments
Open

As a developer, I can make permission object filtering chainable #2066

fao89 opened this issue Jan 17, 2022 · 3 comments
Labels

Comments

@fao89
Copy link
Member

fao89 commented Jan 17, 2022

Author: @bmbouter (bmbouter)

Redmine Issue: 9613, https://pulp.plan.io/issues/9613


Motivation

As a developer with the new Roles facilities in pulpcore==3.17, you likely will want to filter by permissions with something like this example taken from this PR.

current_user = get_current_authenticated_user()
qs = Task.objects.filter(finished_at__lt=finished_before, state__in=states)
units_deleted, details = get_objects_for_user(current_user, "core.delete_task", qs=qs).delete()

As you can see, this needs to determine who the current user is, and you can't build the queryset in one go by using chaining.

Proposal

Introduce a with_perm chainable call on all querysets for Pulp objects. It could be used like this:

  • qs.with_perm("core.task_delete")
  • qs.with_perm("core.task_delete", "core.task_view")
  • qs.with_perms(["core.task_delete", "core.task_view"])
  • qs.with_perm("core.task_delete").with_perm( "core.task_view")
@fao89
Copy link
Member Author

fao89 commented Jan 17, 2022

From: @gerrod3 (gerrod)
Date: 2021-12-07T19:23:50Z


I think it should be mentioned that with_perms will probably call get_authenticated_user implicitly for the permission check. In that case we should probably create our own custom version that can be ran in tasks outside of a django view. Or we would need to make a rule to do all queryset permission checks inside a view before handing off to a task.

@fao89
Copy link
Member Author

fao89 commented Jan 17, 2022

From: @mdellweg (mdellweg)
Date: 2021-12-08T07:54:58Z


If we want to allow both of these syntaxes, we should specify, whether one or all of the permissions are needed:
qs.with_perm("core.task_delete", "core.task_view")
qs.with_perms(["core.task_delete", "core.task_view"])

@dralley dralley added Feature and removed New labels Feb 1, 2022
@stale
Copy link

stale bot commented May 24, 2022

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

@stale stale bot added the stale label May 24, 2022
@dralley dralley removed the stale label May 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants