revoke expert avis

This commit is contained in:
Christophe Robillard 2020-07-16 11:14:37 +02:00
parent 4ff8be4b46
commit 3ea34834a7
8 changed files with 95 additions and 6 deletions

View file

@ -3,6 +3,7 @@ module Instructeurs
include CreateAvisConcern
before_action :authenticate_instructeur!, except: [:sign_up, :create_instructeur]
before_action :check_if_avis_revoked, only: [:show]
before_action :redirect_if_no_sign_up_needed, only: [:sign_up]
before_action :check_avis_exists_and_email_belongs_to_avis, only: [:sign_up, :create_instructeur]
before_action :set_avis_and_dossier, only: [:show, :instruction, :messagerie, :create_commentaire, :update]
@ -114,6 +115,14 @@ module Instructeurs
end
end
def revoquer
avis = Avis.find(params[:id])
if avis.revoke!
flash.notice = "#{avis.email_to_display} ne peut plus donner son avis sur ce dossier."
redirect_back(fallback_location: avis_instructeur_dossier_path(avis.procedure, avis.dossier))
end
end
private
def set_avis_and_dossier
@ -135,6 +144,14 @@ module Instructeurs
end
end
def check_if_avis_revoked
avis = Avis.find(params[:id])
if avis.revoked?
flash.alert = "Vous n'avez plus accès à ce dossier."
redirect_to url_for(root_path)
end
end
def check_avis_exists_and_email_belongs_to_avis
if !Avis.avis_exists_and_email_belongs_to_avis?(params[:id], params[:email])
redirect_to url_for(root_path)

View file

@ -56,6 +56,18 @@ class Avis < ApplicationRecord
dossier.procedure
end
def revoked?
revoked_at.present?
end
def revoke!
if answer.present?
update!(revoked_at: Time.zone.now)
else
destroy!
end
end
private
def try_to_assign_instructeur

View file

@ -24,10 +24,17 @@
%h2.instructeur
= (avis.email_to_display == current_instructeur.email) ? 'Vous' : avis.email_to_display
- if avis.answer.present?
- if avis.revoked?
%span.waiting{ class: highlight_if_unseen_class(avis_seen_at, avis.revoked_at) }
Demande d'avis révoquée le #{l(avis.revoked_at, format: '%d/%m/%y à %H:%M')}
- else
%span.waiting= link_to("Révoquer l'avis", revoquer_instructeur_avis_path(avis.procedure, avis), data: { confirm: "Souhaitez-vous révoquer la demande d'avis à #{avis.email_to_display} ?" }, method: :patch)
%span.date{ class: highlight_if_unseen_class(avis_seen_at, avis.updated_at) }
Réponse donnée le #{l(avis.updated_at, format: '%d/%m/%y à %H:%M')}
- else
%span.waiting En attente de réponse
%span.waiting
En attente de réponse
= link_to("Révoquer l'avis", revoquer_instructeur_avis_path(avis.procedure, avis), data: { confirm: "Souhaitez-vous révoquer la demande d'avis à #{avis.email_to_display} ?" }, method: :patch)
- if avis.piece_justificative_file.attached?
= render partial: 'shared/attachment/show', locals: { attachment: avis.piece_justificative_file.attachment }
.answer-body