change dossier method
This commit is contained in:
parent
598cb09c6d
commit
051d7b2028
1 changed files with 20 additions and 3 deletions
|
@ -682,6 +682,10 @@ class Dossier < ApplicationRecord
|
||||||
!procedure.brouillon? && !brouillon?
|
!procedure.brouillon? && !brouillon?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def deleted_by_instructeur_and_user?
|
||||||
|
termine? && self.hidden_by_instructeur_at.present? && self.hidden_by_user_at.present?
|
||||||
|
end
|
||||||
|
|
||||||
def expose_legacy_carto_api?
|
def expose_legacy_carto_api?
|
||||||
procedure.expose_legacy_carto_api?
|
procedure.expose_legacy_carto_api?
|
||||||
end
|
end
|
||||||
|
@ -733,17 +737,30 @@ class Dossier < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def discard_and_keep_track!(author, reason)
|
def discard_and_keep_track!(author, reason)
|
||||||
|
author_is_user = author.is_a?(User)
|
||||||
|
author_is_instructeur = author.is_a?(Instructeur)
|
||||||
|
|
||||||
|
if self.termine? && author_is_instructeur
|
||||||
|
self.update(hidden_by_instructeur_at: Time.zone.now)
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.termine? && author_is_user
|
||||||
|
self.update(hidden_by_user_at: Time.zone.now)
|
||||||
|
end
|
||||||
|
|
||||||
user_email = user_deleted? ? nil : user_email_for(:notification)
|
user_email = user_deleted? ? nil : user_email_for(:notification)
|
||||||
deleted_dossier = nil
|
deleted_dossier = nil
|
||||||
|
|
||||||
transaction do
|
transaction do
|
||||||
if keep_track_on_deletion?
|
if deleted_by_instructeur_and_user? || !author_is_instructeur && keep_track_on_deletion?
|
||||||
log_dossier_operation(author, :supprimer, self)
|
log_dossier_operation(author, :supprimer, self)
|
||||||
deleted_dossier = DeletedDossier.create_from_dossier(self, reason)
|
deleted_dossier = DeletedDossier.create_from_dossier(self, reason)
|
||||||
end
|
end
|
||||||
|
|
||||||
update!(dossier_transfer_id: nil)
|
if deleted_by_instructeur_and_user? || !author_is_instructeur && !termine?
|
||||||
discard!
|
update!(dossier_transfer_id: nil)
|
||||||
|
discard!
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if deleted_dossier.present?
|
if deleted_dossier.present?
|
||||||
|
|
Loading…
Reference in a new issue