rework type de champ type

This commit is contained in:
simon lehericey 2021-09-27 14:24:57 +02:00
parent dff96e0497
commit f55db98e97

View file

@ -291,16 +291,18 @@ class TypeDeChamp < ApplicationRecord
def self.type_de_champ_types_for(procedure, user)
has_legacy_number = (procedure.types_de_champ + procedure.types_de_champ_private).any?(&:legacy_number?)
type_champs.map do |type_champ|
[I18n.t("activerecord.attributes.type_de_champ.type_champs.#{type_champ.last}"), type_champ.first]
end.filter do |tdc|
if tdc.last == TypeDeChamp.type_champs.fetch(:number)
has_legacy_number
else
feature_name = FEATURE_FLAGS[tdc.last]
show_number = -> (tdc) { tdc != TypeDeChamp.type_champs.fetch(:number) || has_legacy_number }
enabled_featured_champ = -> (tdc) do
feature_name = FEATURE_FLAGS[tdc]
feature_name.blank? || Flipper.enabled?(feature_name, user)
end
end
type_champs
.keys
.filter(&show_number)
.filter(&enabled_featured_champ)
.map { |tdc| [I18n.t("activerecord.attributes.type_de_champ.type_champs.#{tdc}"), tdc] }
end
TYPES_DE_CHAMP_BASE = {