2018-08-29 11:44:12 +02:00
|
|
|
class SupportController < ApplicationController
|
2021-12-29 14:00:47 +01:00
|
|
|
invisible_captcha only: [:create], on_spam: :redirect_to_root
|
|
|
|
|
2018-08-29 11:44:12 +02:00
|
|
|
def index
|
|
|
|
setup_context
|
|
|
|
end
|
|
|
|
|
2018-11-28 15:19:12 +01:00
|
|
|
def admin
|
|
|
|
setup_context_admin
|
|
|
|
end
|
|
|
|
|
2018-08-29 11:44:12 +02:00
|
|
|
def create
|
|
|
|
if direct_message? && create_commentaire
|
|
|
|
flash.notice = "Votre message a été envoyé sur la messagerie de votre dossier."
|
|
|
|
|
2018-09-27 17:14:00 +02:00
|
|
|
redirect_to messagerie_dossier_path(dossier)
|
2018-08-29 11:44:12 +02:00
|
|
|
elsif create_conversation
|
|
|
|
flash.notice = "Votre message a été envoyé."
|
|
|
|
|
2018-11-28 15:19:12 +01:00
|
|
|
if params[:admin]
|
|
|
|
redirect_to root_path(formulaire_contact_admin_submitted: true)
|
|
|
|
else
|
|
|
|
redirect_to root_path(formulaire_contact_general_submitted: true)
|
|
|
|
end
|
2018-08-29 11:44:12 +02:00
|
|
|
else
|
2024-03-20 11:39:42 +01:00
|
|
|
flash.now.alert = "Une erreur est survenue. Vous pouvez nous contacter à #{helpers.mail_to(Current.contact_email)}."
|
2018-08-29 11:44:12 +02:00
|
|
|
|
2018-11-28 15:19:12 +01:00
|
|
|
if params[:admin]
|
|
|
|
setup_context_admin
|
|
|
|
render :admin
|
|
|
|
else
|
|
|
|
setup_context
|
|
|
|
render :index
|
|
|
|
end
|
2018-08-29 11:44:12 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def setup_context
|
|
|
|
@dossier_id = dossier&.id
|
2018-08-30 13:48:03 +02:00
|
|
|
@tags = tags
|
2020-08-25 15:01:54 +02:00
|
|
|
@options = Helpscout::FormAdapter.options
|
2018-08-29 11:44:12 +02:00
|
|
|
end
|
|
|
|
|
2018-11-28 15:19:12 +01:00
|
|
|
def setup_context_admin
|
|
|
|
@tags = tags
|
2020-08-25 15:01:54 +02:00
|
|
|
@options = Helpscout::FormAdapter.admin_options
|
2018-11-28 15:19:12 +01:00
|
|
|
end
|
|
|
|
|
2018-08-29 11:44:12 +02:00
|
|
|
def create_conversation
|
|
|
|
Helpscout::FormAdapter.new(
|
|
|
|
subject: params[:subject],
|
|
|
|
email: email,
|
2018-11-28 15:19:12 +01:00
|
|
|
phone: params[:phone],
|
2018-08-29 11:44:12 +02:00
|
|
|
text: params[:text],
|
2019-06-25 17:12:44 +02:00
|
|
|
file: params[:piece_jointe],
|
2019-02-12 16:59:37 +01:00
|
|
|
dossier_id: dossier&.id,
|
2018-08-29 11:44:12 +02:00
|
|
|
browser: browser_name,
|
|
|
|
tags: tags
|
|
|
|
).send_form
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_commentaire
|
2019-01-21 17:36:36 +01:00
|
|
|
attributes = {
|
2019-06-25 17:12:44 +02:00
|
|
|
piece_jointe: params[:piece_jointe],
|
2018-08-29 11:44:12 +02:00
|
|
|
body: "[#{params[:subject]}]<br><br>#{params[:text]}"
|
2018-11-29 15:00:26 +01:00
|
|
|
}
|
2021-11-30 18:56:12 +01:00
|
|
|
CommentaireService.create!(current_user, dossier, attributes)
|
2018-08-29 11:44:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def tags
|
|
|
|
[params[:tags], params[:type]].flatten.compact
|
2018-08-30 13:48:03 +02:00
|
|
|
.map { |tag| tag.split(',') }
|
|
|
|
.flatten
|
2023-04-19 10:59:21 +02:00
|
|
|
.compact_blank.uniq
|
2018-08-29 11:44:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def browser_name
|
|
|
|
if browser.known?
|
|
|
|
"#{browser.name} #{browser.version} (#{browser.platform.name})"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def direct_message?
|
2019-07-01 18:14:02 +02:00
|
|
|
user_signed_in? && params[:type] == Helpscout::FormAdapter::TYPE_INSTRUCTION && dossier.present? && dossier.messagerie_available?
|
2018-08-29 11:44:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def dossier
|
|
|
|
@dossier ||= current_user&.dossiers&.find_by(id: params[:dossier_id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def email
|
2019-09-17 11:01:20 +02:00
|
|
|
current_user&.email || params[:email]
|
2018-08-29 11:44:12 +02:00
|
|
|
end
|
2021-12-29 14:00:47 +01:00
|
|
|
|
|
|
|
def redirect_to_root
|
2022-07-28 12:31:55 +02:00
|
|
|
redirect_to root_path, alert: t('invisible_captcha.sentence_for_humans')
|
2021-12-29 14:00:47 +01:00
|
|
|
end
|
2018-08-29 11:44:12 +02:00
|
|
|
end
|