Skip to content

Commit

Permalink
fix: don't check permissions for GET requests
Browse files Browse the repository at this point in the history
Permissions should only deal with POST/PATCH/DELETE - GET requests
should be entirely governed by the visibility layer.
  • Loading branch information
czosel committed Apr 16, 2024
1 parent a6b445d commit 47cc775
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions generic_permissions/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def check_object_permissions(self, request, instance):
Called by get_object().
"""
if request.method == "GET":
return

for handler in ObjectPermissionsConfig.get_handlers(
self.get_serializer().Meta.model
):
Expand Down
5 changes: 3 additions & 2 deletions tests/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
("post", HTTP_201_CREATED),
("patch", HTTP_200_OK),
("delete", HTTP_204_NO_CONTENT),
("get", HTTP_200_OK),
],
)
@pytest.mark.parametrize("use_admin_client", [True, False])
Expand Down Expand Up @@ -63,7 +64,7 @@ def has_object_permission_for_document(self, request, instance):

url = reverse("model1-list")

if method in ["patch", "delete"]:
if method in ["patch", "delete", "get"]:
url = reverse("model1-detail", args=[tm.pk])

data = {"text": "bar"}
Expand All @@ -72,7 +73,7 @@ def has_object_permission_for_document(self, request, instance):

response = getattr(client, method)(url, data=data)

if not use_admin_client:
if not use_admin_client and method != "get":
assert response.status_code == HTTP_403_FORBIDDEN
return

Expand Down

0 comments on commit 47cc775

Please sign in to comment.