From 6d58ffae9845ded6c31a665f26df69a4139be4f4 Mon Sep 17 00:00:00 2001 From: Ewen Corre Date: Tue, 15 Oct 2024 15:10:49 +0200 Subject: [PATCH] apply: `reset_url` to company or job description card --- .../apply/submit/application/resume.html | 2 +- .../submit_step_check_job_seeker_nir.html | 2 +- .../apply/submit_step_job_seeker.html | 2 +- .../submit_step_job_seeker_check_info.html | 2 +- itou/www/apply/views/submit_views.py | 25 +++-- tests/www/apply/test_submit.py | 101 +++++++++++++++++- 6 files changed, 122 insertions(+), 12 deletions(-) diff --git a/itou/templates/apply/submit/application/resume.html b/itou/templates/apply/submit/application/resume.html index a58a5c2764..7266c11562 100644 --- a/itou/templates/apply/submit/application/resume.html +++ b/itou/templates/apply/submit/application/resume.html @@ -238,6 +238,6 @@ {% if auto_prescription_process %} {% itou_buttons_form primary_label="Enregistrer" secondary_url=back_url matomo_category="candidature" matomo_action="submit" matomo_name="candidature_employer" %} {% else %} - {% itou_buttons_form primary_label="Envoyer la candidature" secondary_url=back_url matomo_category="candidature" matomo_action="submit" matomo_name="candidature_"|add:request.user.get_kind_display %} + {% itou_buttons_form primary_label="Envoyer la candidature" secondary_url=back_url reset_url=reset_url matomo_category="candidature" matomo_action="submit" matomo_name="candidature_"|add:request.user.get_kind_display %} {% endif %} {% endblock %} diff --git a/itou/templates/apply/submit_step_check_job_seeker_nir.html b/itou/templates/apply/submit_step_check_job_seeker_nir.html index 35347475fa..e8921f3293 100644 --- a/itou/templates/apply/submit_step_check_job_seeker_nir.html +++ b/itou/templates/apply/submit_step_check_job_seeker_nir.html @@ -76,7 +76,7 @@ {% endif %} {# Reload this page and show a modal containing more information about the job seeker. #} - {% itou_buttons_form primary_label="Suivant" primary_name="preview" primary_value="1" %} + {% itou_buttons_form primary_label="Suivant" primary_name="preview" primary_value="1" reset_url=reset_url %} {% if preview_mode %} diff --git a/itou/templates/apply/submit_step_job_seeker.html b/itou/templates/apply/submit_step_job_seeker.html index 7b7f9b3e77..6d11da5471 100644 --- a/itou/templates/apply/submit_step_job_seeker.html +++ b/itou/templates/apply/submit_step_job_seeker.html @@ -39,7 +39,7 @@ {% include "signup/includes/no_email_link.html" with link_text="Le candidat n'a pas d'e-mail ?" only %} - {% itou_buttons_form primary_label="Suivant" secondary_url=back_url primary_name="preview" primary_value="1" %} + {% itou_buttons_form primary_label="Suivant" secondary_url=back_url primary_name="preview" primary_value="1" reset_url=reset_url %} {% if preview_mode %} diff --git a/itou/templates/apply/submit_step_job_seeker_check_info.html b/itou/templates/apply/submit_step_job_seeker_check_info.html index e55a3af535..b0895afd8a 100644 --- a/itou/templates/apply/submit_step_job_seeker_check_info.html +++ b/itou/templates/apply/submit_step_job_seeker_check_info.html @@ -12,7 +12,7 @@ {% bootstrap_form form alert_error_type="all" %} - {% itou_buttons_form primary_label="Continuer" %} + {% itou_buttons_form primary_label="Continuer" reset_url=reset_url %} {% endblock %} diff --git a/itou/www/apply/views/submit_views.py b/itou/www/apply/views/submit_views.py index aa41b0ffe2..5504d59e22 100644 --- a/itou/www/apply/views/submit_views.py +++ b/itou/www/apply/views/submit_views.py @@ -134,6 +134,22 @@ def dispatch(self, request, *args, **kwargs): def get_back_url(self): return None + def get_reset_url(self): + if self.hire_process or self.auto_prescription_process: + # The employer can come either be creating an application or hiring somebody. + # In both cases, the reset_url adds no value compared to going back to the dashboard. + return reverse("dashboard:index") + + try: + selected_jobs = self.apply_session.get("selected_jobs", []) + [job_description] = selected_jobs + except ( + KeyError, # No apply_session + ValueError, # No job description, or multiple job descriptions. + ): + return reverse("companies_views:card", kwargs={"siae_id": self.company.pk}) + return reverse("companies_views:job_description_card", kwargs={"job_description_id": job_description}) + def get_context_data(self, **kwargs): return super().get_context_data(**kwargs) | { "siae": self.company, @@ -141,7 +157,7 @@ def get_context_data(self, **kwargs): "hire_process": self.hire_process, "prescription_process": self.prescription_process, "auto_prescription_process": self.auto_prescription_process, - "reset_url": reverse("dashboard:index"), + "reset_url": self.get_reset_url(), "is_gps": self.is_gps, "page_title": "Postuler", } @@ -953,12 +969,7 @@ def get_back_url(self): # The employer can come either be creating an application or hiring somebody. # In both cases, the back_url adds no value compared to going back to the dashboard. return None - selected_jobs = self.apply_session.get("selected_jobs", []) - try: - [job_description] = selected_jobs - except ValueError: # No job description, or multiple job descriptions. - return reverse("companies_views:card", kwargs={"siae_id": self.company.pk}) - return reverse("companies_views:job_description_card", kwargs={"job_description_id": job_description}) + return self.get_reset_url() class RequireApplySessionMixin: diff --git a/tests/www/apply/test_submit.py b/tests/www/apply/test_submit.py index 2dd2bc9efd..5f1efcdb35 100644 --- a/tests/www/apply/test_submit.py +++ b/tests/www/apply/test_submit.py @@ -65,6 +65,11 @@ BACK_BUTTON_ARIA_LABEL = "Retourner à l’étape précédente" +CONFIRM_RESET_MARKUP = 'Confirmer l\'annulation' +LINK_RESET_MARKUP = ( + '' +) class TestApply: @@ -351,6 +356,7 @@ def test_apply_as_jobseeker(self, client, pdf_file): """Apply as jobseeker.""" company = CompanyWithMembershipAndJobsFactory(romes=("N1101", "N1105")) + reset_url_company = reverse("companies_views:card", kwargs={"siae_id": company.pk}) user = JobSeekerFactory(jobseeker_profile__birthdate=None, jobseeker_profile__nir="") client.force_login(user) @@ -369,6 +375,7 @@ def test_apply_as_jobseeker(self, client, pdf_file): response = client.get(next_url) assert response.status_code == 200 + assertContains(response, LINK_RESET_MARKUP % reset_url_company) nir = "178122978200508" post_data = {"nir": nir, "confirm": 1} @@ -390,6 +397,7 @@ def test_apply_as_jobseeker(self, client, pdf_file): response = client.get(next_url) assert response.status_code == 200 + assertContains(response, LINK_RESET_MARKUP % reset_url_company) post_data = {"birthdate": "20/12/1978", "phone": "0610203040", "pole_emploi_id": "1234567A"} @@ -423,7 +431,7 @@ def test_apply_as_jobseeker(self, client, pdf_file): # ---------------------------------------------------------------------- response = client.get(next_url) - # Check back_url is present + # Check back_url and reset_url are present company_card_url = reverse("companies_views:card", kwargs={"siae_id": company.pk}) assertContains( response, @@ -438,8 +446,12 @@ def test_apply_as_jobseeker(self, client, pdf_file): html=True, count=1, ) + assertContains(response, CONFIRM_RESET_MARKUP % reset_url_company) selected_job = company.job_description_through.first() + reset_url_job_description = reverse( + "companies_views:job_description_card", kwargs={"job_description_id": selected_job.pk} + ) response = client.post(next_url, data={"selected_jobs": [selected_job.pk]}) assert response.status_code == 302 @@ -464,6 +476,7 @@ def test_apply_as_jobseeker(self, client, pdf_file): # ---------------------------------------------------------------------- response = client.get(next_url) assertContains(response, "Envoyer la candidature") + assertContains(response, CONFIRM_RESET_MARKUP % reset_url_job_description) with mock.patch( "itou.www.apply.views.submit_views.uuid.uuid4", @@ -553,6 +566,10 @@ def test_apply_as_job_seeker_on_sender_tunnel(self, client): def test_apply_as_job_seeker_from_job_description(self, client): company = CompanyWithMembershipAndJobsFactory(romes=("N1101", "N1105")) job_description = company.job_description_through.first() + reset_url_job_description = reverse( + "companies_views:job_description_card", kwargs={"job_description_id": job_description.pk} + ) + job_seeker = JobSeekerFactory( jobseeker_profile__nir="141068078200557", with_pole_emploi_id=True, @@ -604,6 +621,7 @@ def test_apply_as_job_seeker_from_job_description(self, client): html=True, count=1, ) + assertContains(response, CONFIRM_RESET_MARKUP % reset_url_job_description) def test_apply_as_job_seeker_resume_not_pdf(self, client): company = CompanyWithMembershipAndJobsFactory(romes=("N1101")) @@ -1062,6 +1080,7 @@ def test_apply_as_prescriber_with_pending_authorization(self, client, pdf_file): def test_apply_as_authorized_prescriber(self, client, pdf_file): company = CompanyWithMembershipAndJobsFactory(romes=("N1101", "N1105")) + reset_url_company = reverse("companies_views:card", kwargs={"siae_id": company.pk}) # test ZRR / QPV template loading city = create_city_in_zrr() @@ -1091,6 +1110,7 @@ def test_apply_as_authorized_prescriber(self, client, pdf_file): response = client.get(next_url) assert response.status_code == 200 + assertContains(response, LINK_RESET_MARKUP % reset_url_company) response = client.post(next_url, data={"nir": dummy_job_seeker.jobseeker_profile.nir, "confirm": 1}) assert response.status_code == 302 @@ -1106,6 +1126,7 @@ def test_apply_as_authorized_prescriber(self, client, pdf_file): response = client.get(next_url) assert response.status_code == 200 + assertContains(response, CONFIRM_RESET_MARKUP % reset_url_company) response = client.post(next_url, data={"email": dummy_job_seeker.email, "confirm": "1"}) assert response.status_code == 302 @@ -1139,6 +1160,7 @@ def test_apply_as_authorized_prescriber(self, client, pdf_file): kwargs={"company_pk": company.pk, "session_uuid": job_seeker_session_name}, ), ) + assertContains(response, CONFIRM_RESET_MARKUP % reset_url_company) geispolsheim = create_city_geispolsheim() birthdate = dummy_job_seeker.jobseeker_profile.birthdate @@ -1172,6 +1194,7 @@ def test_apply_as_authorized_prescriber(self, client, pdf_file): response = client.get(next_url) assert response.status_code == 200 + assertContains(response, CONFIRM_RESET_MARKUP % reset_url_company) post_data = { "ban_api_resolved_address": dummy_job_seeker.geocoding_address, @@ -1196,6 +1219,7 @@ def test_apply_as_authorized_prescriber(self, client, pdf_file): response = client.get(next_url) assert response.status_code == 200 + assertContains(response, CONFIRM_RESET_MARKUP % reset_url_company) post_data = { "education_level": dummy_job_seeker.jobseeker_profile.education_level, @@ -1262,8 +1286,12 @@ def test_apply_as_authorized_prescriber(self, client, pdf_file): html=True, count=1, ) + assertContains(response, CONFIRM_RESET_MARKUP % reset_url_company) selected_job = company.job_description_through.first() + reset_url_job_description = reverse( + "companies_views:job_description_card", kwargs={"job_description_id": selected_job.pk} + ) response = client.post(next_url, data={"selected_jobs": [selected_job.pk]}) assert response.status_code == 302 @@ -1286,6 +1314,7 @@ def test_apply_as_authorized_prescriber(self, client, pdf_file): ): response = client.get(next_url) assert response.status_code == 200 + assertContains(response, CONFIRM_RESET_MARKUP % reset_url_job_description) assert not EligibilityDiagnosis.objects.has_considered_valid(new_job_seeker, for_siae=company) assertTemplateUsed(response, "apply/includes/known_criteria.html", count=1) @@ -1303,6 +1332,7 @@ def test_apply_as_authorized_prescriber(self, client, pdf_file): # ---------------------------------------------------------------------- response = client.get(next_url) assertContains(response, "Postuler") + assertContains(response, CONFIRM_RESET_MARKUP % reset_url_job_description) with mock.patch( "itou.www.apply.views.submit_views.uuid.uuid4", @@ -1410,6 +1440,7 @@ def test_apply_as_prescriber_with_suspension_sanction(self, client): ) def test_apply_as_prescriber(self, client, pdf_file): company = CompanyWithMembershipAndJobsFactory(romes=("N1101", "N1105")) + reset_url_company = reverse("companies_views:card", kwargs={"siae_id": company.pk}) user = PrescriberFactory() client.force_login(user) @@ -1437,6 +1468,7 @@ def test_apply_as_prescriber(self, client, pdf_file): response = client.get(next_url) assert response.status_code == 200 + assertContains(response, LINK_RESET_MARKUP % reset_url_company) response = client.post(next_url, data={"nir": dummy_job_seeker.jobseeker_profile.nir, "confirm": 1}) assert response.status_code == 302 @@ -1454,6 +1486,7 @@ def test_apply_as_prescriber(self, client, pdf_file): response = client.get(next_url) assert response.status_code == 200 + assertContains(response, CONFIRM_RESET_MARKUP % reset_url_company) response = client.post(next_url, data={"email": dummy_job_seeker.email, "confirm": "1"}) assert response.status_code == 302 @@ -1489,6 +1522,7 @@ def test_apply_as_prescriber(self, client, pdf_file): kwargs={"company_pk": company.pk, "session_uuid": job_seeker_session_name}, ), ) + assertContains(response, CONFIRM_RESET_MARKUP % reset_url_company) geispolsheim = create_city_geispolsheim() birthdate = dummy_job_seeker.jobseeker_profile.birthdate @@ -1550,6 +1584,7 @@ def test_apply_as_prescriber(self, client, pdf_file): response = client.get(next_url) assert response.status_code == 200 + assertContains(response, CONFIRM_RESET_MARKUP % reset_url_company) post_data = { "ban_api_resolved_address": dummy_job_seeker.geocoding_address, @@ -1573,6 +1608,7 @@ def test_apply_as_prescriber(self, client, pdf_file): response = client.get(next_url) assert response.status_code == 200 + assertContains(response, CONFIRM_RESET_MARKUP % reset_url_company) post_data = { "education_level": dummy_job_seeker.jobseeker_profile.education_level, @@ -1645,8 +1681,12 @@ def test_apply_as_prescriber(self, client, pdf_file): response = client.get(next_url) assert response.status_code == 200 + assertContains(response, CONFIRM_RESET_MARKUP % reset_url_company) selected_job = company.job_description_through.first() + reset_url_job_description = reverse( + "companies_views:job_description_card", kwargs={"job_description_id": selected_job.pk} + ) response = client.post(next_url, data={"selected_jobs": [selected_job.pk]}) assert response.status_code == 302 @@ -1673,6 +1713,7 @@ def test_apply_as_prescriber(self, client, pdf_file): # ---------------------------------------------------------------------- response = client.get(next_url) assertContains(response, "Postuler") + assertContains(response, CONFIRM_RESET_MARKUP % reset_url_job_description) with mock.patch( "itou.www.apply.views.submit_views.uuid.uuid4", @@ -1956,6 +1997,9 @@ def test_apply_as_siae_with_suspension_sanction(self, client): ) def _test_apply_as_company(self, client, user, company, dummy_job_seeker, pdf_file): + reset_url_dashboard = reverse("dashboard:index") + reset_url_company = reverse("companies_views:card", kwargs={"siae_id": company.pk}) + # Entry point. # ---------------------------------------------------------------------- @@ -1970,6 +2014,11 @@ def _test_apply_as_company(self, client, user, company, dummy_job_seeker, pdf_fi response = client.get(next_url) assert response.status_code == 200 + # Autoprescription: send to dashboard, otherwise send to other company card + assertContains( + response, + LINK_RESET_MARKUP % reset_url_dashboard if company in user.company_set.all() else reset_url_company, + ) response = client.post(next_url, data={"nir": dummy_job_seeker.jobseeker_profile.nir, "confirm": 1}) assert response.status_code == 302 @@ -1987,6 +2036,11 @@ def _test_apply_as_company(self, client, user, company, dummy_job_seeker, pdf_fi response = client.get(next_url) assert response.status_code == 200 + # Autoprescription: send to dashboard, otherwise send to other company card + assertContains( + response, + CONFIRM_RESET_MARKUP % reset_url_dashboard if company in user.company_set.all() else reset_url_company, + ) response = client.post(next_url, data={"email": dummy_job_seeker.email, "confirm": "1"}) assert response.status_code == 302 @@ -2021,6 +2075,11 @@ def _test_apply_as_company(self, client, user, company, dummy_job_seeker, pdf_fi kwargs={"company_pk": company.pk, "session_uuid": job_seeker_session_name}, ), ) + # Autoprescription: send to dashboard, otherwise send to other company card + assertContains( + response, + CONFIRM_RESET_MARKUP % reset_url_dashboard if company in user.company_set.all() else reset_url_company, + ) geispolsheim = create_city_geispolsheim() birthdate = dummy_job_seeker.jobseeker_profile.birthdate @@ -2082,6 +2141,11 @@ def _test_apply_as_company(self, client, user, company, dummy_job_seeker, pdf_fi response = client.get(next_url) assert response.status_code == 200 + # Autoprescription: send to dashboard, otherwise send to other company card + assertContains( + response, + CONFIRM_RESET_MARKUP % reset_url_dashboard if company in user.company_set.all() else reset_url_company, + ) post_data = { "ban_api_resolved_address": dummy_job_seeker.geocoding_address, @@ -2106,6 +2170,11 @@ def _test_apply_as_company(self, client, user, company, dummy_job_seeker, pdf_fi response = client.get(next_url) assert response.status_code == 200 + # Autoprescription: send to dashboard, otherwise send to other company card + assertContains( + response, + CONFIRM_RESET_MARKUP % reset_url_dashboard if company in user.company_set.all() else reset_url_company, + ) post_data = { "education_level": dummy_job_seeker.jobseeker_profile.education_level, @@ -2159,6 +2228,11 @@ def _test_apply_as_company(self, client, user, company, dummy_job_seeker, pdf_fi response = client.get(next_url) assert response.status_code == 200 + # Autoprescription: send to dashboard, otherwise send to other company card + assertContains( + response, + LINK_RESET_MARKUP % reset_url_dashboard if company in user.company_set.all() else reset_url_company, + ) selected_job = company.job_description_through.first() response = client.post(next_url, data={"selected_jobs": [selected_job.pk]}) @@ -2187,6 +2261,11 @@ def _test_apply_as_company(self, client, user, company, dummy_job_seeker, pdf_fi # ---------------------------------------------------------------------- response = client.get(next_url) assertContains(response, "Enregistrer" if user in company.members.all() else "Postuler") + # Autoprescription: send to dashboard, otherwise send to other company card + assertContains( + response, + CONFIRM_RESET_MARKUP % reset_url_dashboard if company in user.company_set.all() else reset_url_company, + ) with mock.patch( "itou.www.apply.views.submit_views.uuid.uuid4", @@ -2383,6 +2462,7 @@ def test_hire_as_company(self, client): """Apply as company (and create new job seeker)""" company = CompanyWithMembershipAndJobsFactory(romes=("N1101", "N1105")) + reset_url_dashboard = reverse("dashboard:index") user = company.members.first() client.force_login(user) @@ -2404,6 +2484,7 @@ def test_hire_as_company(self, client): check_nir_url = reverse("apply:check_nir_for_hire", kwargs={"company_pk": company.pk}) response = client.get(check_nir_url) assert response.status_code == 200 + assertContains(response, LINK_RESET_MARKUP % reset_url_dashboard) response = client.post(check_nir_url, data={"nir": dummy_job_seeker.jobseeker_profile.nir, "preview": 1}) assert response.status_code == 302 @@ -2420,6 +2501,7 @@ def test_hire_as_company(self, client): response = client.get(next_url) assert response.status_code == 200 + assertContains(response, CONFIRM_RESET_MARKUP % reset_url_dashboard) response = client.post(next_url, data={"email": dummy_job_seeker.email, "confirm": "1"}) assert response.status_code == 302 @@ -2454,6 +2536,7 @@ def test_hire_as_company(self, client): kwargs={"company_pk": company.pk, "session_uuid": job_seeker_session_name}, ), ) + assertContains(response, CONFIRM_RESET_MARKUP % reset_url_dashboard) birthdate = dummy_job_seeker.jobseeker_profile.birthdate @@ -2514,6 +2597,7 @@ def test_hire_as_company(self, client): response = client.get(next_url) assert response.status_code == 200 + assertContains(response, CONFIRM_RESET_MARKUP % reset_url_dashboard) post_data = { "ban_api_resolved_address": dummy_job_seeker.geocoding_address, @@ -2539,6 +2623,7 @@ def test_hire_as_company(self, client): response = client.get(next_url) assert response.status_code == 200 + assertContains(response, CONFIRM_RESET_MARKUP % reset_url_dashboard) post_data = { "education_level": dummy_job_seeker.jobseeker_profile.education_level, @@ -2574,6 +2659,7 @@ def test_hire_as_company(self, client): response = client.get(next_url) assert response.status_code == 200 + assertContains(response, CONFIRM_RESET_MARKUP % reset_url_dashboard) response = client.post(next_url) assert response.status_code == 302 @@ -2629,6 +2715,11 @@ def test_hire_as_company(self, client): response = client.get(next_url) assertTemplateNotUsed(response, "approvals/includes/status.html") assertContains(response, "Valider l’embauche") + check_infos_url = reverse( + "apply:check_job_seeker_info_for_hire", + kwargs={"company_pk": company.pk, "job_seeker_public_id": new_job_seeker.public_id}, + ) + assertContains(response, LINK_RESET_MARKUP % check_infos_url) hiring_start_at = timezone.localdate() post_data = { @@ -2684,6 +2775,7 @@ def test_hire_as_company(self, client): def test_hire_as_geiq(self, client): """Apply as GEIQ with pre-existing job seeker without previous application""" company = CompanyWithMembershipAndJobsFactory(romes=("N1101", "N1105"), kind=CompanyKind.GEIQ) + reset_url_dashboard = reverse("dashboard:index") job_seeker = JobSeekerFactory() user = company.members.first() @@ -2695,6 +2787,7 @@ def test_hire_as_geiq(self, client): check_nir_url = reverse("apply:check_nir_for_hire", kwargs={"company_pk": company.pk}) response = client.get(check_nir_url) assert response.status_code == 200 + assertContains(response, LINK_RESET_MARKUP % reset_url_dashboard) response = client.post(check_nir_url, data={"nir": job_seeker.jobseeker_profile.nir, "confirm": 1}) check_infos_url = reverse( @@ -2715,6 +2808,7 @@ def test_hire_as_geiq(self, client): ) assertContains(response, prev_applicaitons_url) assertContains(response, "Éligibilité GEIQ non confirmée") + assertContains(response, CONFIRM_RESET_MARKUP % reset_url_dashboard) # Step check previous applications # ---------------------------------------------------------------------- @@ -2767,6 +2861,11 @@ def test_hire_as_geiq(self, client): response = client.get(confirmation_url) assertTemplateNotUsed(response, "approvals/includes/status.html") assertContains(response, "Valider l’embauche") + check_infos_url = reverse( + "apply:check_job_seeker_info_for_hire", + kwargs={"company_pk": company.pk, "job_seeker_public_id": job_seeker.public_id}, + ) + assertContains(response, LINK_RESET_MARKUP % check_infos_url) hiring_start_at = timezone.localdate() post_data = {