amelioration(user.expiration): ajoute une raison specifique a la suppression d'un dossier : user_expired
This commit is contained in:
parent
bfe27b5eb7
commit
520863d814
6 changed files with 16 additions and 15 deletions
|
@ -56,7 +56,7 @@ module Manager
|
|||
if !user.can_be_deleted?
|
||||
fail "Impossible de supprimer cet utilisateur. Il a des dossiers en instruction ou il est administrateur."
|
||||
end
|
||||
user.delete_and_keep_track_dossiers_also_delete_user(current_super_admin)
|
||||
user.delete_and_keep_track_dossiers_also_delete_user(current_super_admin, reason: :user_removed)
|
||||
|
||||
logger.info("L'utilisateur #{user.id} est supprimé par #{current_super_admin.id}")
|
||||
flash[:notice] = "L'utilisateur #{user.id} est supprimé"
|
||||
|
|
|
@ -12,7 +12,8 @@ class DeletedDossier < ApplicationRecord
|
|||
user_removed: 'user_removed',
|
||||
procedure_removed: 'procedure_removed',
|
||||
expired: 'expired',
|
||||
instructeur_request: 'instructeur_request'
|
||||
instructeur_request: 'instructeur_request',
|
||||
user_expired: 'user_expired'
|
||||
}
|
||||
|
||||
enum state: {
|
||||
|
|
|
@ -176,7 +176,7 @@ class User < ApplicationRecord
|
|||
!administrateur? && !instructeur? && !expert?
|
||||
end
|
||||
|
||||
def delete_and_keep_track_dossiers_also_delete_user(super_admin)
|
||||
def delete_and_keep_track_dossiers_also_delete_user(super_admin, reason:)
|
||||
if !can_be_deleted?
|
||||
raise "Cannot delete this user because they are also instructeur, expert or administrateur"
|
||||
end
|
||||
|
@ -185,29 +185,29 @@ class User < ApplicationRecord
|
|||
# delete invites
|
||||
Invite.where(dossier: dossiers).destroy_all
|
||||
|
||||
delete_and_keep_track_dossiers(super_admin)
|
||||
delete_and_keep_track_dossiers(super_admin, reason: :user_removed)
|
||||
|
||||
destroy!
|
||||
end
|
||||
end
|
||||
|
||||
def delete_and_keep_track_dossiers(super_admin)
|
||||
def delete_and_keep_track_dossiers(super_admin, reason:)
|
||||
transaction do
|
||||
# delete dossiers brouillon
|
||||
dossiers.state_brouillon.each do |dossier|
|
||||
dossier.hide_and_keep_track!(dossier.user, :user_removed)
|
||||
dossier.hide_and_keep_track!(dossier.user, reason)
|
||||
end
|
||||
dossiers.state_brouillon.find_each(&:purge_discarded)
|
||||
|
||||
# delete dossiers en_construction
|
||||
dossiers.state_en_construction.each do |dossier|
|
||||
dossier.hide_and_keep_track!(dossier.user, :user_removed)
|
||||
dossier.hide_and_keep_track!(dossier.user, reason)
|
||||
end
|
||||
dossiers.state_en_construction.find_each(&:purge_discarded)
|
||||
|
||||
# delete dossiers terminé
|
||||
dossiers.state_termine.each do |dossier|
|
||||
dossier.hide_and_keep_track!(dossier.user, :user_removed)
|
||||
dossier.hide_and_keep_track!(dossier.user, reason)
|
||||
end
|
||||
dossiers.update_all(deleted_user_email_never_send: email, user_id: nil, dossier_transfer_id: nil)
|
||||
end
|
||||
|
|
|
@ -23,7 +23,7 @@ class Expired::UsersDeletionService < Expired::MailRateLimiter
|
|||
def delete_notified_users(users)
|
||||
only_notified(users).find_each do |user|
|
||||
begin
|
||||
user.delete_and_keep_track_dossiers_also_delete_user(nil)
|
||||
user.delete_and_keep_track_dossiers_also_delete_user(nil, reason: :user_expired)
|
||||
rescue => e
|
||||
Sentry.capture_exception(e, extra: { user_id: user.id })
|
||||
end
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace :support do
|
|||
user = User.find_by!(email: user_email)
|
||||
administration = Administration.find_by!(email: administration_email)
|
||||
|
||||
user.delete_and_keep_track_dossiers_also_delete_user(administration)
|
||||
user.delete_and_keep_track_dossiers_also_delete_user(administration, reason: :user_removed)
|
||||
user.destroy
|
||||
end
|
||||
|
||||
|
@ -59,7 +59,7 @@ namespace :support do
|
|||
|
||||
# remove all the other dossier from the user side
|
||||
rake_puts "hide #{user.reload.dossiers.count} dossiers"
|
||||
user.delete_and_keep_track_dossiers(super_admin)
|
||||
user.delete_and_keep_track_dossiers(super_admin, reason: :user_removed)
|
||||
|
||||
owned_procedures, shared_procedures = user.administrateur
|
||||
.procedures
|
||||
|
|
|
@ -301,14 +301,14 @@ describe User, type: :model do
|
|||
describe '#delete_and_keep_track_dossiers_also_delete_user' do
|
||||
let(:super_admin) { create(:super_admin) }
|
||||
let(:user) { create(:user) }
|
||||
|
||||
let(:reason) { :user_rmoved }
|
||||
context 'without a dossier with processing strted' do
|
||||
let!(:dossier_en_construction) { create(:dossier, :en_construction, user: user) }
|
||||
let!(:dossier_brouillon) { create(:dossier, user: user) }
|
||||
|
||||
context 'without a discarded dossier' do
|
||||
it "keep track of dossiers and delete user" do
|
||||
user.delete_and_keep_track_dossiers_also_delete_user(super_admin)
|
||||
user.delete_and_keep_track_dossiers_also_delete_user(super_admin, reason:)
|
||||
|
||||
expect(DeletedDossier.find_by(dossier_id: dossier_en_construction)).to be_present
|
||||
expect(DeletedDossier.find_by(dossier_id: dossier_brouillon)).to be_nil
|
||||
|
@ -322,7 +322,7 @@ describe User, type: :model do
|
|||
|
||||
it "keep track of dossiers and delete user" do
|
||||
dossier_to_delete.hide_and_keep_track!(user, :user_request)
|
||||
user.delete_and_keep_track_dossiers_also_delete_user(super_admin)
|
||||
user.delete_and_keep_track_dossiers_also_delete_user(super_admin, reason:)
|
||||
|
||||
expect(DeletedDossier.find_by(dossier_id: dossier_en_construction)).to be_present
|
||||
expect(DeletedDossier.find_by(dossier_id: dossier_brouillon)).to be_nil
|
||||
|
@ -337,7 +337,7 @@ describe User, type: :model do
|
|||
let!(:dossier_termine) { create(:dossier, :accepte, user: user) }
|
||||
|
||||
it "keep track of dossiers and delete user" do
|
||||
user.delete_and_keep_track_dossiers_also_delete_user(super_admin)
|
||||
user.delete_and_keep_track_dossiers_also_delete_user(super_admin, reason:)
|
||||
|
||||
expect(dossier_en_instruction.reload).to be_present
|
||||
expect(dossier_en_instruction.user).to be_nil
|
||||
|
|
Loading…
Reference in a new issue