Skip to content

Commit

Permalink
www.employees_views: handle missing approval case
Browse files Browse the repository at this point in the history
  • Loading branch information
xavfernandez committed Sep 12, 2024
1 parent e123886 commit 026f021
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 52 deletions.
84 changes: 40 additions & 44 deletions itou/templates/employees/detail.html
Original file line number Diff line number Diff line change
@@ -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 %}<h1>Salarié : {{ approval.user.get_full_name }}</h1>{% endblock %}
{% block title_content %}<h1>Salarié : {{ job_seeker.get_full_name }}</h1>{% endblock %}

{% block content %}
<section class="s-section">
Expand All @@ -18,7 +18,7 @@
<div class="c-box mb-3 mb-lg-5">
<h2>Informations du salarié</h2>
<hr>
{% 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 %}
Expand All @@ -35,51 +35,47 @@ <h2>Candidatures de ce salarié</h2>
</div>
</div>
<div class="col-12 col-lg-4 order-1 order-lg-2">
<div class="c-box mb-4">
{# Approval status. #}
<div>{% include "approvals/includes/status.html" with common_approval=approval hiring_pending=False %}</div>
{# Approval actions. #}
{% if approval and request.user.is_employer %}
{% if approval_can_be_suspended_by_siae %}
<a href="{% url 'approvals:suspend' approval_id=approval.id %}?back_url={{ request.get_full_path|urlencode }}"
class="btn btn-block btn-outline-primary mt-3"
aria-label="Suspendre le PASS IAE de {{ approval.user.get_full_name }}">
Suspendre
</a>
{% elif approval.can_be_suspended %}
<div class="btn btn-ico">
<span class="disabled">Suspendre</span>
<i class="ri-information-line ri-xl text-info" data-bs-toggle="tooltip" title="La suspension n’est pas possible car un autre employeur a embauché le candidat."></i>
</div>
{% endif %}
{% if approval_can_be_prolonged %}
<a href="{% url 'approvals:declare_prolongation' approval_id=approval.id %}?back_url={{ request.get_full_path|urlencode }}"
class="btn btn-block btn-outline-primary mt-3"
aria-label="Prolonger le PASS IAE de {{ approval.user.get_full_name }}">
Prolonger
</a>
{% endif %}
{% if approval_deletion_form_url %}
<a href="{{ approval_deletion_form_url }}"
id="approval-deletion-link"
class="btn btn-block btn-outline-warning mt-3"
{% if approval %}
<div class="c-box mb-4">
{# Approval status. #}
<div>{% include "approvals/includes/status.html" with common_approval=approval hiring_pending=False %}</div>
{# Approval actions. #}
{% if request.user.is_employer %}
{% if approval_can_be_suspended_by_siae %}
<a href="{% url 'approvals:suspend' approval_id=approval.id %}?back_url={{ request.get_full_path|urlencode }}"
class="btn btn-block btn-outline-primary mt-3"
aria-label="Suspendre le PASS IAE de {{ job_seeker.get_full_name }}">Suspendre</a>
{% elif approval.can_be_suspended %}
<div class="btn btn-ico">
<span class="disabled">Suspendre</span>
<i class="ri-information-line ri-xl text-info" data-bs-toggle="tooltip" title="La suspension n’est pas possible car un autre employeur a embauché le candidat."></i>
</div>
{% endif %}
{% if approval_can_be_prolonged %}
<a href="{% url 'approvals:declare_prolongation' approval_id=approval.id %}?back_url={{ request.get_full_path|urlencode }}"
class="btn btn-block btn-outline-primary mt-3"
aria-label="Prolonger le PASS IAE de {{ job_seeker.get_full_name }}">Prolonger</a>
{% endif %}
{% if approval_deletion_form_url %}
<a href="{{ approval_deletion_form_url }}"
id="approval-deletion-link"
class="btn btn-block btn-outline-warning mt-3"
target="_blank"
rel="noopener"
aria-label="Mettre fin au PASS IAE de {{ job_seeker.get_full_name }}">Clôturer</a>
{% endif %}
<a class="btn btn-primary btn-block btn-ico mt-3"
{% matomo_event "telechargement-pdf" "agrement" "detail-agrement" %}
href="{% url 'approvals:display_printable_approval' approval_id=approval.id %}"
target="_blank"
rel="noopener"
aria-label="Mettre fin au PASS IAE de {{ approval.user.get_full_name }}">
Clôturer
aria-label="Afficher le PASS IAE de {{ job_seeker.get_full_name }}">
<i class="ri-eye-line ri-xl font-weight-medium" aria-hidden="true"></i>
<span>Afficher l'attestation</span>
</a>
{% endif %}
<a class="btn btn-primary btn-block btn-ico mt-3"
{% matomo_event "telechargement-pdf" "agrement" "detail-agrement" %}
href="{% url 'approvals:display_printable_approval' approval_id=approval.id %}"
target="_blank"
rel="noopener"
aria-label="Afficher le PASS IAE de {{ approval.user.get_full_name }}">
<i class="ri-eye-line ri-xl font-weight-medium" aria-hidden="true"></i>
<span>Afficher l'attestation</span>
</a>
{% endif %}
</div>
</div>
{% endif %}
{% if link_immersion_facile %}
{# Immersion Facilitée proposal on expiring passes #}
<div class="c-box p-0 mb-4" id="immersion-facile-opportunity-alert">
Expand Down
13 changes: 7 additions & 6 deletions itou/www/employees_views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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é"
Expand All @@ -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:
Expand Down Expand Up @@ -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")
Expand Down
20 changes: 18 additions & 2 deletions tests/www/employees_views/test_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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é")
Expand Down Expand Up @@ -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é")

Expand Down

0 comments on commit 026f021

Please sign in to comment.