Discard demarches from manager
This commit is contained in:
parent
89f1f70f0d
commit
876e05aed3
10 changed files with 54 additions and 28 deletions
|
@ -8,7 +8,7 @@ module Manager
|
|||
# this will be used to set the records shown on the `index` action.
|
||||
def scoped_resource
|
||||
if unfiltered_list?
|
||||
# Don't display deleted dossiers in the unfiltered list…
|
||||
# Don't display discarded demarches in the unfiltered list…
|
||||
Procedure.kept
|
||||
else
|
||||
# … but allow them to be searched and displayed.
|
||||
|
@ -22,10 +22,13 @@ module Manager
|
|||
redirect_to manager_procedure_path(procedure)
|
||||
end
|
||||
|
||||
def hide
|
||||
procedure.hide!
|
||||
flash[:notice] = "La démarche a bien été supprimée, en cas d'erreur contactez un développeur."
|
||||
redirect_to manager_procedures_path
|
||||
def discard
|
||||
procedure.discard_and_keep_track!(current_administration)
|
||||
|
||||
logger.info("La démarche #{procedure.id} est supprimée par #{current_administration.email}")
|
||||
flash[:notice] = "La démarche #{procedure.id} a été supprimée."
|
||||
|
||||
redirect_to manager_procedure_path(procedure)
|
||||
end
|
||||
|
||||
def add_administrateur
|
||||
|
@ -51,7 +54,7 @@ module Manager
|
|||
private
|
||||
|
||||
def procedure
|
||||
Procedure.find(params[:id])
|
||||
@procedure ||= Procedure.with_discarded.find(params[:id])
|
||||
end
|
||||
|
||||
def type_de_champ
|
||||
|
|
|
@ -4,10 +4,11 @@ class DeletedDossier < ApplicationRecord
|
|||
validates :dossier_id, uniqueness: true
|
||||
|
||||
enum reason: {
|
||||
user_request: 'user_request',
|
||||
manager_request: 'manager_request',
|
||||
user_removed: 'user_removed',
|
||||
expired: 'expired'
|
||||
user_request: 'user_request',
|
||||
manager_request: 'manager_request',
|
||||
user_removed: 'user_removed',
|
||||
procedure_removed: 'procedure_removed',
|
||||
expired: 'expired'
|
||||
}
|
||||
|
||||
def self.create_from_dossier(dossier, reason)
|
||||
|
|
|
@ -511,9 +511,16 @@ class Procedure < ApplicationRecord
|
|||
groupe_instructeurs.count > 1
|
||||
end
|
||||
|
||||
def hide!
|
||||
def can_be_deleted_by_manager?
|
||||
kept? && dossiers.state_instruction_commencee.empty?
|
||||
end
|
||||
|
||||
def discard_and_keep_track!(author)
|
||||
dossiers.each do |dossier|
|
||||
dossier.discard_and_keep_track!(author, :procedure_removed)
|
||||
end
|
||||
|
||||
discard!
|
||||
dossiers.discard_all
|
||||
end
|
||||
|
||||
def flipper_id
|
||||
|
|
|
@ -22,6 +22,9 @@ as well as a link to its edit page.
|
|||
<header class="main-content__header" role="banner">
|
||||
<h1 class="main-content__page-title">
|
||||
<%= content_for(:title) %>
|
||||
<% if procedure.discarded? %>
|
||||
(Supprimé)
|
||||
<% end %>
|
||||
</h1>
|
||||
|
||||
<div>
|
||||
|
@ -39,8 +42,8 @@ as well as a link to its edit page.
|
|||
<%= link_to 'whitelister', whitelist_manager_procedure_path(procedure), method: :post, class: 'button' %>
|
||||
<% end %>
|
||||
|
||||
<% if !procedure.discarded? %>
|
||||
<%= link_to 'supprimer la démarche', hide_manager_procedure_path(procedure), method: :post, class: 'button', data: { confirm: "Confirmez-vous la suppression de la démarche ?" } %>
|
||||
<% 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 ?" } %>
|
||||
<% end %>
|
||||
<div>
|
||||
|
||||
|
|
|
@ -6,6 +6,6 @@ fr:
|
|||
user_request: Demande d’usager
|
||||
manager_request: Demande d’administration
|
||||
user_removed: Suppression d’un compte usager
|
||||
procedure_removed: Suppression d’une démarche
|
||||
expired: Expiration
|
||||
unknown: Inconnue
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ Rails.application.routes.draw do
|
|||
resources :procedures, only: [:index, :show] do
|
||||
post 'whitelist', on: :member
|
||||
post 'draft', on: :member
|
||||
post 'hide', on: :member
|
||||
post 'discard', on: :member
|
||||
post 'add_administrateur', on: :member
|
||||
post 'change_piece_justificative_template', on: :member
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
describe Manager::ProceduresController, type: :controller do
|
||||
describe '#whitelist' do
|
||||
let(:administration) { create :administration }
|
||||
let!(:procedure) { create(:procedure) }
|
||||
let(:procedure) { create(:procedure) }
|
||||
|
||||
before do
|
||||
sign_in administration
|
||||
|
@ -16,7 +16,7 @@ describe Manager::ProceduresController, type: :controller do
|
|||
render_views
|
||||
|
||||
let(:administration) { create(:administration) }
|
||||
let!(:procedure) { create(:procedure, :with_repetition) }
|
||||
let(:procedure) { create(:procedure, :with_repetition) }
|
||||
|
||||
before do
|
||||
sign_in(administration)
|
||||
|
@ -26,6 +26,19 @@ describe Manager::ProceduresController, type: :controller do
|
|||
it { expect(response.body).to include('sub type de champ') }
|
||||
end
|
||||
|
||||
describe '#discard' do
|
||||
let(:administration) { create :administration }
|
||||
let(:procedure) { create(:procedure) }
|
||||
|
||||
before do
|
||||
sign_in administration
|
||||
post :discard, params: { id: procedure.id }
|
||||
procedure.reload
|
||||
end
|
||||
|
||||
it { expect(procedure.discarded?).to be_truthy }
|
||||
end
|
||||
|
||||
describe '#index' do
|
||||
render_views
|
||||
|
||||
|
|
|
@ -194,11 +194,7 @@ FactoryBot.define do
|
|||
end
|
||||
|
||||
trait :discarded do
|
||||
after(:build) do |procedure, _evaluator|
|
||||
procedure.path = generate(:published_path)
|
||||
procedure.publish!
|
||||
procedure.hide!
|
||||
end
|
||||
hidden_at { Time.zone.now }
|
||||
end
|
||||
|
||||
trait :whitelisted do
|
||||
|
|
|
@ -1226,6 +1226,8 @@ describe Dossier do
|
|||
end
|
||||
|
||||
describe 'discarded_brouillon_expired and discarded_en_construction_expired' do
|
||||
let(:administration) { create(:administration) }
|
||||
|
||||
before do
|
||||
create(:dossier)
|
||||
create(:dossier, :en_construction)
|
||||
|
@ -1236,8 +1238,8 @@ describe Dossier do
|
|||
create(:dossier).discard!
|
||||
create(:dossier, :en_construction).discard!
|
||||
|
||||
create(:dossier).procedure.hide!
|
||||
create(:dossier, :en_construction).procedure.hide!
|
||||
create(:dossier).procedure.discard_and_keep_track!(administration)
|
||||
create(:dossier, :en_construction).procedure.discard_and_keep_track!(administration)
|
||||
end
|
||||
Timecop.travel(1.week.ago) do
|
||||
create(:dossier).discard!
|
||||
|
|
|
@ -836,7 +836,8 @@ describe Procedure do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#hide!" do
|
||||
describe "#discard_and_keep_track!" do
|
||||
let(:administration) { create(:administration) }
|
||||
let(:procedure) { create(:procedure) }
|
||||
let!(:dossier) { create(:dossier, procedure: procedure) }
|
||||
let!(:dossier2) { create(:dossier, procedure: procedure) }
|
||||
|
@ -845,10 +846,10 @@ describe Procedure do
|
|||
it { expect(Dossier.count).to eq(2) }
|
||||
it { expect(Dossier.all).to include(dossier, dossier2) }
|
||||
|
||||
context "when hidding procedure" do
|
||||
context "when discarding procedure" do
|
||||
before do
|
||||
instructeur.followed_dossiers << dossier
|
||||
procedure.hide!
|
||||
procedure.discard_and_keep_track!(administration)
|
||||
instructeur.reload
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue