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