From fa808c8010201bb2562fa71b16d01b57ca8729a2 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 18 Nov 2019 23:12:03 +0100 Subject: [PATCH 01/14] Make login w3c compatible again --- app/views/users/sessions/new.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/users/sessions/new.html.haml b/app/views/users/sessions/new.html.haml index 5cdd40be4..de0d29092 100644 --- a/app/views/users/sessions/new.html.haml +++ b/app/views/users/sessions/new.html.haml @@ -13,7 +13,7 @@ .auth-options %div - = f.check_box :remember_me, as: :boolean + = f.check_box :remember_me = f.label :remember_me, "Se souvenir de moi", class: 'remember-me' .text-right From 41445564b4866ae166eaa2e57fd4b7c6731d02e9 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 19 Nov 2019 09:06:55 +0100 Subject: [PATCH 02/14] Remove unused .header-help div --- app/views/layouts/_new_header.haml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/app/views/layouts/_new_header.haml b/app/views/layouts/_new_header.haml index 7eae51026..a880f875c 100644 --- a/app/views/layouts/_new_header.haml +++ b/app/views/layouts/_new_header.haml @@ -60,15 +60,14 @@ = link_to "Connexion", new_user_session_path, class: "button secondary" %li - .header-help - - if dossier.present? && nav_bar_profile == :user - = render partial: 'shared/help/help_dropdown_dossier', locals: { dossier: dossier } + - if dossier.present? && nav_bar_profile == :user + = render partial: 'shared/help/help_dropdown_dossier', locals: { dossier: dossier } - - elsif procedure.present? && (nav_bar_profile == :user || nav_bar_profile == :guest) - = render partial: 'shared/help/help_dropdown_procedure', locals: { procedure: procedure } + - elsif procedure.present? && (nav_bar_profile == :user || nav_bar_profile == :guest) + = render partial: 'shared/help/help_dropdown_procedure', locals: { procedure: procedure } - - elsif nav_bar_profile == :instructeur - = render partial: 'shared/help/help_dropdown_instructeur' + - elsif nav_bar_profile == :instructeur + = render partial: 'shared/help/help_dropdown_instructeur' - - else - = render partial: 'shared/help/help_button' + - else + = render partial: 'shared/help/help_button' From 0a3a47339ced03c63756d8e10632ca80816b04a5 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 19 Nov 2019 09:32:11 +0100 Subject: [PATCH 03/14] Add title to print button --- app/views/instructeurs/dossiers/_header_actions.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/instructeurs/dossiers/_header_actions.html.haml b/app/views/instructeurs/dossiers/_header_actions.html.haml index dc63ef8d0..63778f4af 100644 --- a/app/views/instructeurs/dossiers/_header_actions.html.haml +++ b/app/views/instructeurs/dossiers/_header_actions.html.haml @@ -1,5 +1,5 @@ %span.dropdown.print-menu-opener - %button.button.dropdown-button.icon-only + %button.button.dropdown-button.icon-only{ title: 'imprimer' } %span.icon.printer %ul.print-menu.dropdown-content %li From 9f6b9c50281760fbfeef8a8967dab199748d116d Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 19 Nov 2019 09:38:13 +0100 Subject: [PATCH 04/14] Make the help button accessible for keyboard --- app/views/shared/help/_help_dropdown_dossier.html.haml | 2 +- app/views/shared/help/_help_dropdown_instructeur.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/shared/help/_help_dropdown_dossier.html.haml b/app/views/shared/help/_help_dropdown_dossier.html.haml index 38b9af8bc..7155fedca 100644 --- a/app/views/shared/help/_help_dropdown_dossier.html.haml +++ b/app/views/shared/help/_help_dropdown_dossier.html.haml @@ -1,5 +1,5 @@ .dropdown.help-dropdown - .button.primary.dropdown-button Aide + %button.button.primary.dropdown-button Aide .dropdown-content.fade-in-down %ul.dropdown-items - title = dossier.brouillon? ? "Besoin d’aide pour remplir votre dossier ?" : "Une question sur votre dossier ?" diff --git a/app/views/shared/help/_help_dropdown_instructeur.html.haml b/app/views/shared/help/_help_dropdown_instructeur.html.haml index d5b2091b8..37581fb91 100644 --- a/app/views/shared/help/_help_dropdown_instructeur.html.haml +++ b/app/views/shared/help/_help_dropdown_instructeur.html.haml @@ -1,5 +1,5 @@ .dropdown.help-dropdown - .button.primary.dropdown-button Aide + %button.button.primary.dropdown-button Aide .dropdown-content.fade-in-down %ul.dropdown-items = render partial: 'shared/help/dropdown_items/faq_item' From 59432594a0234b844d0b3f33683e3cb6ef6f27bb Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 19 Nov 2019 09:42:16 +0100 Subject: [PATCH 05/14] Header: same outline for the search button --- app/assets/stylesheets/new_design/new_header.scss | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/assets/stylesheets/new_design/new_header.scss b/app/assets/stylesheets/new_design/new_header.scss index a7d33baa6..e22cffc73 100644 --- a/app/assets/stylesheets/new_design/new_header.scss +++ b/app/assets/stylesheets/new_design/new_header.scss @@ -150,6 +150,8 @@ $header-mobile-breakpoint: 550px; } button { + @extend %outline; + padding: 9px; border: none; background: none; From 279696451e3a7be26f89b90488362b005c1cbf77 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 19 Nov 2019 14:22:53 +0100 Subject: [PATCH 06/14] Fix html: Element div not allowed as child of element span --- app/assets/stylesheets/new_design/buttons.scss | 4 ++++ app/views/instructeurs/dossiers/_header_actions.html.haml | 2 +- app/views/instructeurs/dossiers/_state_button.html.haml | 2 +- app/views/invites/_dropdown.html.haml | 2 +- app/views/layouts/_account_dropdown.haml | 2 +- app/views/users/dossiers/_dossier_actions.html.haml | 2 +- 6 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/assets/stylesheets/new_design/buttons.scss b/app/assets/stylesheets/new_design/buttons.scss index e66e2c9fa..522c52d57 100644 --- a/app/assets/stylesheets/new_design/buttons.scss +++ b/app/assets/stylesheets/new_design/buttons.scss @@ -130,6 +130,10 @@ } } +.state-button { + display: inline-block; +} + .dropdown { display: inline-block; position: relative; diff --git a/app/views/instructeurs/dossiers/_header_actions.html.haml b/app/views/instructeurs/dossiers/_header_actions.html.haml index 63778f4af..57932439b 100644 --- a/app/views/instructeurs/dossiers/_header_actions.html.haml +++ b/app/views/instructeurs/dossiers/_header_actions.html.haml @@ -20,5 +20,5 @@ = render partial: "instructeurs/procedures/dossier_actions", locals: { procedure: dossier.procedure, dossier: dossier, dossier_is_followed: current_instructeur&.follow?(dossier) } -%span.state-button +.state-button = render partial: "state_button", locals: { dossier: dossier } diff --git a/app/views/instructeurs/dossiers/_state_button.html.haml b/app/views/instructeurs/dossiers/_state_button.html.haml index cbf3c2251..f30fd97d5 100644 --- a/app/views/instructeurs/dossiers/_state_button.html.haml +++ b/app/views/instructeurs/dossiers/_state_button.html.haml @@ -1,4 +1,4 @@ -%span.dropdown +.dropdown -# Dropdown button title %button.button.primary.dropdown-button{ class: button_or_label_class(dossier) } = dossier_display_state dossier diff --git a/app/views/invites/_dropdown.html.haml b/app/views/invites/_dropdown.html.haml index 7fda74dd5..91a451c9e 100644 --- a/app/views/invites/_dropdown.html.haml +++ b/app/views/invites/_dropdown.html.haml @@ -1,4 +1,4 @@ -%span.dropdown.invite-user-action +.dropdown.invite-user-action %button.button.dropdown-button %span.icon.person - if dossier.invites.count > 0 diff --git a/app/views/layouts/_account_dropdown.haml b/app/views/layouts/_account_dropdown.haml index 9f896c390..5cf464c75 100644 --- a/app/views/layouts/_account_dropdown.haml +++ b/app/views/layouts/_account_dropdown.haml @@ -1,4 +1,4 @@ -%span.dropdown.header-menu-opener +.dropdown.header-menu-opener %button.button.dropdown-button.header-menu-button = image_tag "icons/account-circle.svg", title: "Mon compte" %ul.header-menu.dropdown-content diff --git a/app/views/users/dossiers/_dossier_actions.html.haml b/app/views/users/dossiers/_dossier_actions.html.haml index bad0197ba..36d9c290d 100644 --- a/app/views/users/dossiers/_dossier_actions.html.haml +++ b/app/views/users/dossiers/_dossier_actions.html.haml @@ -4,7 +4,7 @@ - has_actions = has_delete_action || has_new_dossier_action - if has_actions - %span.dropdown.user-dossier-actions + .dropdown.user-dossier-actions %button.button.dropdown-button Actions .dropdown-content.fade-in-down From 0e6ffd0baa7e0a9bb48a072209b9b64d60487f41 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 19 Nov 2019 14:27:43 +0100 Subject: [PATCH 07/14] Fix table layout: tbody was wrapped in thead --- app/views/users/dossiers/index.html.haml | 40 ++++++++++++------------ 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/app/views/users/dossiers/index.html.haml b/app/views/users/dossiers/index.html.haml index 9475432c3..fc4f1d4ab 100644 --- a/app/views/users/dossiers/index.html.haml +++ b/app/views/users/dossiers/index.html.haml @@ -30,26 +30,26 @@ %th.status-col Statut %th.updated-at-col Mis à jour %th - %tbody - - @dossiers.each do |dossier| - %tr{ data: { 'dossier-id': dossier.id } } - %td.folder-col - = link_to(url_for_dossier(dossier), class: 'cell-link') do - %span.icon.folder - %td.number-col - = link_to(url_for_dossier(dossier), class: 'cell-link') do - = dossier.id - %td - = link_to(url_for_dossier(dossier), class: 'cell-link') do - = procedure_libelle(dossier.procedure) - %td.status-col - = link_to(url_for_dossier(dossier), class: 'cell-link') do - = render partial: 'shared/dossiers/status_badge', locals: { dossier: dossier } - %td.updated-at-col - = link_to(url_for_dossier(dossier), class: 'cell-link') do - = try_format_date(dossier.updated_at) - %td.action-col.action-col - = render partial: 'dossier_actions', locals: { dossier: dossier } + %tbody + - @dossiers.each do |dossier| + %tr{ data: { 'dossier-id': dossier.id } } + %td.folder-col + = link_to(url_for_dossier(dossier), class: 'cell-link') do + %span.icon.folder + %td.number-col + = link_to(url_for_dossier(dossier), class: 'cell-link') do + = dossier.id + %td + = link_to(url_for_dossier(dossier), class: 'cell-link') do + = procedure_libelle(dossier.procedure) + %td.status-col + = link_to(url_for_dossier(dossier), class: 'cell-link') do + = render partial: 'shared/dossiers/status_badge', locals: { dossier: dossier } + %td.updated-at-col + = link_to(url_for_dossier(dossier), class: 'cell-link') do + = try_format_date(dossier.updated_at) + %td.action-col.action-col + = render partial: 'dossier_actions', locals: { dossier: dossier } = paginate(@dossiers) - if current_user.feedbacks.empty? || current_user.feedbacks.last.created_at < 1.month.ago From 4a5059ed343f7c7c2a638ff1cff3fdac0defc724 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 19 Nov 2019 14:41:41 +0100 Subject: [PATCH 08/14] Add alt='' to decorative image https://www.w3.org/WAI/tutorials/images/decorative/ --- app/views/layouts/_account_dropdown.haml | 12 ++++++------ app/views/layouts/_new_header.haml | 4 ++-- .../shared/dossiers/messages/_message_icon.html.haml | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/views/layouts/_account_dropdown.haml b/app/views/layouts/_account_dropdown.haml index 5cf464c75..21ddf9518 100644 --- a/app/views/layouts/_account_dropdown.haml +++ b/app/views/layouts/_account_dropdown.haml @@ -8,30 +8,30 @@ - if administration_signed_in? %li = link_to manager_root_path, class: "menu-item menu-link" do - = image_tag "icons/super-admin.svg" + = image_tag "icons/super-admin.svg", alt: '' Passer en super-admin - if multiple_devise_profile_connect? - if user_signed_in? && nav_bar_profile != :user %li = link_to dossiers_path, class: "menu-item menu-link" do - = image_tag "icons/switch-profile.svg" + = image_tag "icons/switch-profile.svg", alt: '' Passer en usager - if instructeur_signed_in? && nav_bar_profile != :instructeur %li = link_to instructeur_procedures_path, class: "menu-item menu-link" do - = image_tag "icons/switch-profile.svg" + = image_tag "icons/switch-profile.svg", alt: '' Passer en instructeur - if administrateur_signed_in? && nav_bar_profile != :administrateur %li = link_to admin_procedures_path, class: "menu-item menu-link" do - = image_tag "icons/switch-profile.svg" + = image_tag "icons/switch-profile.svg", alt: '' Passer en administrateur %li = link_to profil_path, class: "menu-item menu-link" do - = image_tag "icons/switch-profile.svg" + = image_tag "icons/switch-profile.svg", alt: '' Voir mon profil %li = link_to destroy_user_session_path, method: :delete, class: "menu-item menu-link" do - = image_tag "icons/sign-out.svg" + = image_tag "icons/sign-out.svg", alt: '' Se déconnecter diff --git a/app/views/layouts/_new_header.haml b/app/views/layouts/_new_header.haml index a880f875c..23abde450 100644 --- a/app/views/layouts/_new_header.haml +++ b/app/views/layouts/_new_header.haml @@ -38,7 +38,7 @@ = form_tag instructeur_recherche_path, method: :get, class: "form" do = text_field_tag "q", "#{@search_terms if @search_terms.present?}", placeholder: "Rechercher un dossier" %button{ title: "Rechercher" } - = image_tag "icons/search-blue.svg" + = image_tag "icons/search-blue.svg", alt: '' - if nav_bar_profile == :user && user_signed_in? && current_user.dossiers.count > 2 %li @@ -46,7 +46,7 @@ = form_tag recherche_dossiers_path, method: :post, class: "form" do = text_field_tag :dossier_id, "", placeholder: "Numéro de dossier" %button{ title: "Rechercher" } - = image_tag "icons/search-blue.svg" + = image_tag "icons/search-blue.svg", alt: '' - if instructeur_signed_in? || user_signed_in? %li diff --git a/app/views/shared/dossiers/messages/_message_icon.html.haml b/app/views/shared/dossiers/messages/_message_icon.html.haml index 0d8eb2db1..849337641 100644 --- a/app/views/shared/dossiers/messages/_message_icon.html.haml +++ b/app/views/shared/dossiers/messages/_message_icon.html.haml @@ -1,7 +1,7 @@ - if commentaire.sent_by_system? - = image_tag('icons/mail.svg', class: 'person-icon') + = image_tag('icons/mail.svg', class: 'person-icon', alt: '') - elsif commentaire.sent_by?(connected_user) - = image_tag('icons/account-circle.svg', class: 'person-icon') + = image_tag('icons/account-circle.svg', class: 'person-icon', alt: '') - else - = image_tag('icons/blue-person.svg', class: 'person-icon') + = image_tag('icons/blue-person.svg', class: 'person-icon', alt: '') From 45ff1fd697936028b26e2439d5997ca111117b96 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 19 Nov 2019 14:52:07 +0100 Subject: [PATCH 09/14] Change span by div to fix Element p not allowed as child of element span --- app/views/shared/dossiers/_champ_row.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/shared/dossiers/_champ_row.html.haml b/app/views/shared/dossiers/_champ_row.html.haml index 8670a15c0..cfb9f6be9 100644 --- a/app/views/shared/dossiers/_champ_row.html.haml +++ b/app/views/shared/dossiers/_champ_row.html.haml @@ -16,7 +16,7 @@ %th.libelle{ class: repetition ? 'padded' : '' } = "#{c.libelle} :" %td.rich-text - %span{ class: highlight_if_unseen_class(demande_seen_at, c.updated_at) } + %div{ class: highlight_if_unseen_class(demande_seen_at, c.updated_at) } - case c.type_champ - when TypeDeChamp.type_champs.fetch(:carte) = render partial: "shared/champs/carte/show", locals: { champ: c } From 59d5cd7abc763b2e56d62d4250a9bc3695d563a7 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 19 Nov 2019 15:01:06 +0100 Subject: [PATCH 10/14] fix label > div by label > span --- app/views/shared/dossiers/messages/_form.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/shared/dossiers/messages/_form.html.haml b/app/views/shared/dossiers/messages/_form.html.haml index 87e88d33c..d7848e585 100644 --- a/app/views/shared/dossiers/messages/_form.html.haml +++ b/app/views/shared/dossiers/messages/_form.html.haml @@ -7,7 +7,7 @@ %div = f.file_field :piece_jointe, id: 'piece_jointe', direct_upload: true %label{ for: :piece_jointe } - .notice + %span.notice (taille max : 20 Mo) %div From b90cd9f28faafe1fc7d146a209121c36b41bd50a Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 20 Nov 2019 10:48:53 +0100 Subject: [PATCH 11/14] styles: fix hover on dropdown items MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit More specifically, fix items in the Help dropdown displaying a pointer cursor on the whole area – where only the links inside the item should have the hover cursor. Also, having a `cursor: pointer` rule applied only on hover state is difficult to debug: better to apply it always, and let the browser handle it. --- app/assets/stylesheets/new_design/buttons.scss | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/new_design/buttons.scss b/app/assets/stylesheets/new_design/buttons.scss index 522c52d57..ba5804564 100644 --- a/app/assets/stylesheets/new_design/buttons.scss +++ b/app/assets/stylesheets/new_design/buttons.scss @@ -217,10 +217,13 @@ } } - &.selected, - &:hover:not(.inactive) { - background: $light-grey; + &:not(.inactive) { cursor: pointer; + + &:hover, + &.selected { + background: $light-grey; + } } &.danger { From 03a7bc3d5adc5322b73bafc92b61000d8cd185ef Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 6 Nov 2019 14:03:08 +0000 Subject: [PATCH 12/14] dossiers: give the edit form an unique id --- app/views/shared/dossiers/_edit.html.haml | 8 ++++---- app/views/users/dossiers/brouillon.html.haml | 9 +++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/views/shared/dossiers/_edit.html.haml b/app/views/shared/dossiers/_edit.html.haml index c617a2450..318489100 100644 --- a/app/views/shared/dossiers/_edit.html.haml +++ b/app/views/shared/dossiers/_edit.html.haml @@ -2,13 +2,13 @@ = render partial: "shared/dossiers/submit_is_over", locals: { dossier: dossier } - if apercu - - form_options = { url: '', method: :get, html: { class: 'form', multipart: true } } + - form_options = { url: '', method: :get } - elsif dossier.brouillon? - - form_options = { url: brouillon_dossier_url(dossier), method: :patch, html: { class: 'form', multipart: true } } + - form_options = { url: brouillon_dossier_url(dossier), method: :patch } - else - - form_options = { url: modifier_dossier_url(dossier), method: :patch, html: { class: 'form', multipart: true } } + - form_options = { url: modifier_dossier_url(dossier), method: :patch } - = form_for dossier, form_options do |f| + = form_for dossier, form_options.merge({ html: { id: 'dossier-edit-form', class: 'form', multipart: true } }) do |f| .prologue %p.mandatory-explanation diff --git a/app/views/users/dossiers/brouillon.html.haml b/app/views/users/dossiers/brouillon.html.haml index 766708cef..580ecd2d7 100644 --- a/app/views/users/dossiers/brouillon.html.haml +++ b/app/views/users/dossiers/brouillon.html.haml @@ -3,8 +3,9 @@ - content_for :footer do = render partial: "users/procedure_footer", locals: { procedure: @dossier.procedure, dossier: @dossier } -.dossier-header.sub-header - .container - = render partial: "shared/dossiers/header", locals: { dossier: @dossier, apercu: false } +#dossier-draft + .dossier-header.sub-header + .container + = render partial: "shared/dossiers/header", locals: { dossier: @dossier, apercu: false } -= render partial: "shared/dossiers/edit", locals: { dossier: @dossier, apercu: false } + = render partial: "shared/dossiers/edit", locals: { dossier: @dossier, apercu: false } From 8b8a96abda61059af7b767190275b6252e58756b Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 6 Nov 2019 15:54:14 +0000 Subject: [PATCH 13/14] dossiers: save draft by default (instead of submitting) Make the default behavior of `update_brouillon` be to update the draft, instead of submitting the dossier. This makes all requests made to `update_brouillon` without specifying an extra `submit_draft` parameter to just save the draft. It will make autosaving the draft easier and safer. --- app/controllers/users/dossiers_controller.rb | 10 +++++----- app/views/shared/dossiers/_edit.html.haml | 3 ++- .../users/dossiers_controller_spec.rb | 18 +++++++++--------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 8c0ccad0f..78039da87 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -147,13 +147,13 @@ module Users flash.now.alert = errors render :brouillon else - if save_draft? - flash.now.notice = 'Votre brouillon a bien été sauvegardé.' - render :brouillon - else + if passage_en_construction? @dossier.en_construction! NotificationMailer.send_initiated_notification(@dossier).deliver_later redirect_to merci_dossier_path(@dossier) + else + flash.now.notice = 'Votre brouillon a bien été sauvegardé.' + render :brouillon end end end @@ -368,7 +368,7 @@ module Users end def save_draft? - dossier.brouillon? && params[:save_draft] + dossier.brouillon? && !params[:submit_draft] end end end diff --git a/app/views/shared/dossiers/_edit.html.haml b/app/views/shared/dossiers/_edit.html.haml index 318489100..7691145af 100644 --- a/app/views/shared/dossiers/_edit.html.haml +++ b/app/views/shared/dossiers/_edit.html.haml @@ -43,13 +43,14 @@ - if dossier.brouillon? = f.button 'Enregistrer le brouillon', formnovalidate: true, - name: :save_draft, value: true, class: 'button send secondary', data: { 'disable-with': "Envoi en cours…" } - if dossier.can_transition_to_en_construction? = f.button 'Déposer le dossier', + name: :submit_draft, + value: true, class: 'button send primary', disabled: !current_user.owns?(dossier), data: { 'disable-with': "Envoi en cours…" } diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index 4c60081bc..e4bf93fed 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -100,38 +100,38 @@ describe Users::DossiersController, type: :controller do let(:user) { create(:user) } let(:asked_dossier) { create(:dossier) } let(:ensure_authorized) { :forbid_invite_submission! } - let(:draft) { false } + let(:submit) { true } before do - @controller.params = @controller.params.merge(dossier_id: asked_dossier.id, save_draft: draft) + @controller.params = @controller.params.merge(dossier_id: asked_dossier.id, submit_draft: submit) allow(@controller).to receive(:current_user).and_return(user) allow(@controller).to receive(:redirect_to) end context 'when a user save their own draft' do let(:asked_dossier) { create(:dossier, user: user) } - let(:draft) { true } + let(:submit) { false } it_behaves_like 'does not redirect nor flash' end context 'when a user submit their own dossier' do let(:asked_dossier) { create(:dossier, user: user) } - let(:draft) { false } + let(:submit) { true } it_behaves_like 'does not redirect nor flash' end context 'when an invite save the draft for a dossier where they where invited' do before { create(:invite, dossier: asked_dossier, user: user) } - let(:draft) { true } + let(:submit) { false } it_behaves_like 'does not redirect nor flash' end context 'when an invite submit a dossier where they where invited' do before { create(:invite, dossier: asked_dossier, user: user) } - let(:draft) { false } + let(:submit) { true } it_behaves_like 'redirects and flashes' end @@ -394,7 +394,7 @@ describe Users::DossiersController, type: :controller do } } end - let(:payload) { submit_payload } + let(:payload) { submit_payload.merge(submit_draft: true) } subject do Timecop.freeze(now) do @@ -480,7 +480,7 @@ describe Users::DossiersController, type: :controller do it { expect(flash.alert).to eq(['Le champ l doit être rempli.']) } context 'and the user saves a draft' do - let(:payload) { submit_payload.merge(save_draft: true) } + let(:payload) { submit_payload.except(:submit_draft) } it { expect(response).to render_template(:brouillon) } it { expect(flash.notice).to eq('Votre brouillon a bien été sauvegardé.') } @@ -510,7 +510,7 @@ describe Users::DossiersController, type: :controller do let!(:invite) { create(:invite, dossier: dossier, user: user) } context 'and the invite saves a draft' do - let(:payload) { submit_payload.merge(save_draft: true) } + let(:payload) { submit_payload.except(:submit_draft) } before do first_champ.type_de_champ.update(mandatory: true, libelle: 'l') From 5f9a9d059efd53b17050f314504616f73124f981 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Thu, 7 Nov 2019 15:11:24 +0000 Subject: [PATCH 14/14] dossiers: render JSON if needed When receiving a request that expects JSON, return a simple '200'. This avoids the unecessary work of rendering all the HTML page (which ultimately will not be used). --- app/controllers/users/dossiers_controller.rb | 21 ++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 78039da87..575473a69 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -143,18 +143,19 @@ module Users errors = update_dossier_and_compute_errors - if errors.present? + if passage_en_construction? && errors.blank? + @dossier.en_construction! + NotificationMailer.send_initiated_notification(@dossier).deliver_later + return redirect_to(merci_dossier_path(@dossier)) + elsif errors.present? flash.now.alert = errors - render :brouillon else - if passage_en_construction? - @dossier.en_construction! - NotificationMailer.send_initiated_notification(@dossier).deliver_later - redirect_to merci_dossier_path(@dossier) - else - flash.now.notice = 'Votre brouillon a bien été sauvegardé.' - render :brouillon - end + flash.now.notice = 'Votre brouillon a bien été sauvegardé.' + end + + respond_to do |format| + format.html { render :brouillon } + format.json { head :ok } end end