2021-11-15 13:18:10 +01:00
|
|
|
module Instructeurs
|
2022-05-20 15:27:59 +02:00
|
|
|
class CommentairesController < ApplicationController
|
|
|
|
before_action :authenticate_instructeur_or_expert!
|
2022-04-19 09:40:59 +02:00
|
|
|
after_action :mark_messagerie_as_read
|
|
|
|
|
2021-11-15 13:18:10 +01:00
|
|
|
def destroy
|
2022-04-19 09:40:59 +02:00
|
|
|
if commentaire.sent_by?(current_instructeur) || commentaire.sent_by?(current_expert)
|
|
|
|
commentaire.soft_delete!
|
|
|
|
|
|
|
|
flash.notice = t('.notice')
|
2021-11-15 13:18:10 +01:00
|
|
|
else
|
2022-04-19 09:40:59 +02:00
|
|
|
flash.alert = t('.alert_acl')
|
2021-11-15 13:18:10 +01:00
|
|
|
end
|
2021-11-16 16:10:08 +01:00
|
|
|
rescue Discard::RecordNotDiscarded
|
2022-04-19 09:40:59 +02:00
|
|
|
# i18n-tasks-use t('instructeurs.commentaires.destroy.alert_already_discarded')
|
|
|
|
flash.alert = t('.alert_already_discarded')
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def mark_messagerie_as_read
|
|
|
|
if commentaire.sent_by?(current_instructeur)
|
|
|
|
current_instructeur.mark_tab_as_seen(commentaire.dossier, :messagerie)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def commentaire
|
|
|
|
@commentaire ||= Dossier
|
|
|
|
.find(params[:dossier_id])
|
|
|
|
.commentaires
|
|
|
|
.find(params[:id])
|
2021-11-15 13:18:10 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|