Activate champ integer number on all the new procedures
This commit is contained in:
parent
d879a43520
commit
be66a8986c
4 changed files with 85 additions and 54 deletions
|
@ -21,8 +21,8 @@ module ProcedureHelper
|
|||
def types_de_champ_data(procedure)
|
||||
{
|
||||
isAnnotation: false,
|
||||
typeDeChampsTypes: types_de_champ_types,
|
||||
typeDeChamps: types_de_champ_as_json(procedure.types_de_champ),
|
||||
typeDeChampsTypes: TypeDeChamp.type_de_champ_types_for(procedure, current_user),
|
||||
typeDeChamps: procedure.types_de_champ.as_json_for_editor,
|
||||
baseUrl: procedure_types_de_champ_path(procedure),
|
||||
directUploadUrl: rails_direct_uploads_url
|
||||
}
|
||||
|
@ -31,58 +31,12 @@ module ProcedureHelper
|
|||
def types_de_champ_private_data(procedure)
|
||||
{
|
||||
isAnnotation: true,
|
||||
typeDeChampsTypes: types_de_champ_types,
|
||||
typeDeChamps: types_de_champ_as_json(procedure.types_de_champ_private),
|
||||
typeDeChampsTypes: TypeDeChamp.type_de_champ_types_for(procedure, current_user),
|
||||
typeDeChamps: procedure.types_de_champ_private.as_json_for_editor,
|
||||
baseUrl: procedure_types_de_champ_path(procedure),
|
||||
directUploadUrl: rails_direct_uploads_url
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
TOGGLES = {
|
||||
TypeDeChamp.type_champs.fetch(:integer_number) => :administrateur_champ_integer_number
|
||||
}
|
||||
|
||||
def types_de_champ_types
|
||||
types_de_champ_types = TypeDeChamp.type_de_champs_list_fr
|
||||
|
||||
types_de_champ_types.select! do |tdc|
|
||||
toggle = TOGGLES[tdc.last]
|
||||
toggle.blank? || feature_enabled?(toggle)
|
||||
end
|
||||
|
||||
types_de_champ_types
|
||||
end
|
||||
|
||||
TYPES_DE_CHAMP_BASE = {
|
||||
except: [
|
||||
:created_at,
|
||||
:options,
|
||||
:order_place,
|
||||
:parent_id,
|
||||
:private,
|
||||
:procedure_id,
|
||||
:stable_id,
|
||||
:type,
|
||||
:updated_at
|
||||
],
|
||||
methods: [
|
||||
:cadastres,
|
||||
:drop_down_list_value,
|
||||
:parcelles_agricoles,
|
||||
:piece_justificative_template_filename,
|
||||
:piece_justificative_template_url,
|
||||
:quartiers_prioritaires
|
||||
]
|
||||
}
|
||||
TYPES_DE_CHAMP = TYPES_DE_CHAMP_BASE
|
||||
.merge(include: { types_de_champ: TYPES_DE_CHAMP_BASE })
|
||||
|
||||
def types_de_champ_as_json(types_de_champ)
|
||||
types_de_champ.includes(:drop_down_list,
|
||||
piece_justificative_template_attachment: :blob,
|
||||
types_de_champ: [:drop_down_list, piece_justificative_template_attachment: :blob])
|
||||
.as_json(TYPES_DE_CHAMP)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -115,10 +115,6 @@ class TypeDeChamp < ApplicationRecord
|
|||
dynamic_type.build_champ
|
||||
end
|
||||
|
||||
def self.type_de_champs_list_fr
|
||||
type_champs.map { |champ| [I18n.t("activerecord.attributes.type_de_champ.type_champs.#{champ.last}"), champ.first] }
|
||||
end
|
||||
|
||||
def check_mandatory
|
||||
if non_fillable?
|
||||
self.mandatory = false
|
||||
|
@ -162,6 +158,10 @@ class TypeDeChamp < ApplicationRecord
|
|||
type_champ == TypeDeChamp.type_champs.fetch(:dossier_link)
|
||||
end
|
||||
|
||||
def legacy_number?
|
||||
type_champ == TypeDeChamp.type_champs.fetch(:number)
|
||||
end
|
||||
|
||||
def public?
|
||||
!private?
|
||||
end
|
||||
|
@ -194,6 +194,54 @@ class TypeDeChamp < ApplicationRecord
|
|||
GraphQL::Schema::UniqueWithinType.encode('Champ', stable_id)
|
||||
end
|
||||
|
||||
FEATURE_FLAGS = {}
|
||||
|
||||
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]
|
||||
feature_name.blank? || Flipper.enabled?(feature_name, user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
TYPES_DE_CHAMP_BASE = {
|
||||
except: [
|
||||
:created_at,
|
||||
:options,
|
||||
:order_place,
|
||||
:parent_id,
|
||||
:private,
|
||||
:procedure_id,
|
||||
:stable_id,
|
||||
:type,
|
||||
:updated_at
|
||||
],
|
||||
methods: [
|
||||
:cadastres,
|
||||
:drop_down_list_value,
|
||||
:parcelles_agricoles,
|
||||
:piece_justificative_template_filename,
|
||||
:piece_justificative_template_url,
|
||||
:quartiers_prioritaires
|
||||
]
|
||||
}
|
||||
TYPES_DE_CHAMP = TYPES_DE_CHAMP_BASE
|
||||
.merge(include: { types_de_champ: TYPES_DE_CHAMP_BASE })
|
||||
|
||||
def self.as_json_for_editor
|
||||
includes(:drop_down_list,
|
||||
piece_justificative_template_attachment: :blob,
|
||||
types_de_champ: [:drop_down_list, piece_justificative_template_attachment: :blob])
|
||||
.as_json(TYPES_DE_CHAMP)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_default_drop_down_list
|
||||
|
|
|
@ -162,6 +162,14 @@ FactoryBot.define do
|
|||
end
|
||||
end
|
||||
|
||||
trait :with_number do
|
||||
after(:build) do |procedure, _evaluator|
|
||||
type_de_champ = create(:type_de_champ_number)
|
||||
|
||||
procedure.types_de_champ << type_de_champ
|
||||
end
|
||||
end
|
||||
|
||||
trait :published do
|
||||
after(:build) do |procedure, _evaluator|
|
||||
procedure.path = generate(:published_path)
|
||||
|
|
|
@ -166,4 +166,25 @@ shared_examples 'type_de_champ_spec' do
|
|||
expect(messages.last.starts_with?("La liste doit commencer par")).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
describe '#type_de_champ_types_for' do
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:user) { create(:user) }
|
||||
|
||||
context 'when procedure without legacy "number"' do
|
||||
it 'should have "nombre decimal" instead of "nombre"' do
|
||||
expect(TypeDeChamp.type_de_champ_types_for(procedure, user).find { |tdc| tdc.last == TypeDeChamp.type_champs.fetch(:number) }).to be_nil
|
||||
expect(TypeDeChamp.type_de_champ_types_for(procedure, user).find { |tdc| tdc.last == TypeDeChamp.type_champs.fetch(:decimal_number) }).not_to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when procedure with legacy "number"' do
|
||||
let(:procedure) { create(:procedure, :with_number) }
|
||||
|
||||
it 'should have "nombre decimal" and "nombre"' do
|
||||
expect(TypeDeChamp.type_de_champ_types_for(procedure, user).find { |tdc| tdc.last == TypeDeChamp.type_champs.fetch(:number) }).not_to be_nil
|
||||
expect(TypeDeChamp.type_de_champ_types_for(procedure, user).find { |tdc| tdc.last == TypeDeChamp.type_champs.fetch(:decimal_number) }).not_to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue