diff --git a/app/controllers/administrateurs/procedures_controller.rb b/app/controllers/administrateurs/procedures_controller.rb index 04ac60cad..5f74e4b4c 100644 --- a/app/controllers/administrateurs/procedures_controller.rb +++ b/app/controllers/administrateurs/procedures_controller.rb @@ -1,6 +1,6 @@ module Administrateurs class ProceduresController < AdministrateurController - before_action :retrieve_procedure, only: [:champs, :annotations, :modifications, :edit, :monavis, :update_monavis, :jeton, :update_jeton, :publication, :publish, :transfert, :allow_expert_review, :experts_require_administrateur_invitation] + before_action :retrieve_procedure, only: [:champs, :annotations, :modifications, :edit, :monavis, :update_monavis, :jeton, :update_jeton, :publication, :publish, :transfert, :close, :allow_expert_review, :experts_require_administrateur_invitation] before_action :procedure_revisable?, only: [:champs, :annotations, :modifications] ITEMS_PER_PAGE = 25 @@ -146,6 +146,12 @@ module Administrateurs def archive procedure = current_administrateur.procedures.find(params[:procedure_id]) + + if params[:new_procedure].present? + new_procedure = current_administrateur.procedures.find(params[:new_procedure]) + procedure.update!(replaced_by_procedure_id: new_procedure.id) + end + procedure.close! flash.notice = "Démarche close" @@ -243,6 +249,9 @@ module Administrateurs def transfert end + def close + end + def allow_expert_review @procedure.update!(allow_expert_review: !@procedure.allow_expert_review) flash.notice = @procedure.allow_expert_review? ? "Avis externes activés" : "Avis externes désactivés" diff --git a/app/views/administrateurs/procedures/_procedures_list.html.haml b/app/views/administrateurs/procedures/_procedures_list.html.haml index 4659ec856..74bfe37eb 100644 --- a/app/views/administrateurs/procedures/_procedures_list.html.haml +++ b/app/views/administrateurs/procedures/_procedures_list.html.haml @@ -54,7 +54,7 @@ - if procedure.publiee? %li - = link_to admin_procedure_archive_path(procedure_id: procedure.id), method: :put, data: { confirm: "Voulez-vous vraiment clore la démarche ? \nLes dossiers en cours pourront être instruits, mais aucun nouveau dossier ne pourra plus être déposé.", disable_with: "Archivage..."} do + = link_to admin_procedure_close_path(procedure_id: procedure.id) do %span.icon.archive .dropdown-description %h4= t('administrateurs.dropdown_actions.to_close') diff --git a/app/views/administrateurs/procedures/close.html.haml b/app/views/administrateurs/procedures/close.html.haml new file mode 100644 index 000000000..53b914e4b --- /dev/null +++ b/app/views/administrateurs/procedures/close.html.haml @@ -0,0 +1,13 @@ += render partial: 'administrateurs/breadcrumbs', + locals: { steps: [link_to('Démarches', admin_procedures_path), + "#{@procedure.libelle}", 'archiver'], + metadatas: ["Créée le #{@procedure.created_at.strftime('%d/%m/%Y')} - n° #{@procedure.id}", "#{@procedure.close? ? "Close le #{@procedure.closed_at.strftime('%d/%m/%Y')}" : @procedure.locked? ? "Publiée - #{procedure_lien(@procedure)}" : "Brouillon"}"] } + +.container + .card + %h2.card-title + = t('administrateurs.procedures.close.replacement_procedure_title') + = form_tag admin_procedure_archive_path(@procedure), method: :put, class: "form" do + - options_from_collection_for_select = current_administrateur.procedures.publiees.map { |p| ["#{p.libelle} (#{p.id})", p.id] }.to_h + = select_tag :new_procedure, options_for_select(options_from_collection_for_select), include_blank: true + = submit_tag t('administrateurs.procedures.close.actions.close_procedure'), { class: "button primary", id: 'publish', data: { confirm: "Voulez-vous vraiment clore la démarche ? \nLes dossiers en cours pourront être instruits, mais aucun nouveau dossier ne pourra plus être déposé.", disable_with: "Archivage..."} } diff --git a/config/locales/views/administrateurs/procedures/en.yml b/config/locales/views/administrateurs/procedures/en.yml new file mode 100644 index 000000000..bca508916 --- /dev/null +++ b/config/locales/views/administrateurs/procedures/en.yml @@ -0,0 +1,7 @@ +en: + administrateurs: + procedures: + close: + replacement_procedure_title: Is this procedure replaced by an existing one? If yes, please indicate the number of the new procedure + actions: + close_procedure: Close the procedure diff --git a/config/locales/views/administrateurs/procedures/fr.yml b/config/locales/views/administrateurs/procedures/fr.yml new file mode 100644 index 000000000..c6f261e5a --- /dev/null +++ b/config/locales/views/administrateurs/procedures/fr.yml @@ -0,0 +1,7 @@ +fr: + administrateurs: + procedures: + close: + replacement_procedure_title: Cette démarche est-elle remplacée par une existante ? Si oui, veuillez indiquer le n° de la nouvelle démarche + actions: + close_procedure: Clore la démarche diff --git a/config/routes.rb b/config/routes.rb index b1cee9b45..766a08fe3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -436,6 +436,7 @@ Rails.application.routes.draw do get 'publication' => 'procedures#publication', as: :publication put 'publish' => 'procedures#publish', as: :publish get 'transfert' => 'procedures#transfert', as: :transfert + get 'close' => 'procedures#close', as: :close post 'transfer' => 'procedures#transfer', as: :transfer resources :mail_templates, only: [:edit, :update] diff --git a/spec/controllers/administrateurs/procedures_controller_spec.rb b/spec/controllers/administrateurs/procedures_controller_spec.rb index a682c29d2..4caa89f0c 100644 --- a/spec/controllers/administrateurs/procedures_controller_spec.rb +++ b/spec/controllers/administrateurs/procedures_controller_spec.rb @@ -351,7 +351,7 @@ describe Administrateurs::ProceduresController, type: :controller do describe 'PUT #archive' do let(:procedure) { create(:procedure, :published, administrateur: admin, lien_site_web: lien_site_web) } - context 'when the admin is an owner of the procedure' do + context 'when the admin is an owner of the procedure without procedure replacement' do before do put :archive, params: { procedure_id: procedure.id } procedure.reload @@ -362,6 +362,28 @@ describe Administrateurs::ProceduresController, type: :controller do expect(response).to redirect_to :admin_procedures expect(flash[:notice]).to have_content 'Démarche close' end + + it 'does not have any replacement procedure' do + expect(procedure.replaced_by_procedure).to be_nil + end + end + + context 'when the admin is an owner of the procedure with procedure replacement' do + let(:new_procedure) { create(:procedure, :published, administrateur: admin, lien_site_web: lien_site_web) } + before do + put :archive, params: { procedure_id: procedure.id, new_procedure: new_procedure } + procedure.reload + end + + it 'archives the procedure' do + expect(procedure.close?).to be_truthy + expect(response).to redirect_to :admin_procedures + expect(flash[:notice]).to have_content 'Démarche close' + end + + it 'does have a replacement procedure' do + expect(procedure.replaced_by_procedure).to eq(new_procedure) + end end context 'when the admin is not an owner of the procedure' do