diff --git a/itou/www/apply/views/batch_views.py b/itou/www/apply/views/batch_views.py index 557f6284d43..612939179ed 100644 --- a/itou/www/apply/views/batch_views.py +++ b/itou/www/apply/views/batch_views.py @@ -180,7 +180,12 @@ class RefuseViewStep(enum.StrEnum): do_not_call_in_templates = enum.nonmember(True) -def _start_refuse_wizard(request, *, application_ids, next_url): +class RefuseTunnel(enum.StrEnum): + SINGLE = "single" + BATCH = "batch" + + +def _start_refuse_wizard(request, *, application_ids, next_url, from_detail_view=False): if next_url is None: # This is somewhat extreme but will force developpers to always provide a proper next_url raise Http404 @@ -204,7 +209,11 @@ def _start_refuse_wizard(request, *, application_ids, next_url): refuse_session = SessionNamespace.create_uuid_namespace( request.session, data={ - "config": {"session_kind": BATCH_REFUSE_SESSION_KIND, "reset_url": next_url}, + "config": { + "session_kind": BATCH_REFUSE_SESSION_KIND, + "reset_url": next_url, + "tunnel": RefuseTunnel.SINGLE if from_detail_view else RefuseTunnel.BATCH, + }, "application_ids": application_ids, }, ) @@ -246,6 +255,7 @@ def load_session(self, session_uuid): raise Http404 self.wizard_session = wizard_session self.reset_url = wizard_session.get("config", {}).get("reset_url") + self.tunnel = wizard_session.get("config", {}).get("tunnel", RefuseTunnel.BATCH) if self.reset_url is None: # Session should have been initialized with a reset_url and this RefuseWizardView expects one raise Http404 @@ -351,11 +361,17 @@ def get_context_data(self, **kwargs): the_prescriber = "les prescripteurs/orienteurs" Steps = namedtuple("Steps", ["current", "step1", "count", "next", "prev"]) + if self.tunnel == RefuseTunnel.BATCH: + matomo_custom_title = "Candidatures refusées" + matomo_event_name = f"batch-refuse-applications-{self.step}-submit" + else: + matomo_custom_title = "Candidature refusée" + matomo_event_name = f"batch-refuse-application-{self.step}-submit" context = super().get_context_data(**kwargs) | { "job_applications": self.applications, "can_view_personal_information": True, # SIAE members have access to personal info - "matomo_custom_title": "Candidatures refusées", - "matomo_event_name": f"batch-refuse-applications-{self.step}-submit", + "matomo_custom_title": matomo_custom_title, + "matomo_event_name": matomo_event_name, # Compatibility with current process_refuse.html "wizard": { "steps": Steps( @@ -460,10 +476,11 @@ def done(self): extra_tags="toast", ) logger.info( - "user=%s batch refused %s applications: %s", + f"user=%s {self.tunnel} refused %s applications: %s", self.request.user.pk, refused_nb, ",".join(str(app_uid) for app_uid in refused_ids), + self.tunnel, ) self.wizard_session.delete() diff --git a/itou/www/apply/views/process_views.py b/itou/www/apply/views/process_views.py index eab678deff7..f63b87b8428 100644 --- a/itou/www/apply/views/process_views.py +++ b/itou/www/apply/views/process_views.py @@ -386,6 +386,7 @@ def start_refuse_wizard(request, job_application_id): request, application_ids=[job_application_id], next_url=reverse("apply:details_for_company", kwargs={"job_application_id": job_application_id}), + from_detail_view=True, ) diff --git a/tests/www/apply/test_batch_views.py b/tests/www/apply/test_batch_views.py index 4aaf7f4669d..45bbd0ba34b 100644 --- a/tests/www/apply/test_batch_views.py +++ b/tests/www/apply/test_batch_views.py @@ -661,6 +661,7 @@ def test_single_app_from_orienter(self, client): expected_session = { "config": { "session_kind": "job-applications-batch-refuse", + "tunnel": "batch", "reset_url": next_url, }, "application_ids": [refusable_app.pk], @@ -675,6 +676,8 @@ def test_single_app_from_orienter(self, client): # Reason step response = client.get(refusal_reason_url) assertContains(response, "Étape 1/3 : Choix du motif de refus", html=True) + assert response.context["matomo_custom_title"] == "Candidatures refusées" + assert response.context["matomo_event_name"] == "batch-refuse-applications-reason-submit" post_data = { "refusal_reason": reason, @@ -692,6 +695,8 @@ def test_single_app_from_orienter(self, client): assertContains(response, "Étape 2/3 : Message au candidat", html=True) assertContains(response, "Réponse au candidat") assertContains(response, f"Motif de refus : {reason_label}", html=True) + assert response.context["matomo_custom_title"] == "Candidatures refusées" + assert response.context["matomo_event_name"] == "batch-refuse-applications-job-seeker-answer-submit" post_data = {"job_seeker_answer": self.FAKE_JOB_SEEKER_ANSWER} response = client.post(job_seeker_answer_url, data=post_data, follow=True) expected_session["job-seeker-answer"] = post_data @@ -705,6 +710,8 @@ def test_single_app_from_orienter(self, client): assertContains(response, "Étape 3/3 : Message à l’orienteur", html=True) assertContains(response, "Réponse à l’orienteur") assertContains(response, f"Motif de refus : {reason_label}", html=True) + assert response.context["matomo_custom_title"] == "Candidatures refusées" + assert response.context["matomo_event_name"] == "batch-refuse-applications-prescriber-answer-submit" post_data = {"prescriber_answer": self.FAKE_PRESCRIBER_ANSWER} response = client.post(prescriber_answer_url, data=post_data, follow=True) assertRedirects(response, next_url) @@ -753,6 +760,7 @@ def test_multiple_apps_from_authorized_prescribers(self, client): expected_session = { "config": { "session_kind": "job-applications-batch-refuse", + "tunnel": "batch", "reset_url": next_url, }, "application_ids": [refusable_apps[1].pk, refusable_apps[0].pk], # default application ordering @@ -767,6 +775,8 @@ def test_multiple_apps_from_authorized_prescribers(self, client): # Reason step response = client.get(refusal_reason_url) assertContains(response, "Étape 1/3 : Choix du motif de refus", html=True) + assert response.context["matomo_custom_title"] == "Candidatures refusées" + assert response.context["matomo_event_name"] == "batch-refuse-applications-reason-submit" post_data = { "refusal_reason": reason, @@ -784,6 +794,8 @@ def test_multiple_apps_from_authorized_prescribers(self, client): assertContains(response, "Étape 2/3 : Message aux candidats", html=True) assertContains(response, "Réponse aux candidats") assertContains(response, f"Motif de refus : {reason_label}", html=True) + assert response.context["matomo_custom_title"] == "Candidatures refusées" + assert response.context["matomo_event_name"] == "batch-refuse-applications-job-seeker-answer-submit" post_data = {"job_seeker_answer": self.FAKE_JOB_SEEKER_ANSWER} response = client.post(job_seeker_answer_url, data=post_data, follow=True) expected_session["job-seeker-answer"] = post_data @@ -797,6 +809,8 @@ def test_multiple_apps_from_authorized_prescribers(self, client): assertContains(response, "Étape 3/3 : Message aux prescripteurs", html=True) assertContains(response, "Réponse aux prescripteurs") assertContains(response, f"Motif de refus : {reason_label}", html=True) + assert response.context["matomo_custom_title"] == "Candidatures refusées" + assert response.context["matomo_event_name"] == "batch-refuse-applications-prescriber-answer-submit" post_data = {"prescriber_answer": self.FAKE_PRESCRIBER_ANSWER} response = client.post(prescriber_answer_url, data=post_data, follow=True) assertRedirects(response, next_url) @@ -839,6 +853,7 @@ def test_multiple_apps_from_same_job_seeker(self, client): expected_session = { "config": { "session_kind": "job-applications-batch-refuse", + "tunnel": "batch", "reset_url": next_url, }, "application_ids": [refusable_apps[1].pk, refusable_apps[0].pk], # default application ordering @@ -853,6 +868,8 @@ def test_multiple_apps_from_same_job_seeker(self, client): # Reason step response = client.get(refusal_reason_url) assertContains(response, "Étape 1/2 : Choix du motif de refus", html=True) + assert response.context["matomo_custom_title"] == "Candidatures refusées" + assert response.context["matomo_event_name"] == "batch-refuse-applications-reason-submit" post_data = { "refusal_reason": reason, @@ -874,6 +891,8 @@ def test_multiple_apps_from_same_job_seeker(self, client): f"Motif de refus : {reason_label} (Motif non communiqué au candidat)", html=True, ) + assert response.context["matomo_custom_title"] == "Candidatures refusées" + assert response.context["matomo_event_name"] == "batch-refuse-applications-job-seeker-answer-submit" post_data = {"job_seeker_answer": self.FAKE_JOB_SEEKER_ANSWER} response = client.post(job_seeker_answer_url, data=post_data, follow=True) assertRedirects(response, next_url) @@ -916,6 +935,7 @@ def test_refuse_step_bypass(self, client, rhone): expected_session = { "config": { "session_kind": "job-applications-batch-refuse", + "tunnel": "batch", "reset_url": next_url, }, "application_ids": [refusable_app.pk], @@ -974,6 +994,7 @@ def test_single_app_transfered_concurrently(self, client): expected_session = { "config": { "session_kind": "job-applications-batch-refuse", + "tunnel": "batch", "reset_url": next_url, }, "application_ids": [refusable_app.pk], @@ -1041,6 +1062,7 @@ def test_multiple_apps_deleted_concurrently(self, client): expected_session = { "config": { "session_kind": "job-applications-batch-refuse", + "tunnel": "batch", "reset_url": next_url, }, "application_ids": [refusable_apps[1].pk, refusable_apps[0].pk], # default application ordering diff --git a/tests/www/apply/test_process.py b/tests/www/apply/test_process.py index 95b61a0fb7b..c18b1e9148c 100644 --- a/tests/www/apply/test_process.py +++ b/tests/www/apply/test_process.py @@ -912,6 +912,7 @@ def test_refuse_session_prefix(self, client): assert client.session[refuse_session_name] == { "config": { "session_kind": "job-applications-batch-refuse", + "tunnel": "single", "reset_url": reverse("apply:details_for_company", kwargs={"job_application_id": job_application.pk}), }, "application_ids": [job_application.pk], @@ -928,6 +929,7 @@ def test_refuse_session_prefix(self, client): expected_session = { "config": { "session_kind": "job-applications-batch-refuse", + "tunnel": "single", "reset_url": reverse("apply:details_for_company", kwargs={"job_application_id": job_application.pk}), }, "application_ids": [job_application.pk], @@ -956,6 +958,7 @@ def test_refuse_session_prefix(self, client): assert client.session[refuse_session_name_2] == { "config": { "session_kind": "job-applications-batch-refuse", + "tunnel": "single", "reset_url": reverse("apply:details_for_company", kwargs={"job_application_id": job_application_2.pk}), }, "application_ids": [job_application_2.pk], @@ -984,6 +987,8 @@ def test_refuse_from_prescriber(self, client): ) assertRedirects(response, refusal_reason_url) assertContains(response, "Étape 1/3 : Choix du motif de refus", html=True) + assert response.context["matomo_custom_title"] == "Candidature refusée" + assert response.context["matomo_event_name"] == "batch-refuse-application-reason-submit" post_data = { "refusal_reason": reason, @@ -997,6 +1002,8 @@ def test_refuse_from_prescriber(self, client): assertContains(response, "Étape 2/3 : Message au candidat", html=True) assertContains(response, "Réponse au candidat") assertContains(response, f"Motif de refus : {reason_label}", html=True) + assert response.context["matomo_custom_title"] == "Candidature refusée" + assert response.context["matomo_event_name"] == "batch-refuse-application-job-seeker-answer-submit" post_data = { "job_seeker_answer": "Message au candidat", @@ -1009,6 +1016,8 @@ def test_refuse_from_prescriber(self, client): assertContains(response, "Étape 3/3 : Message au prescripteur", html=True) assertContains(response, "Réponse au prescripteur") assertContains(response, f"Motif de refus : {reason_label}", html=True) + assert response.context["matomo_custom_title"] == "Candidature refusée" + assert response.context["matomo_event_name"] == "batch-refuse-application-prescriber-answer-submit" post_data = { "prescriber_answer": "Message au prescripteur", @@ -1040,6 +1049,8 @@ def test_refuse_from_job_seeker(self, client): ) assertRedirects(response, refusal_reason_url) assertContains(response, "Étape 1/2 : Choix du motif de refus", html=True) + assert response.context["matomo_custom_title"] == "Candidature refusée" + assert response.context["matomo_event_name"] == "batch-refuse-application-reason-submit" post_data = { "refusal_reason": reason, @@ -1057,6 +1068,8 @@ def test_refuse_from_job_seeker(self, client): f"Motif de refus : {reason_label} (Motif non communiqué au candidat)", html=True, ) + assert response.context["matomo_custom_title"] == "Candidature refusée" + assert response.context["matomo_event_name"] == "batch-refuse-application-job-seeker-answer-submit" post_data = { "job_seeker_answer": "Message au candidat", @@ -3239,6 +3252,7 @@ def test_refuse_jobapplication_geiq_reasons(client, reason): assert client.session[refuse_session_name] == { "config": { "session_kind": "job-applications-batch-refuse", + "tunnel": "single", "reset_url": reverse("apply:details_for_company", kwargs={"job_application_id": job_application.pk}), }, "application_ids": [job_application.pk],