Skip to content

Commit

Permalink
Optional permissions_assignment and creation_hooks
Browse files Browse the repository at this point in the history
These fields were both required by the serializer, which could never
validate.

fixes #9639
  • Loading branch information
mdellweg committed Dec 15, 2021
1 parent 2328f2a commit 9a349a8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGES/9639.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed an api schema bug where both ``permission_assignment`` and ``creation_hooks`` were required
by the ``AccessPolicy`` serializer.
2 changes: 2 additions & 0 deletions pulpcore/app/serializers/access_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ class AccessPolicySerializer(ModelSerializer):
"This is deprecated. Use `creation_hooks` instead."
),
source="creation_hooks",
required=False,
)

creation_hooks = serializers.ListField(
child=serializers.DictField(),
help_text=_("List of callables that may associate user roles for new objects."),
required=False,
)

statements = serializers.ListField(
Expand Down
10 changes: 4 additions & 6 deletions pulpcore/tests/functional/api/test_access_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def test_statements_attr_can_be_modified(self):
self.assertTrue(task_access_policy.customized)
self.assertEqual(task_access_policy.statements, [])

self.access_policy_api.partial_update(tasks_href, {"statements": original_statements})
self.access_policy_api.reset(tasks_href)
task_access_policy = self.access_policy_api.read(tasks_href)
self.assertTrue(task_access_policy.customized)
self.assertFalse(task_access_policy.customized)
self.assertEqual(task_access_policy.statements, original_statements)

def test_creation_hooks_attr_can_be_modified(self):
Expand All @@ -72,11 +72,9 @@ def test_creation_hooks_attr_can_be_modified(self):
self.assertTrue(groups_access_policy.customized)
self.assertEqual(groups_access_policy.creation_hooks, [])

self.access_policy_api.partial_update(
groups_href, {"creation_hooks": original_creation_hooks}
)
self.access_policy_api.reset(groups_href)
groups_access_policy = self.access_policy_api.read(groups_href)
self.assertTrue(groups_access_policy.customized)
self.assertFalse(groups_access_policy.customized)
self.assertEqual(groups_access_policy.creation_hooks, original_creation_hooks)

def test_customized_is_read_only(self):
Expand Down

0 comments on commit 9a349a8

Please sign in to comment.