Skip to content

Commit

Permalink
only show current marking session assignments on ror homepage
Browse files Browse the repository at this point in the history
This also redirects the user to the correct session if the one they are
assigned to is not the default one.
  • Loading branch information
struan committed Nov 25, 2024
1 parent 859381c commit 6983b94
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
15 changes: 15 additions & 0 deletions crowdsourcer/tests/test_right_of_reply_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,27 @@ def setUp(self):
authority=auth2,
response_type=rt,
)
Assigned.objects.create(
marking_session=MarkingSession.objects.get(label="Second Session"),
user=u,
authority=auth2,
response_type=rt,
)

def test_homepage_redirect(self):
response = self.client.get("/")
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, "/authority_ror_authorities/")

def test_homepage_redirect_with_marking_session(self):
self.user.marker.marking_session.clear()
self.user.marker.marking_session.add(
MarkingSession.objects.get(label="Second Session")
)
response = self.client.get("/")
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, "/Second%20Session/authority_ror_authorities/")

def test_council_homepage(self):
url = reverse("authority_ror_authorities")
response = self.client.get(url)
Expand Down
31 changes: 25 additions & 6 deletions crowdsourcer/views/marking.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,35 @@ def dispatch(self, request, *args, **kwargs):
# assignments screen
if count == 1:
assignment = Assigned.objects.filter(
user=user, marking_session=self.request.current_session
user=user, marking_session=session
).first()
url = reverse(
"authority_ror_sections",
kwargs={"name": assignment.authority.name},
)
if self.request.current_session != session:
url = reverse(
"session_urls:authority_ror_sections",
kwargs={
"name": assignment.authority.name,
"marking_session": session,
},
)
else:
url = reverse(
"authority_ror_sections",
kwargs={
"name": assignment.authority.name,
},
)
# if they have nothing assigned then it's fine to show then the blank
# no assignments screen so handle everything else
else:
url = reverse("authority_ror_authorities")
if self.request.current_session != session:
url = reverse(
"session_urls:authority_ror_authorities",
kwargs={
"marking_session": session,
},
)
else:
url = reverse("authority_ror_authorities")

if url is not None:
return redirect(url)
Expand Down
12 changes: 8 additions & 4 deletions crowdsourcer/views/rightofreply.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ def get_queryset(self):
if user.is_anonymous:
return None

qs = Assigned.objects.filter(user=user, authority__isnull=False).order_by(
"authority__name"
)
qs = Assigned.objects.filter(
user=user,
marking_session=self.request.current_session,
authority__isnull=False,
).order_by("authority__name")

return qs

Expand All @@ -76,7 +78,9 @@ def get_queryset(self):
if (
marker.authority != authority
and not Assigned.objects.filter(
user=user, authority=authority, section__isnull=True
user=user,
authority=authority,
marking_session=self.request.current_session,
).exists()
):
raise PermissionDenied
Expand Down

0 comments on commit 6983b94

Please sign in to comment.