From 2b804fcbf80f72abdd6b3d3d34512c5eb2e8b6d1 Mon Sep 17 00:00:00 2001 From: Antoine LAURENT Date: Sat, 11 Jan 2025 21:15:54 +0100 Subject: [PATCH] job_applications: Fix notification structure The sender may be an employer --- itou/job_applications/models.py | 16 ++++++++-------- itou/job_applications/notifications.py | 12 ++++++------ itou/www/apply/views/submit_views.py | 2 +- tests/job_applications/tests.py | 16 ++++++++++++++++ 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/itou/job_applications/models.py b/itou/job_applications/models.py index f2de72e25a..9e8650a79e 100644 --- a/itou/job_applications/models.py +++ b/itou/job_applications/models.py @@ -1085,9 +1085,9 @@ def notifications_new_for_employer(self, employer): @property def notifications_new_for_proxy(self): - return job_application_notifications.JobApplicationNewForPrescriberNotification( + return job_application_notifications.JobApplicationNewForProxyNotification( self.sender, - self.sender_prescriber_organization, + self.sender_prescriber_organization or self.sender_company, job_application=self, ) @@ -1108,9 +1108,9 @@ def notifications_accept_for_job_seeker(self): @property def notifications_accept_for_proxy(self): - return job_application_notifications.JobApplicationAcceptedForPrescriberNotification( + return job_application_notifications.JobApplicationAcceptedForProxyNotification( self.sender, - self.sender_prescriber_organization, + self.sender_prescriber_organization or self.sender_company, job_application=self, ) @@ -1118,7 +1118,7 @@ def notifications_accept_for_proxy(self): def notifications_postpone_for_proxy(self): return job_application_notifications.JobApplicationPostponedForProxyNotification( self.sender, - self.sender_prescriber_organization, + self.sender_prescriber_organization or self.sender_company, job_application=self, ) @@ -1131,9 +1131,9 @@ def notifications_postpone_for_job_seeker(self): @property def notifications_refuse_for_proxy(self): - return job_application_notifications.JobApplicationRefusedForPrescriberNotification( + return job_application_notifications.JobApplicationRefusedForProxyNotification( self.sender, - self.sender_prescriber_organization, + self.sender_prescriber_organization or self.sender_company, job_application=self, ) @@ -1155,7 +1155,7 @@ def notifications_cancel_for_employer(self, canceled_by): def notifications_cancel_for_proxy(self): return job_application_notifications.JobApplicationCanceledNotification( self.sender, - self.sender_prescriber_organization, + self.sender_prescriber_organization or self.sender_company, job_application=self, ) diff --git a/itou/job_applications/notifications.py b/itou/job_applications/notifications.py index 894e184ed1..fd0908973a 100644 --- a/itou/job_applications/notifications.py +++ b/itou/job_applications/notifications.py @@ -19,8 +19,8 @@ class JobApplicationNewForJobSeekerNotification(JobSeekerNotification, EmailNoti @notifications_registry.register -class JobApplicationNewForPrescriberNotification(PrescriberNotification, EmailNotification): - """Notification sent to prescriber when created""" +class JobApplicationNewForProxyNotification(PrescriberOrEmployerNotification, EmailNotification): + """Notification sent to proxy (prescriber or employer/orienter) when created""" name = "Confirmation d’envoi de candidature" category = NotificationCategory.JOB_APPLICATION @@ -71,8 +71,8 @@ class JobApplicationAcceptedForJobSeekerNotification(JobSeekerNotification, Emai @notifications_registry.register -class JobApplicationAcceptedForPrescriberNotification(PrescriberNotification, EmailNotification): - """Notification sent to prescriber when accepted""" +class JobApplicationAcceptedForProxyNotification(PrescriberOrEmployerNotification, EmailNotification): + """Notification sent to proxy (prescriber or employer/orienter) when accepted""" name = "Confirmation d’acceptation de candidature" category = NotificationCategory.JOB_APPLICATION @@ -101,8 +101,8 @@ class JobApplicationRefusedForJobSeekerNotification(JobSeekerNotification, Email @notifications_registry.register -class JobApplicationRefusedForPrescriberNotification(PrescriberNotification, EmailNotification): - """Notification sent to prescriber when refused""" +class JobApplicationRefusedForProxyNotification(PrescriberOrEmployerNotification, EmailNotification): + """Notification sent to proxy (prescriber or employer/orienter) when refused""" name = "Refus de candidature" category = NotificationCategory.JOB_APPLICATION diff --git a/itou/www/apply/views/submit_views.py b/itou/www/apply/views/submit_views.py index 6ff1f98b99..8ebd40bebe 100644 --- a/itou/www/apply/views/submit_views.py +++ b/itou/www/apply/views/submit_views.py @@ -676,7 +676,7 @@ def form_valid(self): for employer in company_recipients: job_application.notifications_new_for_employer(employer).send() job_application.notifications_new_for_job_seeker.send() - if self.request.user.is_prescriber: + if self.request.user.kind in [UserKind.PRESCRIBER, UserKind.EMPLOYER]: job_application.notifications_new_for_proxy.send() finally: # We are done, send to the (mostly) stateless final page as we now have no session. diff --git a/tests/job_applications/tests.py b/tests/job_applications/tests.py index da8a00f92a..ddadfc60f0 100644 --- a/tests/job_applications/tests.py +++ b/tests/job_applications/tests.py @@ -33,6 +33,7 @@ from itou.users.models import User from itou.utils import constants as global_constants from itou.utils.templatetags import format_filters +from itou.www.apply.views.process_views import job_application_sender_left_org from tests.approvals.factories import ( ApprovalFactory, PoleEmploiApprovalFactory, @@ -960,6 +961,21 @@ def test_cancel_sent_by_prescriber(self, django_capture_on_commit_callbacks, mai assert job_application.job_seeker.get_full_name() in mailoutbox[0].body assert mailoutbox[0].body == mailoutbox[1].body + def test_for_proxy_notification(self, subtests): + employer_job_app = JobApplicationFactory(sent_by_another_employer=True) + prescriber_job_app = JobApplicationFactory(sent_by_authorized_prescriber_organisation=True) + + for transition in ["cancel", "postpone", "refuse", "new", "accept"]: + with subtests.test(transition): + assert ( + getattr(employer_job_app, f"notifications_{transition}_for_proxy").structure + == employer_job_app.sender_company + ) + assert ( + getattr(prescriber_job_app, f"notifications_{transition}_for_proxy").structure + == prescriber_job_app.sender_prescriber_organization + ) + def test_cancel_sent_by_job_seeker(self, django_capture_on_commit_callbacks, mailoutbox): # When sent by jobseeker. job_application = JobApplicationSentByJobSeekerFactory(state=JobApplicationState.ACCEPTED)