Skip to content

Commit

Permalink
job_applications: Fix notification structure
Browse files Browse the repository at this point in the history
The sender may be an employer
  • Loading branch information
tonial committed Jan 11, 2025
1 parent e74fe9b commit 2b804fc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
16 changes: 8 additions & 8 deletions itou/job_applications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand All @@ -1108,17 +1108,17 @@ 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,
)

@property
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,
)

Expand All @@ -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,
)

Expand All @@ -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,
)

Expand Down
12 changes: 6 additions & 6 deletions itou/job_applications/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion itou/www/apply/views/submit_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 16 additions & 0 deletions tests/job_applications/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 2b804fc

Please sign in to comment.