From 6983b94b175d48ba21ed0d1605f5e7071c07521a Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 25 Nov 2024 12:24:41 +0000 Subject: [PATCH] only show current marking session assignments on ror homepage This also redirects the user to the correct session if the one they are assigned to is not the default one. --- .../tests/test_right_of_reply_views.py | 15 +++++++++ crowdsourcer/views/marking.py | 31 +++++++++++++++---- crowdsourcer/views/rightofreply.py | 12 ++++--- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/crowdsourcer/tests/test_right_of_reply_views.py b/crowdsourcer/tests/test_right_of_reply_views.py index 5567492..95550db 100644 --- a/crowdsourcer/tests/test_right_of_reply_views.py +++ b/crowdsourcer/tests/test_right_of_reply_views.py @@ -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) diff --git a/crowdsourcer/views/marking.py b/crowdsourcer/views/marking.py index 510b74d..ecec286 100644 --- a/crowdsourcer/views/marking.py +++ b/crowdsourcer/views/marking.py @@ -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) diff --git a/crowdsourcer/views/rightofreply.py b/crowdsourcer/views/rightofreply.py index 7d4ebd5..331ee91 100644 --- a/crowdsourcer/views/rightofreply.py +++ b/crowdsourcer/views/rightofreply.py @@ -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 @@ -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