2015-08-10 11:05:06 +02:00
|
|
|
class CommentairesController < ApplicationController
|
|
|
|
def create
|
2015-08-11 15:22:07 +02:00
|
|
|
@commentaire = Commentaire.new
|
2016-11-14 18:00:26 +01:00
|
|
|
@commentaire.champ = @commentaire.dossier.champs.find(params[:champ_id]) if params[:champ_id]
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2017-07-10 17:11:55 +02:00
|
|
|
dossier_id = params['dossier_id']
|
2018-01-15 10:02:10 +01:00
|
|
|
@commentaire.email = current_user.email
|
|
|
|
@commentaire.dossier = current_user.dossiers.find_by(id: dossier_id) || current_user.invites.find_by!(dossier_id: dossier_id).dossier
|
2015-09-25 10:46:09 +02:00
|
|
|
|
2017-10-31 17:45:04 +01:00
|
|
|
@commentaire.file = params["file"]
|
2016-04-20 16:51:57 +02:00
|
|
|
|
2015-09-25 10:46:09 +02:00
|
|
|
@commentaire.body = params['texte_commentaire']
|
2017-10-31 17:45:04 +01:00
|
|
|
if @commentaire.save
|
|
|
|
flash.notice = "Votre message a été envoyé"
|
2016-12-07 16:59:35 +01:00
|
|
|
else
|
2017-10-31 17:45:04 +01:00
|
|
|
flash.alert = "Veuillez rédiger un message ou ajouter une pièce jointe (maximum 20 Mo)"
|
2016-12-07 16:59:35 +01:00
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2018-01-15 10:02:10 +01:00
|
|
|
if current_user.email != @commentaire.dossier.user.email
|
|
|
|
invite = Invite.where(dossier: @commentaire.dossier, email: current_user.email).first
|
|
|
|
redirect_to url_for(controller: 'users/dossiers/invites', action: :show, id: invite.id)
|
2015-08-10 11:05:06 +02:00
|
|
|
else
|
2018-01-15 10:02:10 +01:00
|
|
|
redirect_to users_dossier_recapitulatif_path(params['dossier_id'])
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|