2018-03-06 13:44:29 +01:00
|
|
|
class AssignTo < ApplicationRecord
|
2016-05-20 15:39:17 +02:00
|
|
|
belongs_to :procedure
|
|
|
|
belongs_to :gestionnaire
|
2017-10-02 17:03:30 +02:00
|
|
|
has_one :procedure_presentation, dependent: :destroy
|
|
|
|
|
2019-03-18 14:43:05 +01:00
|
|
|
scope :with_email_notifications, -> { where(email_notifications_enabled: true) }
|
|
|
|
|
2018-10-23 11:39:54 +02:00
|
|
|
def procedure_presentation_or_default_and_errors
|
2018-10-23 11:48:25 +02:00
|
|
|
errors = reset_procedure_presentation_if_invalid
|
|
|
|
[procedure_presentation || build_procedure_presentation, errors]
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def reset_procedure_presentation_if_invalid
|
|
|
|
if procedure_presentation&.invalid?
|
|
|
|
# This is a last defense against invalid `ProcedurePresentation`s persistently
|
|
|
|
# hindering instructeurs. Whenever this gets triggered, it means that there is
|
|
|
|
# a bug somewhere else that we need to fix.
|
|
|
|
|
|
|
|
errors = procedure_presentation.errors
|
2018-10-23 12:18:46 +02:00
|
|
|
Raven.capture_message(
|
|
|
|
"Destroying invalid ProcedurePresentation",
|
|
|
|
extra: { procedure_presentation: procedure_presentation.as_json }
|
|
|
|
)
|
2018-10-23 11:48:25 +02:00
|
|
|
self.procedure_presentation = nil
|
|
|
|
errors
|
|
|
|
end
|
2017-10-02 17:03:30 +02:00
|
|
|
end
|
2017-04-04 15:27:04 +02:00
|
|
|
end
|