demarches-normaliennes/app/controllers/commentaires_controller.rb

47 lines
1.6 KiB
Ruby
Raw Normal View History

2015-08-10 11:05:06 +02:00
class CommentairesController < ApplicationController
def create
2015-08-11 15:22:07 +02:00
@commentaire = Commentaire.new
2015-08-10 11:05:06 +02:00
@commentaire.dossier = Dossier.find(params['dossier_id'])
if is_gestionnaire?
@commentaire.email = current_gestionnaire.email
@commentaire.dossier.next_step! 'gestionnaire', 'comment'
else
@commentaire.email = current_user.email
@commentaire.dossier.next_step! 'user', 'comment' if current_user.email == @commentaire.dossier.user.email
end
unless params[:piece_justificative].nil?
pj = PiecesJustificativesService.upload_one! @commentaire.dossier, current_user, params
if pj.errors.empty?
@commentaire.piece_justificative = pj
else
flash.alert = pj.errors.full_messages.join("<br>").html_safe
end
end
@commentaire.body = params['texte_commentaire']
saved = false
saved = @commentaire.save unless flash.alert
2015-08-10 11:05:06 +02:00
2015-09-22 15:00:59 +02:00
if is_gestionnaire?
unless current_gestionnaire.follow? @commentaire.dossier
current_gestionnaire.toggle_follow_dossier @commentaire.dossier
end
NotificationMailer.new_answer(@commentaire.dossier).deliver_now! if saved
2015-09-22 15:00:59 +02:00
redirect_to url_for(controller: 'backoffice/dossiers', action: :show, id: params['dossier_id'])
elsif current_user.email != @commentaire.dossier.user.email
2016-02-22 15:21:18 +01:00
invite = Invite.where(dossier: @commentaire.dossier, user: current_user).first
redirect_to url_for(controller: 'users/dossiers/invites', action: :show, id: invite.id)
2015-08-10 11:05:06 +02:00
else
2015-09-22 15:00:59 +02:00
redirect_to url_for(controller: :recapitulatif, action: :show, dossier_id: params['dossier_id'])
2015-08-10 11:05:06 +02:00
end
end
2015-09-22 15:00:59 +02:00
def is_gestionnaire?
false
end
2015-08-10 11:05:06 +02:00
end