Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

[bug] Não permitir que usuário acessem tasks para contests não iniciados ou cancelados #99

Merged
merged 15 commits into from
Nov 27, 2023
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
11 changes: 11 additions & 0 deletions apps/tasks/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,14 @@ def test_send_submission_is_redirecting(self) -> None:
def test_send_submission_without_authentication(self) -> None:
response = self.client.post(self.url, data={"code": self.code})
self.assertEqual(response.status_code, 302)

def test_access_task_that_is_accessible(self) -> None:
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)

def test_access_task_that_is_not_accessible(self) -> None:
self.task.contest.cancelled = True
self.task.contest.save()

response = self.client.get(self.url)
self.assertEqual(response.status_code, 302)
11 changes: 11 additions & 0 deletions apps/tasks/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
def get_success_url(self) -> str:
return reverse("tasks:detail", args=[self.object.id])

def get(
self, request: HttpRequest, *args: Any, **kwargs: Any
) -> HttpResponse:
self.object = self.get_object()

if not self.object.is_accessible:
return redirect("home")

context = self.get_context_data(object=self.object)
return self.render_to_response(context)

def post(self, request: HttpRequest, *, pk: int) -> HttpResponse:
# Unauthenticated users should not be able to submit
# a submission to a task, so we redirect them to the
Expand Down