Merge pull request #6574 from tchak/fix-discarded-dossiers-deletion
fix(dossier): fix dossier.avis cascade
This commit is contained in:
commit
05293ad849
5 changed files with 31 additions and 21 deletions
|
@ -1,16 +1,7 @@
|
|||
class Cron::DiscardedDossiersDeletionJob < Cron::CronJob
|
||||
self.schedule_expression = "every day at 2 am"
|
||||
|
||||
def perform(*args)
|
||||
DossierOperationLog.where(dossier: Dossier.discarded_en_construction_expired)
|
||||
.where.not(operation: DossierOperationLog.operations.fetch(:supprimer))
|
||||
.destroy_all
|
||||
DossierOperationLog.where(dossier: Dossier.discarded_termine_expired)
|
||||
.where.not(operation: DossierOperationLog.operations.fetch(:supprimer))
|
||||
.destroy_all
|
||||
|
||||
Dossier.discarded_brouillon_expired.destroy_all
|
||||
Dossier.discarded_en_construction_expired.destroy_all
|
||||
Dossier.discarded_termine_expired.destroy_all
|
||||
def perform
|
||||
Dossier.purge_discarded
|
||||
end
|
||||
end
|
||||
|
|
|
@ -49,6 +49,7 @@ class Avis < ApplicationRecord
|
|||
scope :for_dossier, -> (dossier_id) { where(dossier_id: dossier_id) }
|
||||
scope :by_latest, -> { order(updated_at: :desc) }
|
||||
scope :updated_since?, -> (date) { where('avis.updated_at > ?', date) }
|
||||
scope :discarded_termine_expired, -> { unscope(:joins).where(dossier: Dossier.discarded_termine_expired) }
|
||||
|
||||
# The form allows subtmitting avis requests to several emails at once,
|
||||
# hence this virtual attribute.
|
||||
|
|
|
@ -960,6 +960,21 @@ class Dossier < ApplicationRecord
|
|||
user&.locale || I18n.default_locale
|
||||
end
|
||||
|
||||
def self.purge_discarded
|
||||
discarded_brouillon_expired.destroy_all
|
||||
|
||||
transaction do
|
||||
DossierOperationLog.discarded_en_construction_expired.destroy_all
|
||||
discarded_en_construction_expired.destroy_all
|
||||
end
|
||||
|
||||
transaction do
|
||||
DossierOperationLog.discarded_termine_expired.destroy_all
|
||||
Avis.discarded_termine_expired.destroy_all
|
||||
discarded_termine_expired.destroy_all
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def defaut_groupe_instructeur?
|
||||
|
|
|
@ -36,6 +36,10 @@ class DossierOperationLog < ApplicationRecord
|
|||
belongs_to :dossier, optional: true
|
||||
belongs_to :bill_signature, optional: true
|
||||
|
||||
scope :not_deletion, -> { where.not(operation: operations.fetch(:supprimer)) }
|
||||
scope :discarded_en_construction_expired, -> { where(dossier: Dossier.discarded_en_construction_expired).not_deletion }
|
||||
scope :discarded_termine_expired, -> { where(dossier: Dossier.discarded_termine_expired).not_deletion }
|
||||
|
||||
def self.create_and_serialize(params)
|
||||
dossier = params.fetch(:dossier)
|
||||
|
||||
|
|
|
@ -182,17 +182,16 @@ class User < ApplicationRecord
|
|||
raise "Cannot delete this user because they are also instructeur, expert or administrateur"
|
||||
end
|
||||
|
||||
Invite.where(dossier: dossiers.with_discarded).destroy_all
|
||||
dossiers.state_en_construction.each do |dossier|
|
||||
dossier.discard_and_keep_track!(administration, :user_removed)
|
||||
transaction do
|
||||
Invite.where(dossier: dossiers.with_discarded).destroy_all
|
||||
dossiers.state_en_construction.each do |dossier|
|
||||
dossier.discard_and_keep_track!(administration, :user_removed)
|
||||
end
|
||||
DossierOperationLog.where(dossier: dossiers.with_discarded.discarded).not_deletion.destroy_all
|
||||
dossiers.with_discarded.discarded.destroy_all
|
||||
dossiers.update_all(deleted_user_email_never_send: email, user_id: nil, dossier_transfer_id: nil)
|
||||
destroy!
|
||||
end
|
||||
DossierOperationLog
|
||||
.where(dossier: dossiers.with_discarded.discarded)
|
||||
.where.not(operation: DossierOperationLog.operations.fetch(:supprimer))
|
||||
.destroy_all
|
||||
dossiers.with_discarded.discarded.destroy_all
|
||||
dossiers.update_all(deleted_user_email_never_send: email, user_id: nil, dossier_transfer_id: nil)
|
||||
destroy!
|
||||
end
|
||||
|
||||
private
|
||||
|
|
Loading…
Reference in a new issue