Skip to content

Commit

Permalink
fix: feat: check permissions only if ?include_perms
Browse files Browse the repository at this point in the history
fixes type/testing issues with previous commit
  • Loading branch information
pomegranited committed Jan 11, 2024
1 parent 1e2d9b0 commit b9797ab
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions openedx_tagging/core/tagging/rest_api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def get_can_tag_object(self, instance) -> Optional[bool]:
model = self._model
app_label = model._meta.app_label
perm_name = f'{app_label}.add_objecttag'
perm_object = ObjectTagPermissionItem(taxonomy=instance, object_id=None)
return request.user.has_perm(perm_name, perm_object)
perm_object = ObjectTagPermissionItem(taxonomy=instance, object_id="")
return request.user.has_perm(perm_name, perm_object) # type: ignore[arg-type]


class ObjectTagListQueryParamsSerializer(serializers.Serializer): # pylint: disable=abstract-method
Expand Down
7 changes: 3 additions & 4 deletions tests/openedx_tagging/core/tagging/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ def test_get_counts_invalid_spec(self):
assert "Wildcard matches are only supported if the * is at the end." in str(result.content)


@ddt.data
@ddt.ddt
class TestTaxonomyTagsView(TestTaxonomyViewMixin):
"""
Tests the list/create/update/delete tags of taxonomy view
Expand Down Expand Up @@ -1442,7 +1442,7 @@ def test_small_query_count(self, include_perms):
expected_perm = True

self.client.force_authenticate(user=self.staff)
with self.assertNumQueries(1):
with self.assertNumQueries(6):
response = self.client.get(url)

assert response.status_code == status.HTTP_200_OK
Expand Down Expand Up @@ -1491,7 +1491,7 @@ def test_large_taxonomy(self, include_perms):
url += "&include_perms"
expected_perm = True

with self.assertNumQueries(1):
with self.assertNumQueries(4):
response = self.client.get(url)

assert response.status_code == status.HTTP_200_OK
Expand Down Expand Up @@ -1746,7 +1746,6 @@ def test_get_leaves_paginated(self):
]
next_url = response.data.get("next")
assert next_url is not None

response2 = self.client.get(next_url)
results2 = response2.data["results"]
assert pretty_format_tags(results2) == [
Expand Down

0 comments on commit b9797ab

Please sign in to comment.