Skip to content

Commit

Permalink
apply: Mask sender email when he left his organization
Browse files Browse the repository at this point in the history
  • Loading branch information
tonial committed Oct 14, 2024
1 parent c05aac7 commit 575e568
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 0 deletions.
12 changes: 12 additions & 0 deletions itou/job_applications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,18 @@ def get_sender_kind_display(self):
else:
return SenderKind(self.sender_kind).label

@property
def sender_left_org(self):
if self.sender_prescriber_organization_id:
return not (
self.sender.prescribermembership_set.active()
.filter(organization_id=self.sender_prescriber_organization_id)
.exists()
)
if self.sender_company_id:
return not (self.sender.companymembership_set.active().filter(company_id=self.sender_company_id).exists())
return False

@property
def is_in_transferable_state(self):
return self.state in JobApplicationWorkflow.CAN_BE_TRANSFERRED_STATES
Expand Down
17 changes: 17 additions & 0 deletions itou/templates/apply/includes/job_application_sender_info.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
{% load format_filters %}
{% load matomo %}

{% if job_application.sender_left_org %}
<div class="alert alert-warning alert-dismissible fade show" role="status">
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Fermer"></button>
<div class="row">
<div class="col-auto pe-0">
<i class="ri-information-line ri-xl text-warning" aria-hidden="true"></i>
</div>
<div class="col">
<p class="mb-0">L’émetteur de cette candidature ne fait plus partie de l’organisation émettrice</p>
</div>
</div>
</div>


{% endif %}
<ul class="list-data list-data__two-column-md mb-3">
<li>
<small>Émetteur</small>
Expand All @@ -14,6 +29,8 @@
<small>Adresse e-mail</small>
{% if request.user.is_job_seeker and job_application.sender_kind != SenderKind.JOB_SEEKER %}
<strong>Non communiquée</strong>
{% elif job_application.sender_left_org %}
<div class="text-warning fst-italic">Les réponses seront transmises aux administrateurs de l’organisation</div>
{% else %}
<strong>{{ job_application.sender.email }}</strong>
{% matomo_event "candidature" "clic" "copied_sender_email" as matomo_event_attrs %}
Expand Down
58 changes: 58 additions & 0 deletions tests/job_applications/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from tests.companies.factories import CompanyMembershipFactory
from tests.job_applications.factories import JobApplicationFactory, JobApplicationSentByJobSeekerFactory
from tests.prescribers.factories import PrescriberMembershipFactory


def test_sender_left_org_prescriber():
prescriber_membership = PrescriberMembershipFactory()
job_app = JobApplicationFactory(
sender=prescriber_membership.user, sender_prescriber_organization=prescriber_membership.organization
)
assert job_app.sender_left_org is False

# membership is inactive
prescriber_membership.is_active = False
prescriber_membership.save(update_fields=["is_active"])
assert job_app.sender_left_org is True

# prescriber is inactive
prescriber_membership.is_active = True
prescriber_membership.save(update_fields=["is_active"])
prescriber_membership.user.is_active = False
prescriber_membership.user.save(update_fields=["is_active"])
assert job_app.sender_left_org is True

# membership was removed
prescriber_membership.user.is_active = True
prescriber_membership.user.save(update_fields=["is_active"])
prescriber_membership.delete()
assert job_app.sender_left_org is True


def test_sender_left_org_employer():
company_membership = CompanyMembershipFactory()
job_app = JobApplicationFactory(sender=company_membership.user, sender_company=company_membership.company)
assert job_app.sender_left_org is False

# membership is inactive
company_membership.is_active = False
company_membership.save(update_fields=["is_active"])
assert job_app.sender_left_org is True

# prescriber is inactive
company_membership.is_active = True
company_membership.save(update_fields=["is_active"])
company_membership.user.is_active = False
company_membership.user.save(update_fields=["is_active"])
assert job_app.sender_left_org is True

