-
Notifications
You must be signed in to change notification settings - Fork 168
feat: Add domain-admin content list endpoint #8084
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
Draft
CryptoRodeo
wants to merge
1
commit into
pulp:main
Choose a base branch
from
CryptoRodeo:feat/domain-admin-content-viewset
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Added a domain-scoped content list endpoint (`/pulp/api/v3/content/domains/`) that lets domain administrators list all content in a domain, including content not in any repository. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
pulpcore/tests/functional/api/test_domain_admin_content.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import os | ||
| import uuid | ||
|
|
||
| import pytest | ||
| from django.conf import settings | ||
|
|
||
| pytestmark = pytest.mark.skipif(not settings.DOMAIN_ENABLED, reason="Domains not enabled.") | ||
|
|
||
|
|
||
| @pytest.mark.parallel | ||
| def test_domain_admin_lists_all_domain_content( | ||
| pulpcore_bindings, | ||
| file_bindings, | ||
| domain_factory, | ||
| gen_user, | ||
| monitor_task, | ||
| tmp_path, | ||
| ): | ||
| domain = domain_factory() | ||
|
|
||
| # Orphan content (not in any repository) uploaded into the domain, with a label. | ||
| temp_file = tmp_path / str(uuid.uuid4()) | ||
| temp_file.write_bytes(os.urandom(128)) | ||
| created = monitor_task( | ||
| file_bindings.ContentFilesApi.create( | ||
| relative_path="a.txt", | ||
| file=str(temp_file), | ||
| pulp_domain=domain.name, | ||
| pulp_labels={"key_a": "value_a"}, | ||
| ).task | ||
| ).created_resources | ||
| href = next(h for h in created if "/content/" in h) | ||
|
|
||
| # A domain-scoped content admin (NOT a repository owner, NOT a superuser). | ||
| user = gen_user(domain_roles=[("core.content_domain_viewer", domain.pulp_href)]) | ||
|
|
||
| with user: | ||
| # Sees the orphan content via the domain-admin endpoint. | ||
| result = pulpcore_bindings.ContentDomainsApi.list(pulp_domain=domain.name) | ||
| assert result.count == 1 | ||
| assert result.results[0].pulp_href == href | ||
|
|
||
| # Label filter works. | ||
| filtered = pulpcore_bindings.ContentDomainsApi.list( | ||
| pulp_domain=domain.name, pulp_label_select="key_a=value_a" | ||
| ) | ||
| assert filtered.count == 1 | ||
| no_match = pulpcore_bindings.ContentDomainsApi.list( | ||
| pulp_domain=domain.name, pulp_label_select="key_a=nope" | ||
| ) | ||
| assert no_match.count == 0 | ||
|
|
||
| # Contrast: the repository-scoped endpoint hides the orphan content. | ||
| repo_scoped = pulpcore_bindings.ContentApi.list(pulp_domain=domain.name) | ||
| assert repo_scoped.count == 0 | ||
|
|
||
|
|
||
| @pytest.mark.parallel | ||
| def test_non_admin_denied( | ||
| pulpcore_bindings, | ||
| domain_factory, | ||
| gen_user, | ||
| ): | ||
| domain = domain_factory() | ||
| user = gen_user() # no roles | ||
|
|
||
| with user: | ||
| with pytest.raises(pulpcore_bindings.ApiException) as ctx: | ||
| pulpcore_bindings.ContentDomainsApi.list(pulp_domain=domain.name) | ||
| assert ctx.value.status == 403 | ||
|
|
||
|
|
||
| @pytest.mark.parallel | ||
| def test_admin_of_one_domain_denied_in_another( | ||
| pulpcore_bindings, | ||
| domain_factory, | ||
| gen_user, | ||
| ): | ||
| domain_a = domain_factory() | ||
| domain_b = domain_factory() | ||
| # Domain admin for domain A only. | ||
| user = gen_user(domain_roles=[("core.content_domain_viewer", domain_a.pulp_href)]) | ||
|
|
||
| with user: | ||
| # Allowed in the domain they administer. | ||
| pulpcore_bindings.ContentDomainsApi.list(pulp_domain=domain_a.name) | ||
| # Denied in a domain they do not administer. | ||
| with pytest.raises(pulpcore_bindings.ApiException) as ctx: | ||
| pulpcore_bindings.ContentDomainsApi.list(pulp_domain=domain_b.name) | ||
| assert ctx.value.status == 403 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| from pulpcore.app.viewsets.content import ContentDomainViewSet | ||
|
|
||
|
|
||
| def test_endpoint_urlpattern(): | ||
| assert ContentDomainViewSet.urlpattern() == "content/domains" | ||
| assert ContentDomainViewSet.routable() is True | ||
|
|
||
|
|
||
| def test_access_policy_gates_on_domain_perms(): | ||
| statements = ContentDomainViewSet.DEFAULT_ACCESS_POLICY["statements"] | ||
| assert statements == [ | ||
| { | ||
| "action": ["list"], | ||
| "principal": "authenticated", | ||
| "effect": "allow", | ||
| "condition": "has_model_or_domain_perms:core.view_content", | ||
| } | ||
| ] | ||
|
|
||
|
|
||
| def test_locked_role_grants_view_content(): | ||
| assert ContentDomainViewSet.LOCKED_ROLES == { | ||
| "core.content_domain_viewer": ["core.view_content"], | ||
| } | ||
|
|
||
|
|
||
| def test_scope_queryset_is_identity(): | ||
| sentinel = object() | ||
| # scope_queryset must not touch the queryset (repository scoping is bypassed) | ||
| assert ContentDomainViewSet.scope_queryset(ContentDomainViewSet(), sentinel) is sentinel |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we put this under domains - so
/domains/is "list all domains", and/domains/content/is "list content for domains"? (or even{domain_href}content/, which is "list content for this domain"?)That would also suggest this be "DomainContentViewSet", and it would live in domain.py instead of content.py. My thinking here, is that this would reinforce that this is a property of domains, more than a property of "content in the instance". wdyt?