Undo discard dossiers and demarches from manager
This commit is contained in:
parent
876e05aed3
commit
da52ec30bd
11 changed files with 109 additions and 17 deletions
|
@ -30,6 +30,15 @@ module Manager
|
|||
redirect_to manager_dossier_path(dossier)
|
||||
end
|
||||
|
||||
def restore
|
||||
dossier = Dossier.with_discarded.find(params[:id])
|
||||
dossier.restore(current_administration)
|
||||
|
||||
flash[:notice] = "Le dossier #{dossier.id} a été restauré."
|
||||
|
||||
redirect_to manager_dossier_path(dossier)
|
||||
end
|
||||
|
||||
def repasser_en_instruction
|
||||
dossier = Dossier.find(params[:id])
|
||||
dossier.repasser_en_instruction(current_administration)
|
||||
|
|
|
@ -31,6 +31,14 @@ module Manager
|
|||
redirect_to manager_procedure_path(procedure)
|
||||
end
|
||||
|
||||
def restore
|
||||
procedure.restore(current_administration)
|
||||
|
||||
flash[:notice] = "La démarche #{procedure.id} a été restauré."
|
||||
|
||||
redirect_to manager_procedure_path(procedure)
|
||||
end
|
||||
|
||||
def add_administrateur
|
||||
administrateur = Administrateur.by_email(params[:email])
|
||||
if administrateur
|
||||
|
|
|
@ -20,4 +20,8 @@ class DeletedDossier < ApplicationRecord
|
|||
deleted_at: Time.zone.now
|
||||
)
|
||||
end
|
||||
|
||||
def procedure_removed?
|
||||
reason == self.class.reasons.fetch(:procedure_removed)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -487,6 +487,19 @@ class Dossier < ApplicationRecord
|
|||
discard!
|
||||
end
|
||||
|
||||
def restore(author, only_discarded_with_procedure = false)
|
||||
if discarded?
|
||||
deleted_dossier = DeletedDossier.find_by(dossier_id: id)
|
||||
|
||||
if !only_discarded_with_procedure || deleted_dossier&.procedure_removed?
|
||||
if undiscard && keep_track_on_deletion? && en_construction?
|
||||
deleted_dossier&.destroy
|
||||
log_dossier_operation(author, :restaurer, self)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def after_passer_en_instruction(instructeur)
|
||||
instructeur.follow(self)
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ class DossierOperationLog < ApplicationRecord
|
|||
refuser: 'refuser',
|
||||
classer_sans_suite: 'classer_sans_suite',
|
||||
supprimer: 'supprimer',
|
||||
restaurer: 'restaurer',
|
||||
modifier_annotation: 'modifier_annotation',
|
||||
demander_un_avis: 'demander_un_avis'
|
||||
}
|
||||
|
|
|
@ -523,6 +523,14 @@ class Procedure < ApplicationRecord
|
|||
discard!
|
||||
end
|
||||
|
||||
def restore(author)
|
||||
if discarded? && undiscard
|
||||
dossiers.with_discarded.discarded.find_each do |dossier|
|
||||
dossier.restore(author, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def flipper_id
|
||||
"Procedure;#{id}"
|
||||
end
|
||||
|
|
|
@ -33,6 +33,8 @@ as well as a link to its edit page.
|
|||
<% end %>
|
||||
<% if dossier.can_be_deleted_by_manager? %>
|
||||
<%= link_to 'Supprimer le dossier', discard_manager_dossier_path(dossier), method: :post, class: 'button', data: { confirm: "Confirmez vous la suppression du dossier ?" } %>
|
||||
<% elsif dossier.discarded? && !dossier.procedure.discarded? %>
|
||||
<%= link_to 'Restaurer le dossier', restore_manager_dossier_path(dossier), method: :post, class: 'button', data: { confirm: "Confirmez vous la restauration du dossier ?" } %>
|
||||
<% end %>
|
||||
</div>
|
||||
</header>
|
||||
|
|
|
@ -44,6 +44,8 @@ as well as a link to its edit page.
|
|||
|
||||
<% if procedure.can_be_deleted_by_manager? %>
|
||||
<%= link_to 'Supprimer la démarche', discard_manager_procedure_path(procedure), method: :post, class: 'button', data: { confirm: "Confirmez-vous la suppression de la démarche ?" } %>
|
||||
<% elsif procedure.discarded? %>
|
||||
<%= link_to 'Restaurer la démarche', restore_manager_procedure_path(procedure), method: :post, class: 'button', data: { confirm: "Confirmez-vous la restauration de la démarche ?" } %>
|
||||
<% end %>
|
||||
<div>
|
||||
|
||||
|
|
|
@ -10,12 +10,14 @@ Rails.application.routes.draw do
|
|||
post 'whitelist', on: :member
|
||||
post 'draft', on: :member
|
||||
post 'discard', on: :member
|
||||
post 'restore', on: :member
|
||||
post 'add_administrateur', on: :member
|
||||
post 'change_piece_justificative_template', on: :member
|
||||
end
|
||||
|
||||
resources :dossiers, only: [:index, :show] do
|
||||
post 'discard', on: :member
|
||||
post 'restore', on: :member
|
||||
post 'repasser_en_instruction', on: :member
|
||||
end
|
||||
|
||||
|
|
|
@ -1,23 +1,43 @@
|
|||
describe Manager::DossiersController, type: :controller do
|
||||
let(:administration) { create :administration }
|
||||
let(:deleted_dossier) { DeletedDossier.find_by(dossier_id: dossier) }
|
||||
let(:operations) { dossier.dossier_operation_logs.map(&:operation).map(&:to_sym) }
|
||||
|
||||
before { sign_in administration }
|
||||
|
||||
describe '#discard' do
|
||||
let(:administration) { create :administration }
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:dossier) { create(:dossier, :en_construction) }
|
||||
|
||||
before do
|
||||
sign_in administration
|
||||
post :discard, params: { id: dossier.id }
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
it { expect(dossier.discarded?).to be_truthy }
|
||||
it { expect(deleted_dossier).not_to be_nil }
|
||||
it { expect(deleted_dossier.reason).to eq("manager_request") }
|
||||
it { expect(operations).to eq([:supprimer]) }
|
||||
end
|
||||
|
||||
describe '#restore' do
|
||||
let(:dossier) { create(:dossier, :en_construction) }
|
||||
|
||||
before do
|
||||
dossier.discard_and_keep_track!(administration, :manager_request)
|
||||
|
||||
post :restore, params: { id: dossier.id }
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
it { expect(dossier.kept?).to be_truthy }
|
||||
it { expect(deleted_dossier).to be_nil }
|
||||
it { expect(operations).to eq([:supprimer, :restaurer]) }
|
||||
end
|
||||
|
||||
describe '#repasser_en_instruction' do
|
||||
let(:administration) { create :administration }
|
||||
let(:dossier) { create(:dossier, :accepte) }
|
||||
|
||||
before do
|
||||
sign_in administration
|
||||
post :repasser_en_instruction, params: { id: dossier.id }
|
||||
dossier.reload
|
||||
end
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
describe Manager::ProceduresController, type: :controller do
|
||||
let(:administration) { create :administration }
|
||||
|
||||
before { sign_in administration }
|
||||
|
||||
describe '#whitelist' do
|
||||
let(:administration) { create :administration }
|
||||
let(:procedure) { create(:procedure) }
|
||||
|
||||
before do
|
||||
sign_in administration
|
||||
post :whitelist, params: { id: procedure.id }
|
||||
procedure.reload
|
||||
end
|
||||
|
||||
it { expect(procedure.whitelisted_at).not_to be_nil }
|
||||
it { expect(procedure.whitelisted?).to be_truthy }
|
||||
end
|
||||
|
||||
describe '#show' do
|
||||
render_views
|
||||
|
||||
let(:administration) { create(:administration) }
|
||||
let(:procedure) { create(:procedure, :with_repetition) }
|
||||
|
||||
before do
|
||||
sign_in(administration)
|
||||
get :show, params: { id: procedure.id }
|
||||
end
|
||||
|
||||
|
@ -27,27 +27,50 @@ describe Manager::ProceduresController, type: :controller do
|
|||
end
|
||||
|
||||
describe '#discard' do
|
||||
let(:administration) { create :administration }
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:dossier) { create(:dossier, :en_construction) }
|
||||
let(:procedure) { dossier.procedure }
|
||||
let(:deleted_dossier) { DeletedDossier.find_by(dossier_id: dossier.id) }
|
||||
let(:operations) { dossier.dossier_operation_logs.map(&:operation).map(&:to_sym) }
|
||||
|
||||
before do
|
||||
sign_in administration
|
||||
post :discard, params: { id: procedure.id }
|
||||
procedure.reload
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
it { expect(procedure.discarded?).to be_truthy }
|
||||
it { expect(dossier.discarded?).to be_truthy }
|
||||
it { expect(deleted_dossier).not_to be_nil }
|
||||
it { expect(deleted_dossier.reason).to eq("procedure_removed") }
|
||||
it { expect(operations).to eq([:supprimer]) }
|
||||
end
|
||||
|
||||
describe '#restore' do
|
||||
let(:dossier) { create(:dossier, :en_construction) }
|
||||
let(:procedure) { dossier.procedure }
|
||||
let(:deleted_dossier) { DeletedDossier.find_by(dossier_id: dossier.id) }
|
||||
let(:operations) { dossier.dossier_operation_logs.map(&:operation).map(&:to_sym) }
|
||||
|
||||
before do
|
||||
procedure.discard_and_keep_track!(administration)
|
||||
|
||||
post :restore, params: { id: procedure.id }
|
||||
procedure.reload
|
||||
end
|
||||
|
||||
it { expect(procedure.kept?).to be_truthy }
|
||||
it { expect(dossier.kept?).to be_truthy }
|
||||
it { expect(deleted_dossier).to be_nil }
|
||||
it { expect(operations).to eq([:supprimer, :restaurer]) }
|
||||
end
|
||||
|
||||
describe '#index' do
|
||||
render_views
|
||||
|
||||
let(:administration) { create(:administration) }
|
||||
let!(:dossier) { create(:dossier) }
|
||||
|
||||
context 'sort by dossiers' do
|
||||
let!(:dossier) { create(:dossier) }
|
||||
|
||||
before do
|
||||
sign_in(administration)
|
||||
get :index, params: { procedure: { direction: 'asc', order: 'dossiers' } }
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue