Skip to content

Commit

Permalink
control user stage with marker and not current stage
Browse files Browse the repository at this point in the history
Allow users to be on different stages based on the stage value in marker
and not controlled by the value in the current stage table. Means you
can have users doing first mark and audit at the same time.
  • Loading branch information
struan committed Oct 30, 2023
1 parent f29371e commit a493f56
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
43 changes: 42 additions & 1 deletion crowdsourcer/tests/test_audit_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.test import TestCase
from django.urls import reverse

from crowdsourcer.models import Assigned, Question, Response, ResponseType
from crowdsourcer.models import Assigned, Marker, Question, Response, ResponseType


class BaseTestCase(TestCase):
Expand Down Expand Up @@ -62,6 +62,47 @@ def test_basics(self):
self.assertEqual(second["total"], 1)
self.assertEqual(second["complete"], 0)

def test_first_mark_assigned_user(self):
rt = ResponseType.objects.get(type="First Mark")
u = User.objects.get(username="marker")
m, _ = Marker.objects.get_or_create(user=u)
m.response_type = rt
m.save()

self.client.force_login(u)
self.user = u

response = self.client.get("/")
self.assertEqual(response.status_code, 200)

context = response.context
assignments = context["progress"]

self.assertEqual(len(assignments), 2)
first = assignments[0]

self.assertEqual(context["section_link"], "section_authorities")
self.assertEqual(first["assignment"].section.title, "Planning & Land Use")

url = reverse(
"authority_question_edit", args=("Aberdeenshire Council", "Transport")
)
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
url = reverse("authority_audit", args=("Aberdeenshire Council", "Transport"))
response = self.client.get(url)
self.assertEqual(response.status_code, 403)

rt = ResponseType.objects.get(type="Audit")
m.response_type = rt
m.save()

response = self.client.get("/")
self.assertEqual(response.status_code, 200)

context = response.context
self.assertEqual(context["section_link"], "audit_section_authorities")


class TestSaveView(BaseTestCase):
fixtures = [
Expand Down
12 changes: 9 additions & 3 deletions crowdsourcer/views/marking.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def get_context_data(self, **kwargs):
context["show_login"] = True
return context

context["show_users"] = self.request.user.is_superuser
user = self.request.user
context["show_users"] = user.is_superuser

assignments = (
context["assignments"]
Expand Down Expand Up @@ -130,9 +131,14 @@ def get_context_data(self, **kwargs):

context["progress"] = progress

if self.current_stage.type == "First Mark":
user_stage = self.current_stage.type
if hasattr(user, "marker"):
if user.marker.response_type:
user_stage = user.marker.response_type.type

if user_stage == "First Mark":
section_link = "section_authorities"
elif self.current_stage.type == "Audit":
elif user_stage == "Audit":
section_link = "audit_section_authorities"

context["page_title"] = "Assignments"
Expand Down

0 comments on commit a493f56

Please sign in to comment.