2020-08-06 16:35:45 +02:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: deleted_dossiers
|
|
|
|
#
|
2020-11-12 10:38:10 +01:00
|
|
|
# id :bigint not null, primary key
|
|
|
|
# deleted_at :datetime
|
|
|
|
# reason :string
|
|
|
|
# state :string
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
|
|
|
# dossier_id :bigint
|
|
|
|
# groupe_instructeur_id :bigint
|
|
|
|
# procedure_id :bigint
|
|
|
|
# revision_id :bigint
|
|
|
|
# user_id :bigint
|
2020-08-06 16:35:45 +02:00
|
|
|
#
|
2018-05-30 11:36:48 +02:00
|
|
|
class DeletedDossier < ApplicationRecord
|
2020-07-20 16:35:44 +02:00
|
|
|
belongs_to :procedure, -> { with_discarded }, inverse_of: :deleted_dossiers, optional: false
|
2019-02-13 16:13:37 +01:00
|
|
|
|
2020-03-31 14:33:54 +02:00
|
|
|
validates :dossier_id, uniqueness: true
|
|
|
|
|
2020-11-17 13:25:35 +01:00
|
|
|
scope :order_by_updated_at, -> (order = :desc) { order(created_at: order) }
|
2021-05-26 13:50:02 +02:00
|
|
|
scope :deleted_since, -> (since) { where('deleted_dossiers.deleted_at >= ?', since) }
|
2020-11-17 13:25:35 +01:00
|
|
|
|
2020-03-19 11:51:47 +01:00
|
|
|
enum reason: {
|
2020-03-26 09:08:52 +01:00
|
|
|
user_request: 'user_request',
|
|
|
|
manager_request: 'manager_request',
|
|
|
|
user_removed: 'user_removed',
|
|
|
|
procedure_removed: 'procedure_removed',
|
2020-11-17 13:25:35 +01:00
|
|
|
expired: 'expired',
|
|
|
|
instructeur_request: 'instructeur_request'
|
2020-03-19 11:51:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
def self.create_from_dossier(dossier, reason)
|
|
|
|
create!(
|
|
|
|
reason: reasons.fetch(reason),
|
|
|
|
dossier_id: dossier.id,
|
2020-11-12 10:38:10 +01:00
|
|
|
groupe_instructeur_id: dossier.groupe_instructeur_id,
|
|
|
|
revision_id: dossier.revision_id,
|
|
|
|
user_id: dossier.user_id,
|
2020-03-19 11:51:47 +01:00
|
|
|
procedure: dossier.procedure,
|
|
|
|
state: dossier.state,
|
|
|
|
deleted_at: Time.zone.now
|
|
|
|
)
|
2019-02-13 16:13:37 +01:00
|
|
|
end
|
2020-03-26 17:35:50 +01:00
|
|
|
|
|
|
|
def procedure_removed?
|
|
|
|
reason == self.class.reasons.fetch(:procedure_removed)
|
|
|
|
end
|
2021-09-01 18:17:26 +02:00
|
|
|
|
|
|
|
def user_locale
|
|
|
|
User.find_by(id: user_id)&.locale || I18n.default_locale
|
|
|
|
end
|
2018-05-30 11:36:48 +02:00
|
|
|
end
|