Merge pull request #3428 from betagouv/fix_3427_super_admin_soft_delete
[fix #3427] Administration can soft delete a dossier
This commit is contained in:
commit
6e07eb84c1
10 changed files with 79 additions and 6 deletions
|
@ -29,6 +29,17 @@ module Manager
|
||||||
redirect_to manager_dossier_path(dossier)
|
redirect_to manager_dossier_path(dossier)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def hide
|
||||||
|
dossier = Dossier.find(params[:id])
|
||||||
|
deleted_dossier = dossier.hide!(current_administration)
|
||||||
|
|
||||||
|
DossierMailer.notify_deletion_to_user(deleted_dossier, dossier.user.email).deliver_later
|
||||||
|
logger.info("Le dossier #{dossier.id} est supprimé par #{current_administration.email}")
|
||||||
|
flash[:notice] = "Le dossier #{dossier.id} est supprimé"
|
||||||
|
|
||||||
|
redirect_to manager_dossier_path(dossier)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def unfiltered_list?
|
def unfiltered_list?
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
class DeletedDossier < ApplicationRecord
|
class DeletedDossier < ApplicationRecord
|
||||||
belongs_to :procedure
|
belongs_to :procedure
|
||||||
|
|
||||||
|
def self.create_from_dossier(dossier)
|
||||||
|
DeletedDossier.create!(dossier_id: dossier.id, procedure: dossier.procedure, state: dossier.state, deleted_at: Time.now.utc)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -258,9 +258,8 @@ class Dossier < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_and_keep_track
|
def delete_and_keep_track
|
||||||
now = Time.zone.now
|
deleted_dossier = DeletedDossier.create_from_dossier(self)
|
||||||
deleted_dossier = DeletedDossier.create!(dossier_id: id, procedure: procedure, state: state, deleted_at: now)
|
update(hidden_at: deleted_dossier.deleted_at)
|
||||||
update(hidden_at: now)
|
|
||||||
|
|
||||||
if en_construction?
|
if en_construction?
|
||||||
administration_emails = followers_gestionnaires.present? ? followers_gestionnaires.pluck(:email) : [procedure.administrateur.email]
|
administration_emails = followers_gestionnaires.present? ? followers_gestionnaires.pluck(:email) : [procedure.administrateur.email]
|
||||||
|
@ -318,6 +317,13 @@ class Dossier < ApplicationRecord
|
||||||
log_dossier_operation(nil, :accepter, automatic_operation: true)
|
log_dossier_operation(nil, :accepter, automatic_operation: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def hide!(administration)
|
||||||
|
update(hidden_at: Time.zone.now)
|
||||||
|
|
||||||
|
log_administration_dossier_operation(administration, :supprimer)
|
||||||
|
DeletedDossier.create_from_dossier(self)
|
||||||
|
end
|
||||||
|
|
||||||
def refuser!(gestionnaire, motivation)
|
def refuser!(gestionnaire, motivation)
|
||||||
self.motivation = motivation
|
self.motivation = motivation
|
||||||
self.en_instruction_at ||= Time.zone.now
|
self.en_instruction_at ||= Time.zone.now
|
||||||
|
@ -356,6 +362,13 @@ class Dossier < ApplicationRecord
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def log_administration_dossier_operation(administration, operation)
|
||||||
|
dossier_operation_logs.create(
|
||||||
|
administration: administration,
|
||||||
|
operation: DossierOperationLog.operations.fetch(operation)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
def update_state_dates
|
def update_state_dates
|
||||||
if en_construction? && !self.en_construction_at
|
if en_construction? && !self.en_construction_at
|
||||||
self.en_construction_at = Time.zone.now
|
self.en_construction_at = Time.zone.now
|
||||||
|
|
|
@ -4,9 +4,11 @@ class DossierOperationLog < ApplicationRecord
|
||||||
repasser_en_construction: 'repasser_en_construction',
|
repasser_en_construction: 'repasser_en_construction',
|
||||||
accepter: 'accepter',
|
accepter: 'accepter',
|
||||||
refuser: 'refuser',
|
refuser: 'refuser',
|
||||||
classer_sans_suite: 'classer_sans_suite'
|
classer_sans_suite: 'classer_sans_suite',
|
||||||
|
supprimer: 'supprimer'
|
||||||
}
|
}
|
||||||
|
|
||||||
belongs_to :dossier
|
belongs_to :dossier
|
||||||
belongs_to :gestionnaire
|
belongs_to :gestionnaire
|
||||||
|
belongs_to :administration
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,7 +23,7 @@ as well as a link to its edit page.
|
||||||
<h1 class="main-content__page-title">
|
<h1 class="main-content__page-title">
|
||||||
<%= content_for(:title) %>
|
<%= content_for(:title) %>
|
||||||
<% if dossier.hidden_at %>
|
<% if dossier.hidden_at %>
|
||||||
(SUPPRIMÉ)
|
(Supprimé)
|
||||||
<% end %>
|
<% end %>
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
|
@ -31,6 +31,9 @@ as well as a link to its edit page.
|
||||||
<% if dossier.termine? %>
|
<% if dossier.termine? %>
|
||||||
<%= link_to 'Repasser en instruction', change_state_to_instruction_manager_dossier_path(dossier), method: :post, class: 'button', data: { confirm: "Repasser en instruction ?" } %>
|
<%= link_to 'Repasser en instruction', change_state_to_instruction_manager_dossier_path(dossier), method: :post, class: 'button', data: { confirm: "Repasser en instruction ?" } %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<% if dossier.hidden_at.nil? %>
|
||||||
|
<%= link_to 'Supprimer le dossier', hide_manager_dossier_path(dossier), method: :post, class: 'button', data: { confirm: "Confirmez vous la suppression du dossier ?" } %>
|
||||||
|
<% end %>
|
||||||
<div>
|
<div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
resources :dossiers, only: [:index, :show] do
|
resources :dossiers, only: [:index, :show] do
|
||||||
post 'change_state_to_instruction', on: :member
|
post 'change_state_to_instruction', on: :member
|
||||||
|
post 'hide', on: :member
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :administrateurs, only: [:index, :show, :new, :create] do
|
resources :administrateurs, only: [:index, :show, :new, :create] do
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddAdministrationColumnToLogDossierOperation < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_reference :dossier_operation_logs, :administration, foreign_key: true
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2019_01_10_163655) do
|
ActiveRecord::Schema.define(version: 2019_02_13_144145) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -219,6 +219,8 @@ ActiveRecord::Schema.define(version: 2019_01_10_163655) do
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.boolean "automatic_operation", default: false, null: false
|
t.boolean "automatic_operation", default: false, null: false
|
||||||
|
t.bigint "administration_id"
|
||||||
|
t.index ["administration_id"], name: "index_dossier_operation_logs_on_administration_id"
|
||||||
t.index ["dossier_id"], name: "index_dossier_operation_logs_on_dossier_id"
|
t.index ["dossier_id"], name: "index_dossier_operation_logs_on_dossier_id"
|
||||||
t.index ["gestionnaire_id"], name: "index_dossier_operation_logs_on_gestionnaire_id"
|
t.index ["gestionnaire_id"], name: "index_dossier_operation_logs_on_gestionnaire_id"
|
||||||
end
|
end
|
||||||
|
@ -597,6 +599,7 @@ ActiveRecord::Schema.define(version: 2019_01_10_163655) do
|
||||||
add_foreign_key "champs", "champs", column: "parent_id"
|
add_foreign_key "champs", "champs", column: "parent_id"
|
||||||
add_foreign_key "closed_mails", "procedures"
|
add_foreign_key "closed_mails", "procedures"
|
||||||
add_foreign_key "commentaires", "dossiers"
|
add_foreign_key "commentaires", "dossiers"
|
||||||
|
add_foreign_key "dossier_operation_logs", "administrations"
|
||||||
add_foreign_key "dossier_operation_logs", "dossiers"
|
add_foreign_key "dossier_operation_logs", "dossiers"
|
||||||
add_foreign_key "dossier_operation_logs", "gestionnaires"
|
add_foreign_key "dossier_operation_logs", "gestionnaires"
|
||||||
add_foreign_key "dossiers", "users"
|
add_foreign_key "dossiers", "users"
|
||||||
|
|
14
spec/controllers/manager/dossiers_controller_spec.rb
Normal file
14
spec/controllers/manager/dossiers_controller_spec.rb
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
describe Manager::DossiersController, type: :controller do
|
||||||
|
describe '#hide' do
|
||||||
|
let(:administration) { create :administration }
|
||||||
|
let!(:dossier) { create(:dossier) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
sign_in administration
|
||||||
|
post :hide, params: { id: dossier.id }
|
||||||
|
dossier.reload
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(dossier.hidden_at).not_to be_nil }
|
||||||
|
end
|
||||||
|
end
|
|
@ -892,4 +892,21 @@ describe Dossier do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#hide!' do
|
||||||
|
let(:dossier) { create(:dossier) }
|
||||||
|
let(:administration) { create(:administration) }
|
||||||
|
let(:last_operation) { dossier.dossier_operation_logs.last }
|
||||||
|
|
||||||
|
before do
|
||||||
|
Timecop.freeze
|
||||||
|
dossier.hide!(administration)
|
||||||
|
end
|
||||||
|
|
||||||
|
after { Timecop.return }
|
||||||
|
|
||||||
|
it { expect(dossier.hidden_at).to eq(Time.zone.now) }
|
||||||
|
it { expect(last_operation.operation).to eq('supprimer') }
|
||||||
|
it { expect(last_operation.administration).to eq(administration) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue