diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index f004c76f7..2b08f6c84 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -44,14 +44,6 @@ class Admin::ProceduresController < AdminController @mine = @procedure.path_is_mine?(@path) end - def hide - procedure = current_administrateur.procedures.find(params[:id]) - procedure.hide! - - flash.notice = "Démarche supprimée, en cas d'erreur #{helpers.contact_link('contactez nous', tags: 'démarche supprimée')}" - redirect_to admin_procedures_draft_path - end - def destroy procedure = current_administrateur.procedures.find(params[:id]) diff --git a/app/helpers/procedure_helper.rb b/app/helpers/procedure_helper.rb index 7f4325c1b..2f28feed9 100644 --- a/app/helpers/procedure_helper.rb +++ b/app/helpers/procedure_helper.rb @@ -19,29 +19,4 @@ module ProcedureHelper action = procedure.archivee? ? :reopen : :publish t(action, scope: [:modal, :publish, key]) end - - def dossiers_deletion_warning(procedure) - dossiers_count = procedure.dossiers.state_not_brouillon.count - brouillons_count = procedure.dossiers.state_brouillon.count - formatted_dossiers_count = nil - formatted_brouillons_count = nil - - if dossiers_count > 0 - formatted_dossiers_count = pluralize(dossiers_count, "dossier", "dossiers") - end - - if brouillons_count > 0 - formatted_brouillons_count = pluralize(brouillons_count, "brouillon", "brouillons") - end - - formatted_combination = [formatted_dossiers_count, formatted_brouillons_count] - .compact - .join(" et ") - - [ - formatted_combination, - dossiers_count + brouillons_count == 1 ? "est rattaché" : "sont rattachés", - "à cette démarche, la suppression de cette démarche entrainera également leur suppression." - ].join(" ") - end end diff --git a/app/views/admin/procedures/show.html.haml b/app/views/admin/procedures/show.html.haml index 1d9f335b8..31e04f553 100644 --- a/app/views/admin/procedures/show.html.haml +++ b/app/views/admin/procedures/show.html.haml @@ -74,23 +74,3 @@ - else .alert.alert-info Cette démarche n’a pas encore de lien, et n’est donc pas accessible par le public. - - %br - - - if @procedure.publiee_ou_archivee? - %h3 Supprimer la démarche - .alert.alert-danger - %p - Attention : la suppression d’une démarche est définitive. - - - dossiers_count = @procedure.dossiers.count - - if dossiers_count > 0 - %p - = dossiers_deletion_warning(@procedure) - - %p.text-right - = link_to "J'ai compris, je supprime la démarche", - hide_admin_procedure_path(@procedure), - method: :post, - class: "btn btn-danger", - data: { confirm: "Voulez-vous supprimer la démarche ?", disable: true } diff --git a/config/routes.rb b/config/routes.rb index 1970e80a5..689d63479 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -197,7 +197,6 @@ Rails.application.routes.draw do end member do - post :hide delete :delete_logo delete :delete_deliberation delete :delete_notice diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index 75f3b3e4c..b0215e956 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -680,38 +680,6 @@ describe Admin::ProceduresController, type: :controller do end end - describe "POST #hide" do - subject { post :hide, params: { id: procedure.id } } - - context "when procedure is not owned by administrateur" do - let(:procedure) { create :procedure, administrateur: create(:administrateur) } - - it { expect{ subject }.to raise_error(ActiveRecord::RecordNotFound) } - end - - context "when procedure is owned by administrateur" do - let(:procedure) { create :procedure, :published, administrateur: admin } - - before do - subject - procedure.reload - end - - it { expect(procedure.hidden_at).not_to be_nil } - it { expect(procedure.procedure_path).to be_nil } - end - - context "when procedure has no path" do - let(:procedure) { create :procedure, administrateur: admin } - - it { expect{ subject }.not_to raise_error } - it do - subject - expect(procedure.reload.hidden_at).not_to be_nil - end - end - end - describe "DELETE #delete_deliberation" do context "with a demarche the admin owns" do let(:procedure) { create(:procedure, :with_deliberation, administrateur: admin) } diff --git a/spec/helpers/procedure_helper_spec.rb b/spec/helpers/procedure_helper_spec.rb deleted file mode 100644 index 7c09014ea..000000000 --- a/spec/helpers/procedure_helper_spec.rb +++ /dev/null @@ -1,51 +0,0 @@ -RSpec.describe ProcedureHelper, type: :helper do - let(:procedure) { create(:procedure) } - - describe '#dossiers_deletion_warning' do - subject { dossiers_deletion_warning(procedure) } - - context 'with 1 submitted dossier' do - before do - dossier_1 = create(:dossier, :en_construction, procedure: procedure) - end - - it { is_expected.to eq('1 dossier est rattaché à cette démarche, la suppression de cette démarche entrainera également leur suppression.') } - end - - context 'with 2 submitted dossiers' do - before do - dossier_1 = create(:dossier, :en_construction, procedure: procedure) - dossier_2 = create(:dossier, :en_instruction, procedure: procedure) - end - - it { is_expected.to eq('2 dossiers sont rattachés à cette démarche, la suppression de cette démarche entrainera également leur suppression.') } - end - - context 'with 1 brouillon dossier' do - before do - dossier_1 = create(:dossier, procedure: procedure) - end - - it { is_expected.to eq('1 brouillon est rattaché à cette démarche, la suppression de cette démarche entrainera également leur suppression.') } - end - - context 'with 2 brouillons dossiers' do - before do - dossier_1 = create(:dossier, procedure: procedure) - dossier_2 = create(:dossier, procedure: procedure) - end - - it { is_expected.to eq('2 brouillons sont rattachés à cette démarche, la suppression de cette démarche entrainera également leur suppression.') } - end - - context 'with 2 submitted dossiers and 1 brouillon dossier' do - before do - dossier_1 = create(:dossier, :en_instruction, procedure: procedure) - dossier_2 = create(:dossier, :en_instruction, procedure: procedure) - dossier_3 = create(:dossier, procedure: procedure) - end - - it { is_expected.to eq('2 dossiers et 1 brouillon sont rattachés à cette démarche, la suppression de cette démarche entrainera également leur suppression.') } - end - end -end