Skip to content

Commit

Permalink
display approving instructor on authorizations
Browse files Browse the repository at this point in the history
  • Loading branch information
JeSuisUnCaillou committed Jan 20, 2025
1 parent 7573b00 commit 5186fc2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 17 deletions.
12 changes: 12 additions & 0 deletions app/models/authorization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class Authorization < ApplicationRecord
inverse_of: :authorization,
dependent: :destroy

has_many :authorization_request_event,
as: :entity,
dependent: :nullify

scope :validated, -> { joins(:request).where(authorization_requests: { state: 'validated' }) }

delegate :name, :kind, to: :request
Expand Down Expand Up @@ -64,6 +68,14 @@ def definition
authorization_request_class.constantize.definition
end

def approving_instructor
authorization_request_event
.where(name: 'approve')
.order(created_at: :desc)
.first
.try(:user)
end

private

def affect_snapshot_documents(request_as_validated)
Expand Down
7 changes: 6 additions & 1 deletion app/views/authorization_request_forms/build/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@

<% if @authorization && policy([:instruction, @authorization_request]).show? %>
<div class="fr-pb-2w fr-pl-1w">
Cette habilitation a été délivrée suite à la <%= link_to "demande N°#{@authorization_request.id}", instruction_authorization_request_authorizations_path(@authorization_request), class: 'fr-link' %>
Cette habilitation a été validée
<% if @authorization.approving_instructor %>
par
<strong><%=@authorization.approving_instructor.email%></strong>
<% end %>
durant la <%= link_to "demande N°#{@authorization_request.id}", instruction_authorization_request_authorizations_path(@authorization_request), class: 'fr-link' %>
</div>
<% end %>
</div>
Expand Down
38 changes: 23 additions & 15 deletions app/views/instruction/authorizations/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,32 @@
<% @authorizations.each do |authorization| %>
<li class="authorization-row fr-mb-4w fr-pb-2w">
<div class="fr-grid-row fr-grid-row--middle">
<ul class="fr-badge-group fr-col">
<li>
<span class="fr-badge fr-badge--no-icon">
<%= t("authorization.id_badge", id: authorization.id) %>
</span>
</li>
<li>
<span class="fr-badge fr-badge--no-icon">
<%= t("authorization.date_badge", date: authorization.created_at.strftime('%d/%m/%Y')) %>
</span>
</li>

<% if authorization.definition.stage.exists? %>
<div class="fr-col">
<ul class="fr-badge-group">
<li>
<span class="fr-badge fr-badge--no-icon">
<%= t("authorization.id_badge", id: authorization.id) %>
</span>
</li>
<li>
<%= authorization_stage_badge(authorization) %>
<span class="fr-badge fr-badge--no-icon">
<%= t("authorization.date_badge", date: authorization.created_at.strftime('%d/%m/%Y')) %>
</span>
</li>

<% if authorization.definition.stage.exists? %>
<li>
<%= authorization_stage_badge(authorization) %>
</li>
<% end %>
</ul>

<% if authorization.approving_instructor.present? %>
<div>
Validé par <strong><%= authorization.approving_instructor.email %></strong>
</div>
<% end %>
</ul>
</div>

<div>
<%= link_to t('.show_cta'), authorization_request_authorization_path(@authorization_request, authorization), class: "fr-btn" %>
Expand Down
2 changes: 1 addition & 1 deletion features/instructeurs/historique_habilitation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,5 @@ Fonctionnalité: Instruction: historique habilitation
Et que je clique sur "Consulter"
Et que je clique sur "Historique"
Et que je clique sur "Consulter l'habilitation"
Alors la page contient "Cette habilitation a été délivrée suite à la demande N°"
Alors la page contient "Cette habilitation a été validée par"
Et la page contient un lien vers "/instruction/demandes/\d+/habilitations"

0 comments on commit 5186fc2

Please sign in to comment.