diff --git a/itou/templates/employees/detail.html b/itou/templates/employees/detail.html
index e9e0fbf033e..2e58415f0b7 100644
--- a/itou/templates/employees/detail.html
+++ b/itou/templates/employees/detail.html
@@ -1,13 +1,13 @@
{% extends "layout/base.html" %}
{% load matomo %}
-{% block title %}Profil salarié - {{ approval.user.get_full_name }} {{ block.super }}{% endblock %}
+{% block title %}Profil salarié - {{ job_seeker.get_full_name }} {{ block.super }}{% endblock %}
{% block title_prevstep %}
{% include "layout/previous_step.html" with back_url=back_url only %}
{% endblock %}
-{% block title_content %}
@@ -18,7 +18,7 @@
Informations du salarié
- {% include "apply/includes/job_seeker_info.html" with job_seeker=approval.user job_application=job_application with_matomo_event=True can_view_personal_information=can_view_personal_information can_edit_personal_information=can_edit_personal_information request=request csrf_token=csrf_token SenderKind=SenderKind only %}
+ {% include "apply/includes/job_seeker_info.html" with job_seeker=job_seeker job_application=job_application with_matomo_event=True can_view_personal_information=can_view_personal_information can_edit_personal_information=can_edit_personal_information request=request csrf_token=csrf_token SenderKind=SenderKind only %}
{# Eligibility ------------------------------------------------------------------------- #}
{% if eligibility_diagnosis %}
{% include "apply/includes/eligibility_diagnosis.html" with eligibility_diagnosis=eligibility_diagnosis job_seeker=job_application.job_seeker is_sent_by_authorized_prescriber=job_application.is_sent_by_authorized_prescriber siae=job_application.to_company %}
@@ -35,51 +35,47 @@ Candidatures de ce salarié
+ {% endif %}
{% if link_immersion_facile %}
{# Immersion Facilitée proposal on expiring passes #}
diff --git a/itou/www/employees_views/views.py b/itou/www/employees_views/views.py
index 0b22003626f..46326f930a3 100644
--- a/itou/www/employees_views/views.py
+++ b/itou/www/employees_views/views.py
@@ -33,6 +33,7 @@ class EmployeeDetailView(LoginRequiredMixin, DetailView):
template_name = "employees/detail.html"
slug_field = "public_id"
slug_url_kwarg = "public_id"
+ context_object_name = "job_seeker"
def setup(self, request, *args, **kwargs):
super().setup(request, *args, **kwargs)
@@ -85,9 +86,9 @@ def get_context_data(self, **kwargs):
approval = self.object.approvals.order_by("-end_at").first()
context["can_view_personal_information"] = True # SIAE members have access to personal info
- context["can_edit_personal_information"] = self.request.user.can_edit_personal_information(approval.user)
- context["approval_can_be_suspended_by_siae"] = approval.can_be_suspended_by_siae(self.siae)
- context["approval_can_be_prolonged"] = approval.can_be_prolonged
+ context["can_edit_personal_information"] = self.request.user.can_edit_personal_information(self.object)
+ context["approval_can_be_suspended_by_siae"] = approval and approval.can_be_suspended_by_siae(self.siae)
+ context["approval_can_be_prolonged"] = approval and approval.can_be_prolonged
context["approval"] = approval
context["job_application"] = job_application
context["matomo_custom_title"] = "Profil salarié"
@@ -96,7 +97,7 @@ def get_context_data(self, **kwargs):
context["back_url"] = get_safe_url(self.request, "back_url", fallback_url=reverse_lazy("approvals:list"))
context["link_immersion_facile"] = None
- if approval.is_in_progress:
+ if approval and approval.is_in_progress:
# suspension_set has already been loaded via prefetch_related for the remainder computation
for suspension in sorted(approval.suspension_set.all(), key=lambda s: s.start_at):
if suspension.is_in_progress:
@@ -127,13 +128,13 @@ def get_context_data(self, **kwargs):
)
break
- if approval.remainder.days < 90 and self.request.user.is_employer:
+ if approval and approval.remainder.days < 90 and self.request.user.is_employer:
context["link_immersion_facile"] = immersion_search_url(approval.user)
context["approval_expired"] = not approval.is_in_progress
context["all_job_applications"] = (
JobApplication.objects.filter(
- job_seeker=approval.user,
+ job_seeker=self.object,
to_company=self.siae,
)
.select_related("sender", "to_company")
diff --git a/tests/www/employees_views/test_detail.py b/tests/www/employees_views/test_detail.py
index 1c7ec752211..01af5b3cbf1 100644
--- a/tests/www/employees_views/test_detail.py
+++ b/tests/www/employees_views/test_detail.py
@@ -29,6 +29,8 @@
class TestEmployeeDetailView:
+ APPROVAL_NUMBER_LABEL = "Numéro de PASS IAE"
+
def test_anonymous_user(self, client):
approval = ApprovalFactory()
url = reverse("employees:detail", kwargs={"public_id": approval.user.public_id})
@@ -68,7 +70,7 @@ def test_detail_view(self, client):
{"back_url": reverse("approvals:list")},
)
response = client.get(url)
- assertContains(response, "Numéro de PASS IAE")
+ assertContains(response, self.APPROVAL_NUMBER_LABEL)
assertContains(response, "Informations du salarié")
assertContains(response, "Éligibilité à l'IAE")
assertContains(response, "Candidatures de ce salarié")
@@ -101,7 +103,21 @@ def test_detail_view_no_job_application(self, client):
url = reverse("employees:detail", kwargs={"public_id": approval.user.public_id})
response = client.get(url)
# Check that the page didn't crash
- assertContains(response, "Numéro de PASS IAE")
+ assertContains(response, self.APPROVAL_NUMBER_LABEL)
+ assertContains(response, "Informations du salarié")
+ assertContains(response, "Candidatures de ce salarié")
+
+ def test_detail_view_no_approval(self, client):
+ company = CompanyFactory(with_membership=True, subject_to_eligibility=True)
+ employer = company.members.first()
+
+ job_seeker = JobApplicationFactory(to_company=company, state=JobApplicationState.ACCEPTED).job_seeker
+
+ client.force_login(employer)
+ url = reverse("employees:detail", kwargs={"public_id": job_seeker.public_id})
+ response = client.get(url)
+ # Check that the page didn't crash
+ assertNotContains(response, self.APPROVAL_NUMBER_LABEL)
assertContains(response, "Informations du salarié")
assertContains(response, "Candidatures de ce salarié")