Revert "4127 fix superadmin supprime compte usager"
This commit is contained in:
parent
65a78b682f
commit
751f24f7bb
13 changed files with 22 additions and 150 deletions
|
@ -70,17 +70,4 @@ class Administrateur < ApplicationRecord
|
|||
def can_be_deleted?
|
||||
dossiers.state_instruction_commencee.none? && procedures.all? { |p| p.administrateurs.count > 1 }
|
||||
end
|
||||
|
||||
def delete_and_transfer_services
|
||||
if !can_be_deleted?
|
||||
fail "Impossible de supprimer cet administrateur car il a des dossiers ou des procédures"
|
||||
end
|
||||
dossiers.each(&:delete_and_keep_track)
|
||||
|
||||
procedures.each do |procedure|
|
||||
next_administrateur = procedure.administrateurs.where.not(id: self.id).first
|
||||
procedure.service.update(administrateur: next_administrateur)
|
||||
end
|
||||
destroy
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,9 +17,9 @@ class Instructeur < ApplicationRecord
|
|||
has_many :previously_followed_dossiers, -> { distinct }, through: :previous_follows, source: :dossier
|
||||
has_many :avis
|
||||
has_many :dossiers_from_avis, through: :avis, source: :dossier
|
||||
has_many :trusted_device_tokens, dependent: :destroy
|
||||
has_many :trusted_device_tokens
|
||||
|
||||
has_one :user, dependent: :nullify
|
||||
has_one :user
|
||||
|
||||
default_scope { eager_load(:user) }
|
||||
|
||||
|
@ -176,10 +176,6 @@ class Instructeur < ApplicationRecord
|
|||
trusted_device_token&.token_young?
|
||||
end
|
||||
|
||||
def can_be_deleted?
|
||||
user.administrateur.nil? && procedures.all? { |p| p.defaut_groupe_instructeur.instructeurs.count > 1 }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def annotations_hash(demande, annotations_privees, avis, messagerie)
|
||||
|
|
|
@ -97,7 +97,7 @@ class User < ApplicationRecord
|
|||
end
|
||||
|
||||
def can_be_deleted?
|
||||
administrateur.nil? && instructeur.nil? && dossiers.state_instruction_commencee.empty?
|
||||
dossiers.state_instruction_commencee.empty?
|
||||
end
|
||||
|
||||
def delete_and_keep_track_dossiers(administration)
|
||||
|
@ -105,11 +105,12 @@ class User < ApplicationRecord
|
|||
raise "Cannot delete this user because instruction has started for some dossiers"
|
||||
end
|
||||
|
||||
dossiers.each do |dossier|
|
||||
dossier.delete_and_keep_track(administration)
|
||||
if can_be_deleted?
|
||||
dossiers.each do |dossier|
|
||||
dossier.delete_and_keep_track(administration)
|
||||
end
|
||||
destroy
|
||||
end
|
||||
dossiers.unscoped.destroy_all
|
||||
destroy!
|
||||
end
|
||||
|
||||
private
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue