2021-11-15 13:18:10 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Instructeurs
|
|
|
|
class CommentairesController < ProceduresController
|
|
|
|
def destroy
|
2021-11-16 16:10:08 +01:00
|
|
|
commentaire = Dossier.find(params[:dossier_id]).commentaires.find(params[:id])
|
|
|
|
if commentaire.sent_by?(current_instructeur)
|
|
|
|
commentaire.piece_jointe.purge_later if commentaire.piece_jointe.attached?
|
|
|
|
commentaire.discard!
|
|
|
|
commentaire.update!(body: '')
|
2021-11-15 14:15:05 +01:00
|
|
|
flash[:notice] = t('views.shared.commentaires.destroy.notice')
|
2021-11-15 13:18:10 +01:00
|
|
|
else
|
2021-11-16 16:10:08 +01:00
|
|
|
flash[:alert] = I18n.t('views.shared.commentaires.destroy.alert_reasons.acl')
|
2021-11-15 13:18:10 +01:00
|
|
|
end
|
2021-11-15 13:53:32 +01:00
|
|
|
redirect_to(messagerie_instructeur_dossier_path(params[:procedure_id], params[:dossier_id]))
|
2021-11-16 16:10:08 +01:00
|
|
|
rescue Discard::RecordNotDiscarded
|
|
|
|
flash[:alert] = I18n.t('views.shared.commentaires.destroy.alert_reasons.already_discarded')
|
|
|
|
redirect_to(messagerie_instructeur_dossier_path(params[:procedure_id], params[:dossier_id]))
|
2021-11-15 13:18:10 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|