2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-05-25 19:09:59 +02:00
|
|
|
module ProcedureSVASVRConcern
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
2023-06-05 18:22:33 +02:00
|
|
|
scope :sva_svr, -> { where("sva_svr ->> 'decision' IN (?)", ['sva', 'svr']) }
|
2023-06-02 18:34:46 +02:00
|
|
|
validate :sva_svr_immutable_on_published, if: :will_save_change_to_sva_svr?
|
2023-06-26 17:34:54 +02:00
|
|
|
validate :validates_sva_svr_compatible
|
2023-06-02 18:34:46 +02:00
|
|
|
|
2023-05-25 19:09:59 +02:00
|
|
|
def sva_svr_enabled?
|
|
|
|
sva? || svr?
|
|
|
|
end
|
|
|
|
|
|
|
|
def sva?
|
|
|
|
decision == :sva
|
|
|
|
end
|
|
|
|
|
|
|
|
def svr?
|
|
|
|
decision == :svr
|
|
|
|
end
|
|
|
|
|
|
|
|
def sva_svr_configuration
|
|
|
|
@sva_svr_configuration ||= SVASVRConfiguration.new(sva_svr)
|
|
|
|
end
|
|
|
|
|
2023-06-28 16:34:50 +02:00
|
|
|
def sva_svr_decision
|
|
|
|
decision
|
|
|
|
end
|
|
|
|
|
2023-05-25 19:09:59 +02:00
|
|
|
private
|
|
|
|
|
|
|
|
def decision
|
|
|
|
sva_svr.fetch("decision", nil)&.to_sym
|
|
|
|
end
|
2023-06-02 18:34:46 +02:00
|
|
|
|
|
|
|
def decision_was
|
|
|
|
sva_svr_was.fetch("decision", nil)&.to_sym
|
|
|
|
end
|
|
|
|
|
|
|
|
def sva_svr_immutable_on_published
|
|
|
|
return if brouillon?
|
|
|
|
return if [:sva, :svr].exclude?(decision_was)
|
|
|
|
|
|
|
|
errors.add(:sva_svr, :immutable)
|
|
|
|
end
|
2023-06-26 17:34:54 +02:00
|
|
|
|
|
|
|
def validates_sva_svr_compatible
|
|
|
|
return if !sva_svr_enabled?
|
|
|
|
|
|
|
|
if declarative_with_state.present?
|
|
|
|
errors.add(:sva_svr, :declarative_incompatible)
|
|
|
|
end
|
|
|
|
end
|
2023-05-25 19:09:59 +02:00
|
|
|
end
|
|
|
|
end
|