Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions backend/problem/views/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
)
from rest_framework.permissions import IsAuthenticated, IsAuthenticatedOrReadOnly

from django.http import Http404
from django.shortcuts import get_object_or_404

from problem.problem_details import (
Expand Down Expand Up @@ -51,18 +52,7 @@ def get_permissions(self):
return [IsAuthenticatedOrReadOnly()]

def list(self, request: Request) -> Response:
"""
Lists all Problems in the database, with optional filtering.
"""
filters = get_filters(request.query_params)

qs = self.get_queryset()

if filters is not None:
qs = qs.filter(filters)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also just filter qs by hidden=False if the current user lacks appropriate permissions (after merging #106). I don't have a strong opinion on the matter though. We can always revert this later if we feel we need a list endpoint.


serializer = self.get_serializer(qs, many=True)
return Response(serializer.data, status=HTTP_200_OK)
raise Http404

@action(detail=False, methods=["get"], url_path="first")
def first(self, request: Request) -> Response:
Expand Down
27 changes: 0 additions & 27 deletions backend/problem/views/problem_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,6 @@ class TestProblemViewPermissions:
Tests for problem view permissions as documented in the README.
"""

# List / browse

def test_unauthenticated_user_can_list_problems(self, client, sample_problem):
"""Unauthenticated users should be able to browse problems (read-only)."""
response = client.get("/api/problem/")
assert response.status_code == status.HTTP_200_OK

def test_visitor_can_list_problems(self, client, visitor, sample_problem):
"""Visitors should be able to browse problems."""
client.force_login(user=visitor)
response = client.get("/api/problem/")
assert response.status_code == status.HTTP_200_OK

def test_annotator_can_list_problems(self, client, annotator, sample_problem):
"""Annotators should be able to browse problems."""
client.force_login(user=annotator)
response = client.get("/api/problem/")
assert response.status_code == status.HTTP_200_OK

def test_master_annotator_can_list_problems(
self, client, master_annotator, sample_problem
):
"""Master annotators should be able to browse problems."""
client.force_login(user=master_annotator)
response = client.get("/api/problem/")
assert response.status_code == status.HTTP_200_OK

# Retrieve / browse single

def test_unauthenticated_user_can_retrieve_problem(self, client, sample_problem):
Expand Down
Loading