pulp / pulp/pulpcore

As a developer, I can make permission object filtering chainable

Open
#2,066 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Feature
Dominant language
Python
Stars
598
Forks
168
Avg merge
1d 4h
Merged PRs (30d)
86

Description

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")

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start from the get_objects_for_user example and the Task.objects queryset shown in the issue. Determine how Pulp object querysets currently apply permission filtering and how a chainable with_perm or with_perms API should compose multiple permissions. Done means permission-filtered querysets support the listed chained and multi-permission forms.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
authorization, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.