Merge pull request #7278 from betagouv/feat/7134

ETQ Administrateur, je veux restaurer une démarche supprimée
This commit is contained in:
Kara Diaby 2022-05-10 17:24:12 +02:00 committed by GitHub
commit 0f089067ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 83 additions and 13 deletions

View file

@ -9,9 +9,11 @@ module Administrateurs
@procedures_publiees = paginated_published_procedures
@procedures_draft = paginated_draft_procedures
@procedures_closed = paginated_closed_procedures
@procedures_deleted = paginated_deleted_procedures
@procedures_publiees_count = current_administrateur.procedures.publiees.count
@procedures_draft_count = current_administrateur.procedures.brouillons.count
@procedures_closed_count = current_administrateur.procedures.closes.count
@procedures_deleted_count = current_administrateur.procedures.with_discarded.discarded.count
@statut = params[:statut]
@statut.blank? ? @statut = 'publiees' : @statut = params[:statut]
end
@ -43,6 +45,16 @@ module Administrateurs
.order(created_at: :desc)
end
def paginated_deleted_procedures
current_administrateur
.procedures
.with_discarded
.discarded
.page(params[:page])
.per(ITEMS_PER_PAGE)
.order(created_at: :desc)
end
def apercu
@dossier = procedure_without_control.draft_revision.dossier_for_preview(current_user)
@tab = apercu_tab
@ -157,6 +169,13 @@ module Administrateurs
end
end
def restore
procedure = current_administrateur.procedures.with_discarded.discarded.find(params[:id])
procedure.restore_procedure
flash.notice = t('administrateurs.index.restored', procedure_id: procedure.id)
redirect_to admin_procedures_path
end
def monavis
end

View file

@ -696,6 +696,12 @@ class Procedure < ApplicationRecord
end
end
def restore_procedure
if discarded?
undiscard
end
end
def flipper_id
"Procedure;#{id}"
end

View file

@ -29,37 +29,47 @@
%span.badge.baseline= procedure.dossiers.state_not_brouillon.visible_by_administration.count
%div
= link_to admin_procedure_path(procedure), class: 'button mr-1 edit-procedure' do
%span.icon.edit
Modifier
- unless procedure.discarded?
= link_to admin_procedure_path(procedure), class: 'button mr-1 edit-procedure' do
%span.icon.edit
Modifier
.dropdown
.button.dropdown-button.procedures-actions-btn{ 'aria-expanded' => 'false', 'aria-controls' => 'actions-menu' }
Actions
#actions-menu.dropdown-content.fade-in-down
%ul.dropdown-items.pl-0
- if !procedure.close?
- if !procedure.close? && !procedure.discarded?
%li
= link_to sanitize_url(procedure.brouillon? ? commencer_test_url(path: procedure.path) : commencer_url(path: procedure.path)), target: :blank, rel: :noopener do
%span.icon.in-progress
.dropdown-description
%h4 Tester
%h4= t('administrateurs.dropdown_actions.to_test')
%li
= link_to admin_procedure_clone_path(procedure.id), class: 'clone-btn', data: { method: :put } do
%span.icon.new-folder
.dropdown-description
%h4 Cloner
- unless procedure.discarded?
%li
= link_to admin_procedure_clone_path(procedure.id), class: 'clone-btn', data: { method: :put } do
%span.icon.new-folder
.dropdown-description
%h4= t('administrateurs.dropdown_actions.to_clone')
- 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
%span.icon.archive
.dropdown-description
%h4 Clore
%h4= t('administrateurs.dropdown_actions.to_close')
- if procedure.can_be_deleted_by_administrateur?
- if procedure.can_be_deleted_by_administrateur? && !procedure.discarded?
%li
= link_to admin_procedure_path(procedure), method: :delete, data: { confirm: "Voulez-vous vraiment supprimer la démarche ? \nToute suppression est définitive et s'appliquera aux éventuels autres administrateurs de cette démarche !" } do
%span.icon.refuse
.dropdown-description
%h4 Supprimer
%h4= t('administrateurs.dropdown_actions.delete')
- if procedure.discarded?
%li
= link_to restore_admin_procedure_path(procedure), method: :put do
%span.icon.unarchive
.dropdown-description
%h4= t('administrateurs.dropdown_actions.restore')

View file

@ -8,6 +8,7 @@
= tab_item(t('pluralize.published', count: @procedures_publiees.count), admin_procedures_path(statut: 'publiees'), active: @statut == 'publiees', badge: number_with_html_delimiter(@procedures_publiees_count))
= tab_item('En test', admin_procedures_path(statut: 'brouillons'), active: @statut == 'brouillons', badge: number_with_html_delimiter(@procedures_draft_count))
= tab_item(t('pluralize.closed', count: @procedures_closed.count), admin_procedures_path(statut: 'archivees'), active: @statut == 'archivees', badge: number_with_html_delimiter(@procedures_closed_count))
= tab_item(t('pluralize.deleted', count: @procedures_deleted.count), admin_procedures_path(statut: 'supprimees'), active: @statut === 'supprimees', badge: number_with_html_delimiter(@procedures_deleted_count))
.container#procedures{ data: { item_count: @statut === "publiees" ? @procedures_publiees_count : @statut === "brouillons" ? @procedures_draft_count : @procedures_closed_count } }
- if @statut === "publiees"
@ -21,3 +22,7 @@
- if @statut === "archivees"
= render partial: "procedures_list", locals: { procedures: @procedures_closed }
= paginate @procedures_closed
- if @statut === "supprimees"
= render partial: "procedures_list", locals: { procedures: @procedures_deleted }
= paginate @procedures_deleted

View file

@ -434,6 +434,10 @@ en:
zero: Draft
one: Draft
other: Drafts
deleted:
zero: Deleted
one: Deleted
other: Deleted
users:
dossiers:
test_procedure: "This file is submitted on a test procedure. Any modification of the procedure by the administrator (addition of a field, publication of the procedure, etc.) will result in the removal of the file."

View file

@ -441,6 +441,10 @@ fr:
zero: Brouillon
one: Brouillon
other: Brouillons
deleted:
zero: Supprimée
one: Supprimée
other: Supprimées
users:
dossiers:
test_procedure: "Ce dossier est déposé sur une démarche en test. Toute modification de la démarche par ladministrateur (ajout d'un champ, publication de la démarche...) entraînera sa suppression."
@ -488,6 +492,14 @@ fr:
to_follow: à suivre
total: dossiers
administrateurs:
index:
restored: La démarche %{procedure_id} a été restaurée
dropdown_actions:
delete: Supprimer
restore: Restaurer
to_test: Tester
to_clone: Cloner
to_close: Clore
procedures:
show:
ready: "Validé"

View file

@ -418,6 +418,7 @@ Rails.application.routes.draw do
patch 'update_jeton'
put :allow_expert_review
put :experts_require_administrateur_invitation
put :restore
end
get :api_particulier, controller: 'jeton_particulier'

View file

@ -761,4 +761,17 @@ describe Administrateurs::ProceduresController, type: :controller do
it { expect(procedure.allow_expert_review).to be_truthy }
end
end
describe 'PUT #restore' do
let(:procedure) { create :procedure, :discarded, administrateur: admin }
context 'when the admin wants to restore a procedure' do
before do
put :restore, params: { id: procedure.id }
procedure.reload
end
it { expect(procedure.discarded?).to be_falsy }
end
end
end