Merge pull request #7417 from betagouv/feat/7414

ETQ Admin, lorsque j'archive une démarche, je souhaite indiquer s'il existe une nouvelle démarche
This commit is contained in:
Kara Diaby 2022-05-30 15:00:01 +02:00 committed by GitHub
commit d140d8c263
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 62 additions and 3 deletions

View file

@ -1,6 +1,6 @@
module Administrateurs module Administrateurs
class ProceduresController < AdministrateurController 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] before_action :procedure_revisable?, only: [:champs, :annotations, :modifications]
ITEMS_PER_PAGE = 25 ITEMS_PER_PAGE = 25
@ -146,6 +146,12 @@ module Administrateurs
def archive def archive
procedure = current_administrateur.procedures.find(params[:procedure_id]) 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! procedure.close!
flash.notice = "Démarche close" flash.notice = "Démarche close"
@ -243,6 +249,9 @@ module Administrateurs
def transfert def transfert
end end
def close
end
def allow_expert_review def allow_expert_review
@procedure.update!(allow_expert_review: !@procedure.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" flash.notice = @procedure.allow_expert_review? ? "Avis externes activés" : "Avis externes désactivés"

View file

@ -54,7 +54,7 @@
- if procedure.publiee? - if procedure.publiee?
%li %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 %span.icon.archive
.dropdown-description .dropdown-description
%h4= t('administrateurs.dropdown_actions.to_close') %h4= t('administrateurs.dropdown_actions.to_close')

View file

@ -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..."} }

View file

@ -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

View file

@ -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

View file

@ -436,6 +436,7 @@ Rails.application.routes.draw do
get 'publication' => 'procedures#publication', as: :publication get 'publication' => 'procedures#publication', as: :publication
put 'publish' => 'procedures#publish', as: :publish put 'publish' => 'procedures#publish', as: :publish
get 'transfert' => 'procedures#transfert', as: :transfert get 'transfert' => 'procedures#transfert', as: :transfert
get 'close' => 'procedures#close', as: :close
post 'transfer' => 'procedures#transfer', as: :transfer post 'transfer' => 'procedures#transfer', as: :transfer
resources :mail_templates, only: [:edit, :update] resources :mail_templates, only: [:edit, :update]

View file

@ -351,7 +351,7 @@ describe Administrateurs::ProceduresController, type: :controller do
describe 'PUT #archive' do describe 'PUT #archive' do
let(:procedure) { create(:procedure, :published, administrateur: admin, lien_site_web: lien_site_web) } 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 before do
put :archive, params: { procedure_id: procedure.id } put :archive, params: { procedure_id: procedure.id }
procedure.reload procedure.reload
@ -362,6 +362,28 @@ describe Administrateurs::ProceduresController, type: :controller do
expect(response).to redirect_to :admin_procedures expect(response).to redirect_to :admin_procedures
expect(flash[:notice]).to have_content 'Démarche close' expect(flash[:notice]).to have_content 'Démarche close'
end 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 end
context 'when the admin is not an owner of the procedure' do context 'when the admin is not an owner of the procedure' do