Skip to content

Commit

Permalink
www.apply: add RefuseTunnel to keep current matomo titles/events
Browse files Browse the repository at this point in the history
and be able to keep current values for both cases
  • Loading branch information
xavfernandez committed Feb 3, 2025
1 parent 823b2ad commit 0cb2a0d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
27 changes: 22 additions & 5 deletions itou/www/apply/views/batch_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
},
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()

Expand Down
1 change: 1 addition & 0 deletions itou/www/apply/views/process_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down
22 changes: 22 additions & 0 deletions tests/www/apply/test_batch_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -675,6 +676,8 @@ def test_single_app_from_orienter(self, client):
# Reason step
response = client.get(refusal_reason_url)
assertContains(response, "<strong>Étape 1</strong>/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,
Expand All @@ -692,6 +695,8 @@ def test_single_app_from_orienter(self, client):
assertContains(response, "<strong>Étape 2</strong>/3 : Message au candidat", html=True)
assertContains(response, "Réponse au candidat")
assertContains(response, f"<strong>Motif de refus :</strong> {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
Expand All @@ -705,6 +710,8 @@ def test_single_app_from_orienter(self, client):
assertContains(response, "<strong>Étape 3</strong>/3 : Message à l’orienteur", html=True)
assertContains(response, "Réponse à l’orienteur")
assertContains(response, f"<strong>Motif de refus :</strong> {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)
Expand Down Expand Up @@ -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
Expand All @@ -767,6 +775,8 @@ def test_multiple_apps_from_authorized_prescribers(self, client):
# Reason step
response = client.get(refusal_reason_url)
assertContains(response, "<strong>Étape 1</strong>/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,
Expand All @@ -784,6 +794,8 @@ def test_multiple_apps_from_authorized_prescribers(self, client):
assertContains(response, "<strong>Étape 2</strong>/3 : Message aux candidats", html=True)
assertContains(response, "Réponse aux candidats")
assertContains(response, f"<strong>Motif de refus :</strong> {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
Expand All @@ -797,6 +809,8 @@ def test_multiple_apps_from_authorized_prescribers(self, client):
assertContains(response, "<strong>Étape 3</strong>/3 : Message aux prescripteurs", html=True)
assertContains(response, "Réponse aux prescripteurs")
assertContains(response, f"<strong>Motif de refus :</strong> {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)
Expand Down Expand Up @@ -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
Expand All @@ -853,6 +868,8 @@ def test_multiple_apps_from_same_job_seeker(self, client):
# Reason step
response = client.get(refusal_reason_url)
assertContains(response, "<strong>Étape 1</strong>/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,
Expand All @@ -874,6 +891,8 @@ def test_multiple_apps_from_same_job_seeker(self, client):
f"<strong>Motif de refus :</strong> {reason_label} <em>(Motif non communiqué au candidat)</em>",
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)
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions tests/www/apply/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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],
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -984,6 +987,8 @@ def test_refuse_from_prescriber(self, client):
)
assertRedirects(response, refusal_reason_url)
assertContains(response, "<strong>Étape 1</strong>/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,
Expand All @@ -997,6 +1002,8 @@ def test_refuse_from_prescriber(self, client):
assertContains(response, "<strong>Étape 2</strong>/3 : Message au candidat", html=True)
assertContains(response, "Réponse au candidat")
assertContains(response, f"<strong>Motif de refus :</strong> {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",
Expand All @@ -1009,6 +1016,8 @@ def test_refuse_from_prescriber(self, client):
assertContains(response, "<strong>Étape 3</strong>/3 : Message au prescripteur", html=True)
assertContains(response, "Réponse au prescripteur")
assertContains(response, f"<strong>Motif de refus :</strong> {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",
Expand Down Expand Up @@ -1040,6 +1049,8 @@ def test_refuse_from_job_seeker(self, client):
)
assertRedirects(response, refusal_reason_url)
assertContains(response, "<strong>Étape 1</strong>/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,
Expand All @@ -1057,6 +1068,8 @@ def test_refuse_from_job_seeker(self, client):
f"<strong>Motif de refus :</strong> {reason_label} <em>(Motif non communiqué au candidat)</em>",
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",
Expand Down Expand Up @@ -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],
Expand Down

0 comments on commit 0cb2a0d

Please sign in to comment.