# membership was removed
company_membership.user.is_active = True
company_membership.user.save(update_fields=["is_active"])
company_membership.delete()
assert job_app.sender_left_org is True


def test_sender_left_org_job_seeker():
job_app = JobApplicationSentByJobSeekerFactory()
assert job_app.sender_left_org is False
46 changes: 46 additions & 0 deletions tests/www/apply/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
PriorActionFactory,
)
from tests.jobs.factories import create_test_romes_and_appellations
from tests.prescribers.factories import PrescriberMembershipFactory
from tests.siae_evaluations.factories import EvaluatedSiaeFactory
from tests.users.factories import EmployerFactory, JobSeekerFactory, LaborInspectorFactory, PrescriberFactory
from tests.utils.htmx.test import assertSoupEqual, update_page_with_htmx
Expand Down Expand Up @@ -248,6 +249,21 @@ def test_details_for_company_from_list(self, client, snapshot):
assertContains(response, resume_link)
assertNotContains(response, PRIOR_ACTION_SECTION_TITLE)

def test_details_when_sender_left_org(self, client):
job_application = JobApplicationFactory(sent_by_authorized_prescriber_organisation=True)
company = job_application.to_company
employer = company.members.first()
sender = job_application.sender
sender.is_active = False
sender.save()
client.force_login(employer)

url = reverse("apply:details_for_company", kwargs={"job_application_id": job_application.pk})
response = client.get(url)
assertNotContains(response, sender.email)
assertContains(response, "Les réponses seront transmises aux administrateurs de l’organisation")
assertContains(response, "L’émetteur de cette candidature ne fait plus partie de l’organisation émettrice")

def test_details_archived(self, client):
UNARCHIVE = "Désarchiver"
job_application = JobApplicationFactory(
Expand Down Expand Up @@ -392,6 +408,20 @@ def test_details_for_prescriber(self, client):
response = client.get(url)
assertContains(response, LackOfNIRReason.NIR_ASSOCIATED_TO_OTHER.label, html=True)

def test_details_for_prescriber_when_sender_left_org(self, client):
job_application = JobApplicationFactory(sent_by_authorized_prescriber_organisation=True)
prescriber = PrescriberMembershipFactory(organization=job_application.sender_prescriber_organization).user
sender = job_application.sender
sender.is_active = False
sender.save()
client.force_login(prescriber)

url = reverse("apply:details_for_prescriber", kwargs={"job_application_id": job_application.pk})
response = client.get(url)
assertNotContains(response, sender.email)
assertContains(response, "Les réponses seront transmises aux administrateurs de l’organisation")
assertContains(response, "L’émetteur de cette candidature ne fait plus partie de l’organisation émettrice")

def test_details_for_prescriber_as_company_when_i_am_not_the_sender(self, client):
job_application = JobApplicationFactory(sent_by_authorized_prescriber_organisation=True)
employer = job_application.to_company.members.first()
Expand Down Expand Up @@ -489,6 +519,22 @@ def test_details_for_job_seeker(self, client):

assertNotContains(response, PRIOR_ACTION_SECTION_TITLE)

def test_details_for_job_seeker_when_sendèer_left_org(self, client):
job_seeker = JobSeekerFactory()

job_application = JobApplicationFactory(job_seeker=job_seeker, job_seeker_with_address=True)
sender = job_application.sender
sender.is_active = False
sender.save()

client.force_login(job_seeker)

url = reverse("apply:details_for_jobseeker", kwargs={"job_application_id": job_application.pk})
response = client.get(url)
assertNotContains(response, sender.email)
assertContains(response, "Les réponses seront transmises aux administrateurs de l’organisation")
assertContains(response, "L’émetteur de cette candidature ne fait plus partie de l’organisation émettrice")

def test_details_for_job_seeker_as_other_user(self, client, subtests):
job_application = JobApplicationFactory()
url = reverse("apply:details_for_jobseeker", kwargs={"job_application_id": job_application.pk})
Expand Down

0 comments on commit 575e568

Please sign in to comment.