Skip to content

Commit

Permalink
Fixes has_remote_param_obj_perms
Browse files Browse the repository at this point in the history
fixes: pulp#4925
  • Loading branch information
dkliban committed Jan 16, 2024
1 parent efb17a7 commit 0a3a4cf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES/4925.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed RBAC related bug where syncing a repository with a predefined remote required specifying the
remote's HREF at sync time.
5 changes: 4 additions & 1 deletion pulpcore/app/global_access_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,13 @@ def has_remote_param_obj_perms(request, view, action, permission):
"""
kwargs = {}
obj = view.get_object() if view.detail else None
context = {"request": request}
if obj:
context["repository_pk"] = obj.pk
if action == "partial_update":
kwargs["partial"] = True
serializer = view.serializer_class(
instance=obj, data=request.data, context={"request": request}, **kwargs
instance=obj, data=request.data, context=context, **kwargs
)
serializer.is_valid(raise_exception=True)
if remote := serializer.validated_data.get("remote"):
Expand Down
4 changes: 3 additions & 1 deletion pulpcore/tests/functional/api/pulp_file/test_rbac.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,13 @@ def test_repository_apis(
alice, bob, charlie = gen_users(["filerepository", "fileremote"])
# Sync tests
with bob:
repo = file_repository_factory()
bob_remote = file_remote_factory(manifest_path=basic_manifest_path, policy="on_demand")
repo = file_repository_factory(remote=bob_remote.pulp_href)
body = {"remote": bob_remote.pulp_href}
try_action(alice, file_bindings.RepositoriesFileApi, "sync", 403, repo.pulp_href, body)
try_action(bob, file_bindings.RepositoriesFileApi, "sync", 202, repo.pulp_href, body)
# Try syncing without specifying a remote
try_action(bob, file_bindings.RepositoriesFileApi, "sync", 202, repo.pulp_href, {})
try_action(charlie, file_bindings.RepositoriesFileApi, "sync", 404, repo.pulp_href, body)
# Modify tests
try_action(alice, file_bindings.RepositoriesFileApi, "modify", 403, repo.pulp_href, {})
Expand Down

0 comments on commit 0a3a4cf

Please sign in to comment.