From b1efe574036aadd59abfd63d924d04281c82bad5 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Wed, 16 Jan 2019 15:34:38 +0100 Subject: [PATCH] [Fix #2423] Allow Usager to delete brouillon from dossiers#index --- app/assets/images/icons/trash.svg | 1 + app/assets/stylesheets/new_design/buttons.scss | 4 ++++ .../stylesheets/new_design/dossiers_table.scss | 11 +++++++++-- app/assets/stylesheets/new_design/icons.scss | 4 ++++ .../new_gestionnaire/procedures/show.html.haml | 4 ++-- .../new_gestionnaire/recherche/index.html.haml | 4 ++-- app/views/new_user/dossiers/index.html.haml | 6 ++++++ spec/features/new_user/list_dossiers_spec.rb | 16 ++++++++++++++++ 8 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 app/assets/images/icons/trash.svg diff --git a/app/assets/images/icons/trash.svg b/app/assets/images/icons/trash.svg new file mode 100644 index 000000000..ea3e1ca31 --- /dev/null +++ b/app/assets/images/icons/trash.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/app/assets/stylesheets/new_design/buttons.scss b/app/assets/stylesheets/new_design/buttons.scss index d2c809c5b..5092221ff 100644 --- a/app/assets/stylesheets/new_design/buttons.scss +++ b/app/assets/stylesheets/new_design/buttons.scss @@ -60,6 +60,10 @@ color: #FFFFFF; border-color: $medium-red; background-color: $medium-red; + + > .icon { + filter: brightness(100); + } } } diff --git a/app/assets/stylesheets/new_design/dossiers_table.scss b/app/assets/stylesheets/new_design/dossiers_table.scss index b3cd92a4e..1f3468039 100644 --- a/app/assets/stylesheets/new_design/dossiers_table.scss +++ b/app/assets/stylesheets/new_design/dossiers_table.scss @@ -70,10 +70,17 @@ width: 110px; } - .follow-col { - width: 200px; + .action-col { text-align: right; padding-left: $default-spacer; padding-right: $default-spacer; } + + .follow-col { + width: 200px; + } + + .delete-col { + width: 150px; + } } diff --git a/app/assets/stylesheets/new_design/icons.scss b/app/assets/stylesheets/new_design/icons.scss index c2efb749a..fd3b8497c 100644 --- a/app/assets/stylesheets/new_design/icons.scss +++ b/app/assets/stylesheets/new_design/icons.scss @@ -105,4 +105,8 @@ &.meh { background-image: image-url("icons/meh-regular.svg"); } + + &.delete { + background-image: image-url("icons/trash.svg"); + } } diff --git a/app/views/new_gestionnaire/procedures/show.html.haml b/app/views/new_gestionnaire/procedures/show.html.haml index ca1a06a13..11f17fc4f 100644 --- a/app/views/new_gestionnaire/procedures/show.html.haml +++ b/app/views/new_gestionnaire/procedures/show.html.haml @@ -77,7 +77,7 @@ = render partial: "header_field", locals: { field: { "label" => "Statut", "table" => "self", "column" => "state" }, classname: "status-col" } - %th.follow-col + %th.action-col.follow-col %span.dropdown %button.button.dropdown-button Personnaliser @@ -112,7 +112,7 @@ %td.status-col = link_to(gestionnaire_dossier_path(@procedure, dossier), class: 'cell-link') do = render partial: 'shared/dossiers/status_badge', locals: { dossier: dossier } - %td.follow-col= render partial: 'dossier_actions', locals: { procedure: @procedure, dossier: dossier, dossier_is_followed: @followed_dossiers_id.include?(dossier.id) } + %td.action-col.follow-col= render partial: 'dossier_actions', locals: { procedure: @procedure, dossier: dossier, dossier_is_followed: @followed_dossiers_id.include?(dossier.id) } = paginate @dossiers - else %h2.empty-text Aucun dossier diff --git a/app/views/new_gestionnaire/recherche/index.html.haml b/app/views/new_gestionnaire/recherche/index.html.haml index 68e93156a..3af866a83 100644 --- a/app/views/new_gestionnaire/recherche/index.html.haml +++ b/app/views/new_gestionnaire/recherche/index.html.haml @@ -14,7 +14,7 @@ %th Démarche %th Demandeur %th.status-col Statut - %th.follow-col + %th.action-col.follow-col %tbody - @dossiers.each do |dossier| / # FIXME: here we have a n+1, we fire a request @@ -31,6 +31,6 @@ %td.status-col = link_to(dossier_linked_path(current_gestionnaire, dossier), class: 'cell-link') do = render partial: 'shared/dossiers/status_badge', locals: { dossier: dossier } - %td.follow-col= render partial: 'new_gestionnaire/procedures/dossier_actions', locals: { procedure: dossier.procedure, dossier: dossier, dossier_is_followed: @followed_dossiers_id.include?(dossier.id) } + %td.action-col.follow-col= render partial: 'new_gestionnaire/procedures/dossier_actions', locals: { procedure: dossier.procedure, dossier: dossier, dossier_is_followed: @followed_dossiers_id.include?(dossier.id) } - else %h2 Aucun dossier correspondant à votre recherche n'a été trouvé diff --git a/app/views/new_user/dossiers/index.html.haml b/app/views/new_user/dossiers/index.html.haml index 80f6a9aff..347961d81 100644 --- a/app/views/new_user/dossiers/index.html.haml +++ b/app/views/new_user/dossiers/index.html.haml @@ -31,6 +31,7 @@ %th Démarche %th.status-col Statut %th.updated-at-col Mis à jour + %th %tbody - @dossiers.each do |dossier| %tr @@ -49,6 +50,11 @@ %td.updated-at-col = link_to(url_for_dossier(dossier), class: 'cell-link') do = dossier.updated_at.strftime("%d/%m/%Y") + %td.action-col.delete-col + - if dossier.brouillon? + = link_to(ask_deletion_dossier_path(dossier), method: :post, class: 'button danger', data: { disable: true, confirm: "En continuant, vous allez supprimer ce dossier ainsi que les informations qu’il contient. Toute suppression entraine l’annulation de la démarche en cours.\n\nConfirmer la suppression ?" }) do + %span.icon.delete + Supprimer = paginate(@dossiers) - if current_user.feedbacks.empty? || current_user.feedbacks.last.created_at < 1.month.ago diff --git a/spec/features/new_user/list_dossiers_spec.rb b/spec/features/new_user/list_dossiers_spec.rb index 999aef5d6..3e36e97d8 100644 --- a/spec/features/new_user/list_dossiers_spec.rb +++ b/spec/features/new_user/list_dossiers_spec.rb @@ -5,6 +5,7 @@ describe 'user access to the list of his dossier' do let!(:last_updated_dossier) { create(:dossier, :with_entreprise, user: user, state: Dossier.states.fetch(:en_construction)) } let!(:dossier1) { create(:dossier, :with_entreprise, user: user, state: Dossier.states.fetch(:en_construction)) } let!(:dossier2) { create(:dossier, :with_entreprise) } + let!(:dossier_brouillon) { create(:dossier, :with_entreprise, user: user) } let!(:dossier_archived) { create(:dossier, :with_entreprise, user: user, state: Dossier.states.fetch(:en_construction)) } let(:dossiers_per_page) { 25 } @@ -43,6 +44,21 @@ describe 'user access to the list of his dossier' do expect(page).to have_content(dossier_archived.procedure.libelle) end + it 'should have link to only delete brouillon' do + expect(page).to have_link(nil, href: ask_deletion_dossier_path(dossier_brouillon)) + expect(page).not_to have_link(nil, href: ask_deletion_dossier_path(dossier1)) + end + + context 'when user clicks on delete brouillon list', js: true do + before do + find(:xpath, "//a[@href='#{ask_deletion_dossier_path(dossier_brouillon)}']").click + page.driver.browser.switch_to.alert.accept + end + scenario 'dossier is deleted' do + expect(page).not_to have_link("Supprimer", href: dossier_brouillon.procedure.libelle) + end + end + context 'when user clicks on a projet in list', js: true do before do page.click_on(dossier1.procedure.libelle)