From 7ac4dc355fb13c1cfc1029e888eec7d7d89fcd59 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 30 Aug 2018 12:10:56 +0100 Subject: [PATCH 1/9] Add default dossier_id to contact form on dossier pages --- app/helpers/application_helper.rb | 6 +++++- app/views/layouts/_footer.html.haml | 5 ++++- app/views/new_user/dossiers/_footer.html.haml | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 070455ded..aadc34ce2 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -56,7 +56,11 @@ module ApplicationHelper def contact_link(title, options = {}) if Flipflop.support_form? - params = { tags: options[:tags], type: options[:type] }.compact + params = { + tags: options[:tags], + type: options[:type], + dossier_id: options[:dossier_id] + }.compact link_to title, contact_url(params), options else mail_to CONTACT_EMAIL, title, diff --git a/app/views/layouts/_footer.html.haml b/app/views/layouts/_footer.html.haml index 1d9a90032..7140724b5 100644 --- a/app/views/layouts/_footer.html.haml +++ b/app/views/layouts/_footer.html.haml @@ -9,4 +9,7 @@ \- = link_to 'CGU / Mentions légales', CGU_URL \- - = contact_link 'Contact' + - if @facade.present? && @facade.respond_to?(:dossier) + = contact_link 'Contact', dossier_id: @facade.dossier&.id + - else + = contact_link 'Contact' diff --git a/app/views/new_user/dossiers/_footer.html.haml b/app/views/new_user/dossiers/_footer.html.haml index 45d6fafda..a012e66ea 100644 --- a/app/views/new_user/dossiers/_footer.html.haml +++ b/app/views/new_user/dossiers/_footer.html.haml @@ -36,4 +36,4 @@ – = link_to "Mentions légales", MENTIONS_LEGALES_URL, :class => "footer-link", :target => "_blank", rel: "noopener noreferrer" – - = contact_link "Contact technique", class: "footer-link" + = contact_link "Contact technique", class: "footer-link", dossier_id: dossier.id From 441e123e8a909cc029bb36e8006941eea0d3405c Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 30 Aug 2018 12:47:13 +0100 Subject: [PATCH 2/9] Do not lose form content on errors --- app/controllers/support_controller.rb | 2 -- app/views/support/index.html.haml | 10 +++++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/controllers/support_controller.rb b/app/controllers/support_controller.rb index fdb634758..9a04d1563 100644 --- a/app/controllers/support_controller.rb +++ b/app/controllers/support_controller.rb @@ -26,8 +26,6 @@ class SupportController < ApplicationController def setup_context @dossier_id = dossier&.id - @type = params[:type] - @tags = params[:tags] @options = Helpscout::FormAdapter::OPTIONS end diff --git a/app/views/support/index.html.haml b/app/views/support/index.html.haml index 5b1a5a307..09b019893 100644 --- a/app/views/support/index.html.haml +++ b/app/views/support/index.html.haml @@ -14,13 +14,13 @@ = label_tag :email do Email %span.mandatory * - = text_field_tag :email, '', required: true + = text_field_tag :email, params[:email], required: true .contact-champ = label_tag :type do Votre problème %span.mandatory * - = select_tag :type, options_for_select(@options, @type) + = select_tag :type, options_for_select(@options, params[:type]) .contact-champ = label_tag :dossier_id, 'Numéro du dossier concerné' @@ -30,19 +30,19 @@ = label_tag :subject do Sujet %span.mandatory * - = text_field_tag :subject, '', required: true + = text_field_tag :subject, params[:subject], required: true .contact-champ = label_tag :text do Message %span.mandatory * - = text_area_tag :text, '', rows: 6, required: true + = text_area_tag :text, params[:text], rows: 6, required: true .contact-champ = label_tag :text, 'Pièce jointe' = file_field_tag :file - = hidden_field_tag :tags, @tags + = hidden_field_tag :tags, params[:tags] .send-wrapper = button_tag 'Envoyer le message', type: :submit, class: 'button send primary' From b60805a54c8275c4268fe1810d12f60e164695f6 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 30 Aug 2018 12:47:45 +0100 Subject: [PATCH 3/9] Use mailto in error message --- app/assets/stylesheets/new_design/new_alert.scss | 5 +++++ app/controllers/support_controller.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/new_design/new_alert.scss b/app/assets/stylesheets/new_design/new_alert.scss index 909048b2e..0e5d04c60 100644 --- a/app/assets/stylesheets/new_design/new_alert.scss +++ b/app/assets/stylesheets/new_design/new_alert.scss @@ -8,6 +8,11 @@ .alert-danger { background-color: $medium-red; color: #FFFFFF; + + a { + color: #FFFFFF; + text-decoration: underline; + } } .alert-success { diff --git a/app/controllers/support_controller.rb b/app/controllers/support_controller.rb index 9a04d1563..13424e02e 100644 --- a/app/controllers/support_controller.rb +++ b/app/controllers/support_controller.rb @@ -16,7 +16,7 @@ class SupportController < ApplicationController redirect_to root_path else setup_context - flash.now.alert = "Une erreur est survenue. Vous pouvez nous contactez à #{CONTACT_EMAIL}." + flash.now.alert = "Une erreur est survenue. Vous pouvez nous contactez à #{view_context.mail_to(CONTACT_EMAIL)}." render :index end From ea5248dde1ad2d2940fe79c60ade3d5a6c3fa6bb Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 30 Aug 2018 12:48:03 +0100 Subject: [PATCH 4/9] Flatten tags list, cast to array and remove blank elements --- app/controllers/support_controller.rb | 4 ++++ app/views/support/index.html.haml | 2 +- spec/controllers/support_controller_spec.rb | 11 +++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/controllers/support_controller.rb b/app/controllers/support_controller.rb index 13424e02e..99089edd0 100644 --- a/app/controllers/support_controller.rb +++ b/app/controllers/support_controller.rb @@ -26,6 +26,7 @@ class SupportController < ApplicationController def setup_context @dossier_id = dossier&.id + @tags = tags @options = Helpscout::FormAdapter::OPTIONS end @@ -51,6 +52,9 @@ class SupportController < ApplicationController def tags [params[:tags], params[:type]].flatten.compact + .map { |tag| tag.split(',') } + .flatten + .reject(&:blank?).uniq end def browser_name diff --git a/app/views/support/index.html.haml b/app/views/support/index.html.haml index 09b019893..ac566f292 100644 --- a/app/views/support/index.html.haml +++ b/app/views/support/index.html.haml @@ -42,7 +42,7 @@ = label_tag :text, 'Pièce jointe' = file_field_tag :file - = hidden_field_tag :tags, params[:tags] + = hidden_field_tag :tags, @tags&.join(',') .send-wrapper = button_tag 'Envoyer le message', type: :submit, class: 'button send primary' diff --git a/spec/controllers/support_controller_spec.rb b/spec/controllers/support_controller_spec.rb index 93ea27bc8..e47d1f002 100644 --- a/spec/controllers/support_controller_spec.rb +++ b/spec/controllers/support_controller_spec.rb @@ -38,6 +38,17 @@ describe SupportController, type: :controller do expect(response.body).to include(tag) end end + + describe "with multiple tags" do + let(:tags) { ['yolo', 'toto'] } + + it 'should fill tags' do + get :index, params: { tags: tags } + + expect(response.status).to eq(200) + expect(response.body).to include(tags.join(',')) + end + end end context 'signed out' do From 854bc62caa733ed63cbe8582d3b4668bf6d41d76 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 30 Aug 2018 13:25:10 +0100 Subject: [PATCH 5/9] Fix class name --- app/views/root/landing.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/root/landing.html.haml b/app/views/root/landing.html.haml index c912c1bfa..6fa52eb8f 100644 --- a/app/views/root/landing.html.haml +++ b/app/views/root/landing.html.haml @@ -72,7 +72,7 @@ %div = contact_link "Contactez-nous", tags: 'landing', - class: "cta-panel-button white", + class: "cta-panel-button-white", target: "_blank", rel: "noopener noreferrer" From 0c582197dad3e2bd0d1c7a2cc4edb9ba34fca775 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 30 Aug 2018 13:43:03 +0100 Subject: [PATCH 6/9] Do not send messages to brouillon dossier --- app/controllers/support_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/support_controller.rb b/app/controllers/support_controller.rb index 99089edd0..1309927f4 100644 --- a/app/controllers/support_controller.rb +++ b/app/controllers/support_controller.rb @@ -64,7 +64,7 @@ class SupportController < ApplicationController end def direct_message? - user_signed_in? && params[:type] == Helpscout::FormAdapter::TYPE_INSTRUCTION && dossier.present? + user_signed_in? && params[:type] == Helpscout::FormAdapter::TYPE_INSTRUCTION && dossier.present? && !dossier.brouillon? end def dossier From 8e88f2c27f4ed949b91ff98259307e2164662824 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 30 Aug 2018 14:08:26 +0100 Subject: [PATCH 7/9] Cleanup support controller tests --- spec/controllers/support_controller_spec.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/controllers/support_controller_spec.rb b/spec/controllers/support_controller_spec.rb index e47d1f002..e6335081b 100644 --- a/spec/controllers/support_controller_spec.rb +++ b/spec/controllers/support_controller_spec.rb @@ -9,6 +9,13 @@ describe SupportController, type: :controller do end let(:user) { create(:user) } + it 'should not have email field' do + get :index + + expect(response.status).to eq(200) + expect(response.body).not_to have_content("Email *") + end + describe "with dossier" do let(:user) { dossier.user } let(:dossier) { create(:dossier) } @@ -19,16 +26,9 @@ describe SupportController, type: :controller do expect(response.status).to eq(200) expect(response.body).to include("#{dossier.id}") end - - it 'should not have email field' do - get :index - - expect(response.status).to eq(200) - expect(response.body).not_to have_content("Email *") - end end - describe "with dossier" do + describe "with tag" do let(:tag) { 'yolo' } it 'should fill tags' do From 5d5a356adea3e82d6e7f5e5aff22a20314ce8c4a Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 30 Aug 2018 14:10:18 +0100 Subject: [PATCH 8/9] Cleanup contact_link helper --- app/helpers/application_helper.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index aadc34ce2..76d73157f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -55,12 +55,11 @@ module ApplicationHelper end def contact_link(title, options = {}) + tags, type, dossier_id = options.values_at(:tags, :type, :dossier_id) + options.except!(:tags, :type, :dossier_id) + if Flipflop.support_form? - params = { - tags: options[:tags], - type: options[:type], - dossier_id: options[:dossier_id] - }.compact + params = { tags: tags, type: type, dossier_id: dossier_id }.compact link_to title, contact_url(params), options else mail_to CONTACT_EMAIL, title, From 4866f9724a329809afc941912220ce7094927436 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 30 Aug 2018 15:12:40 +0100 Subject: [PATCH 9/9] Add support controller send_form tests --- spec/controllers/support_controller_spec.rb | 54 +++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/spec/controllers/support_controller_spec.rb b/spec/controllers/support_controller_spec.rb index e6335081b..f35a3e51c 100644 --- a/spec/controllers/support_controller_spec.rb +++ b/spec/controllers/support_controller_spec.rb @@ -49,6 +49,60 @@ describe SupportController, type: :controller do expect(response.body).to include(tags.join(',')) end end + + describe "send form" do + it 'should create conversation' do + expect(subject).not_to receive(:create_commentaire) + allow(subject).to receive(:create_conversation).and_return(true) + + post :create, params: { + subject: 'bonjour', + text: 'un message' + } + + expect(flash[:notice]).to match('Votre message a été envoyé.') + expect(response).to redirect_to root_path + end + + context "with dossier" do + let(:user) { dossier.user } + let(:dossier) { create(:dossier) } + + it 'should create conversation' do + expect(subject).not_to receive(:create_commentaire) + allow(subject).to receive(:create_conversation).and_return(true) + + post :create, params: { + dossier_id: dossier.id, + type: Helpscout::FormAdapter::TYPE_INSTRUCTION, + subject: 'bonjour', + text: 'un message' + } + + expect(flash[:notice]).to match('Votre message a été envoyé.') + expect(response).to redirect_to root_path + end + + context "en_construction" do + let(:dossier) { create(:dossier, :en_construction) } + + it 'should create commentaire' do + allow(subject).to receive(:create_commentaire).and_return(true) + expect(subject).not_to receive(:create_conversation) + + post :create, params: { + dossier_id: dossier.id, + type: Helpscout::FormAdapter::TYPE_INSTRUCTION, + subject: 'bonjour', + text: 'un message' + } + + expect(flash[:notice]).to match('Votre message a été envoyé sur la messagerie de votre dossier.') + expect(response).to redirect_to users_dossier_recapitulatif_path(dossier) + end + end + end + end end context 'signed out' do