Skip to content

Commit

Permalink
Fix creation hooks being called for Upload
Browse files Browse the repository at this point in the history
The mixin for automatic calling of creation hooks was missing on the
Upload model.

fixes #5199

(cherry picked from commit 9192c2b)
  • Loading branch information
mdellweg committed Apr 11, 2024
1 parent e50d28f commit 66ca0ed
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGES/5199.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix Upload failing to run post create hooks.
On installations using the default access policy, this fixes the automatic owner assignment for
users with the `core.upload_create` role on upload objects.
4 changes: 2 additions & 2 deletions pulpcore/app/models/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
from django.dispatch import receiver
from rest_framework import serializers

from pulpcore.app.models import BaseModel, fields, storage
from pulpcore.app.models import BaseModel, fields, storage, AutoAddObjPermsMixin
from pulpcore.app.util import get_domain_pk


class Upload(BaseModel):
class Upload(BaseModel, AutoAddObjPermsMixin):
"""
A chunked upload. Stores chunks until used to create an artifact, etc.
Expand Down
10 changes: 5 additions & 5 deletions pulpcore/tests/functional/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,31 +840,31 @@ def _role_factory(**kwargs):


@pytest.fixture
def gen_user(bindings_cfg, users_api_client, users_roles_api_client, gen_object_with_cleanup):
def gen_user(bindings_cfg, pulpcore_bindings, gen_object_with_cleanup):
class user_context:
def __init__(self, username=None, model_roles=None, object_roles=None, domain_roles=None):
self.username = username or str(uuid.uuid4())
self.password = str(uuid.uuid4())
self.user = gen_object_with_cleanup(
users_api_client, {"username": self.username, "password": self.password}
pulpcore_bindings.UsersApi, {"username": self.username, "password": self.password}
)
self._saved_credentials = []

if model_roles:
for role in model_roles:
users_roles_api_client.create(
pulpcore_bindings.UsersRolesApi.create(
auth_user_href=self.user.pulp_href,
user_role={"role": role, "domain": None, "content_object": None},
)
if domain_roles:
for role, domain in domain_roles:
users_roles_api_client.create(
pulpcore_bindings.UsersRolesApi.create(
auth_user_href=self.user.pulp_href,
user_role={"role": role, "domain": domain, "content_object": None},
)
if object_roles:
for role, content_object in object_roles:
users_roles_api_client.create(
pulpcore_bindings.UsersRolesApi.create(
auth_user_href=self.user.pulp_href,
user_role={"role": role, "domain": None, "content_object": content_object},
)
Expand Down
13 changes: 13 additions & 0 deletions pulpcore/tests/functional/api/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,16 @@ def test_delete_upload(
uploads_api_client.read(upload.pulp_href)

assert e.value.status == 404


def test_upload_owner(pulpcore_bindings, gen_user, gen_object_with_cleanup):
user = gen_user(model_roles=["core.upload_creator"])
with user:
upload = gen_object_with_cleanup(pulpcore_bindings.UploadsApi, {"size": 1024})
pulpcore_bindings.UploadsApi.read(upload.pulp_href)
assert set(pulpcore_bindings.UploadsApi.my_permissions(upload.pulp_href).permissions) == {
"core.view_upload",
"core.change_upload",
"core.delete_upload",
"core.manage_roles_upload",
}

0 comments on commit 66ca0ed

Please sign in to comment.