From b516cbc17963a3e2e704c8196213f3e079e73c32 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 13 Mar 2020 15:32:30 +0100 Subject: [PATCH] =?UTF-8?q?Enable=20republish=20on=20d=C3=A9marches=20d?= =?UTF-8?q?=C3=A9publi=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/procedure.rb | 6 +- app/views/admin/procedures/show.html.haml | 16 +-- spec/features/admin/procedure_publish_spec.rb | 97 +++++++++++++++++++ .../admin/procedures/show.html.haml_spec.rb | 16 +-- 4 files changed, 118 insertions(+), 17 deletions(-) create mode 100644 spec/features/admin/procedure_publish_spec.rb diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 60b3c78d6..f4a83c7d2 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -195,7 +195,11 @@ class Procedure < ApplicationRecord def path_available?(administrateur, path) procedure = other_procedure_with_path(path) - procedure.blank? || administrateur.owns?(procedure) + procedure.blank? || (administrateur.owns?(procedure) && canonical_procedure_child?(procedure)) + end + + def canonical_procedure_child?(procedure) + !canonical_procedure || canonical_procedure == procedure || canonical_procedure == procedure.canonical_procedure end def locked? diff --git a/app/views/admin/procedures/show.html.haml b/app/views/admin/procedures/show.html.haml index 622022ba3..4f656adbb 100644 --- a/app/views/admin/procedures/show.html.haml +++ b/app/views/admin/procedures/show.html.haml @@ -1,9 +1,9 @@ = render partial: 'admin/closed_mail_template_attestation_inconsistency_alert' .row.white-back - #procedure_show - = render 'modal_publish', procedure: @procedure, administrateur: @current_administrateur - = render partial: '/admin/procedures/modal_transfer' + = render 'modal_publish', procedure: @procedure, administrateur: @current_administrateur + = render 'modal_transfer' + #procedure_show - if @procedure.brouillon? - if @procedure.missing_steps.present? - missing_elements = [] @@ -12,20 +12,20 @@ - if @procedure.service.nil? - missing_elements << 'un service' - message = "Affectez #{missing_elements.join(' et ')} à votre démarche." - %a.action_button.btn.btn-success#disabled-publish-procedure{ data: { toggle: :tooltip, placement: :bottom }, style: 'float: right; margin-top: 10px;', disabled: true, title: message } + %button.action_button.btn.btn-success#disabled-publish-procedure{ data: { toggle: :tooltip, placement: :bottom }, style: 'float: right; margin-top: 10px;', disabled: true, title: message } %i.fa.fa-eraser Publier - else - %a.btn.btn-success#publish-procedure{ data: { target: '#publish-modal', toggle: :modal }, type: 'button', style: 'float: right; margin-top: 10px;' } + %button.btn.btn-success#publish-procedure{ data: { target: '#publish-modal', toggle: :modal }, type: 'button', style: 'float: right; margin-top: 10px;' } %i.fa.fa-eraser Publier - %a.btn.btn-default#transfer-procedure{ data: { target: '#transfer-modal', toggle: :modal }, type: 'button', style: 'float: right; margin-top: 10px; margin-right: 10px;' } + %button.btn.btn-default#transfer-procedure{ data: { target: '#transfer-modal', toggle: :modal }, type: 'button', style: 'float: right; margin-top: 10px; margin-right: 10px;' } %i.fa.fa-exchange Envoyer une copie - - if @procedure.close? - %a.btn.btn-default#reopen-procedure{ data: { target: '#publish-modal', toggle: :modal }, type: 'button', style: 'float: right; margin-top: 10px; margin-right: 10px;' } + - if @procedure.close? || @procedure.depubliee? + %button.btn.btn-default#reopen-procedure{ data: { target: '#publish-modal', toggle: :modal }, type: 'button', style: 'float: right; margin-top: 10px; margin-right: 10px;' } %i.fa.fa-rocket Réactiver diff --git a/spec/features/admin/procedure_publish_spec.rb b/spec/features/admin/procedure_publish_spec.rb new file mode 100644 index 000000000..b3327ae29 --- /dev/null +++ b/spec/features/admin/procedure_publish_spec.rb @@ -0,0 +1,97 @@ +require 'features/admin/procedure_spec_helper' + +feature 'Publication de démarches', js: true do + include ProcedureSpecHelper + + let(:administrateur) { create(:administrateur) } + let(:instructeurs) { [administrateur.user.instructeur] } + let!(:procedure) do + create(:procedure_with_dossiers, + :with_path, + :with_type_de_champ, + :with_service, + instructeurs: instructeurs, + administrateur: administrateur) + end + + before do + login_as administrateur.user, scope: :user + end + + context 'lorsqu’une démarche est en test' do + scenario 'un administrateur peut la publier' do + visit admin_procedures_draft_path + click_on procedure.libelle + within "#procedure_show" do + click_on "Publier" + end + + within '#publish-modal' do + expect(find_field('procedure_path').value).to eq procedure.path + fill_in 'lien_site_web', with: 'http://some.website' + click_on 'publish' + end + + expect(page).to have_text('Démarche publiée') + expect(page).to have_selector('.procedure-lien') + end + end + + context 'lorsqu’une démarche est close' do + let!(:procedure) do + create(:procedure_with_dossiers, + :closed, + :with_path, + :with_type_de_champ, + :with_service, + instructeurs: instructeurs, + administrateur: administrateur) + end + + scenario 'un administrateur peut la publier' do + visit admin_procedures_archived_path + click_on procedure.libelle + within "#procedure_show" do + click_on "Réactiver" + end + + within '#publish-modal' do + expect(find_field('procedure_path').value).to eq procedure.path + fill_in 'lien_site_web', with: 'http://some.website' + click_on 'publish' + end + + expect(page).to have_text('Démarche publiée') + expect(page).to have_selector('.procedure-lien') + end + end + + context 'lorsqu’une démarche est dépublié' do + let!(:procedure) do + create(:procedure_with_dossiers, + :unpublished, + :with_path, + :with_type_de_champ, + :with_service, + instructeurs: instructeurs, + administrateur: administrateur) + end + + scenario 'un administrateur peut la publier' do + visit admin_procedures_archived_path + click_on procedure.libelle + within "#procedure_show" do + click_on "Réactiver" + end + + within '#publish-modal' do + expect(find_field('procedure_path').value).to eq procedure.path + fill_in 'lien_site_web', with: 'http://some.website' + click_on 'publish' + end + + expect(page).to have_text('Démarche publiée') + expect(page).to have_selector('.procedure-lien') + end + end +end diff --git a/spec/views/admin/procedures/show.html.haml_spec.rb b/spec/views/admin/procedures/show.html.haml_spec.rb index 15d179de5..7fdad4628 100644 --- a/spec/views/admin/procedures/show.html.haml_spec.rb +++ b/spec/views/admin/procedures/show.html.haml_spec.rb @@ -14,9 +14,9 @@ describe 'admin/procedures/show.html.haml', type: :view do end describe 'publish button is not visible' do - it { expect(rendered).not_to have_css('a#publish-procedure') } + it { expect(rendered).not_to have_css('button#publish-procedure') } it { expect(rendered).not_to have_css('button#archive-procedure') } - it { expect(rendered).not_to have_css('a#reopen-procedure') } + it { expect(rendered).not_to have_css('button#reopen-procedure') } end end @@ -27,9 +27,9 @@ describe 'admin/procedures/show.html.haml', type: :view do end describe 'publish button is visible' do - it { expect(rendered).to have_css('a#publish-procedure') } + it { expect(rendered).to have_css('button#publish-procedure') } it { expect(rendered).not_to have_css('button#archive-procedure') } - it { expect(rendered).not_to have_css('a#reopen-procedure') } + it { expect(rendered).not_to have_css('button#reopen-procedure') } end describe 'procedure path is not customized' do @@ -46,9 +46,9 @@ describe 'admin/procedures/show.html.haml', type: :view do end describe 'archive button is visible', js: true do - it { expect(rendered).not_to have_css('a#publish-procedure') } + it { expect(rendered).not_to have_css('button#publish-procedure') } it { expect(rendered).to have_css('button#archive-procedure') } - it { expect(rendered).not_to have_css('a#reopen-procedure') } + it { expect(rendered).not_to have_css('button#reopen-procedure') } end describe 'procedure link is present' do @@ -65,9 +65,9 @@ describe 'admin/procedures/show.html.haml', type: :view do end describe 'Re-enable button is visible' do - it { expect(rendered).not_to have_css('a#publish-procedure') } + it { expect(rendered).not_to have_css('button#publish-procedure') } it { expect(rendered).not_to have_css('button#archive-procedure') } - it { expect(rendered).to have_css('a#reopen-procedure') } + it { expect(rendered).to have_css('button#reopen-procedure') } end describe 'procedure link is present' do