show cnaf tdc when procedure is compatible
This commit is contained in:
parent
7072993721
commit
7aee944daa
2 changed files with 18 additions and 5 deletions
|
@ -716,6 +716,10 @@ class Procedure < ApplicationRecord
|
||||||
published_revision.touch(:published_at)
|
published_revision.touch(:published_at)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def cnaf_enabled?
|
||||||
|
api_particulier_sources['cnaf'].present?
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def before_publish
|
def before_publish
|
||||||
|
|
|
@ -292,17 +292,26 @@ class TypeDeChamp < ApplicationRecord
|
||||||
def self.type_de_champ_types_for(procedure, user)
|
def self.type_de_champ_types_for(procedure, user)
|
||||||
has_legacy_number = (procedure.types_de_champ + procedure.types_de_champ_private).any?(&:legacy_number?)
|
has_legacy_number = (procedure.types_de_champ + procedure.types_de_champ_private).any?(&:legacy_number?)
|
||||||
|
|
||||||
show_number = -> (tdc) { tdc != TypeDeChamp.type_champs.fetch(:number) || has_legacy_number }
|
filter_featured_tdc = -> (tdc) do
|
||||||
|
|
||||||
enabled_featured_champ = -> (tdc) do
|
|
||||||
feature_name = FEATURE_FLAGS[tdc]
|
feature_name = FEATURE_FLAGS[tdc]
|
||||||
feature_name.blank? || Flipper.enabled?(feature_name, user)
|
feature_name.blank? || Flipper.enabled?(feature_name, user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
filter_tdc = -> (tdc) do
|
||||||
|
case tdc
|
||||||
|
when TypeDeChamp.type_champs.fetch(:number)
|
||||||
|
has_legacy_number
|
||||||
|
when TypeDeChamp.type_champs.fetch(:cnaf)
|
||||||
|
procedure.cnaf_enabled?
|
||||||
|
else
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
type_champs
|
type_champs
|
||||||
.keys
|
.keys
|
||||||
.filter(&show_number)
|
.filter(&filter_tdc)
|
||||||
.filter(&enabled_featured_champ)
|
.filter(&filter_featured_tdc)
|
||||||
.map { |tdc| [I18n.t("activerecord.attributes.type_de_champ.type_champs.#{tdc}"), tdc] }
|
.map { |tdc| [I18n.t("activerecord.attributes.type_de_champ.type_champs.#{tdc}"), tdc] }
|
||||||
.sort_by(&:first)
|
.sort_by(&:first)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue