Merge pull request #4811 from tchak/champ-nombre
Activate champ integer number on all the new procedures
This commit is contained in:
commit
e2356c8000
4 changed files with 85 additions and 54 deletions
|
@ -21,8 +21,8 @@ module ProcedureHelper
|
||||||
def types_de_champ_data(procedure)
|
def types_de_champ_data(procedure)
|
||||||
{
|
{
|
||||||
isAnnotation: false,
|
isAnnotation: false,
|
||||||
typeDeChampsTypes: types_de_champ_types,
|
typeDeChampsTypes: TypeDeChamp.type_de_champ_types_for(procedure, current_user),
|
||||||
typeDeChamps: types_de_champ_as_json(procedure.types_de_champ),
|
typeDeChamps: procedure.types_de_champ.as_json_for_editor,
|
||||||
baseUrl: procedure_types_de_champ_path(procedure),
|
baseUrl: procedure_types_de_champ_path(procedure),
|
||||||
directUploadUrl: rails_direct_uploads_url
|
directUploadUrl: rails_direct_uploads_url
|
||||||
}
|
}
|
||||||
|
@ -31,58 +31,12 @@ module ProcedureHelper
|
||||||
def types_de_champ_private_data(procedure)
|
def types_de_champ_private_data(procedure)
|
||||||
{
|
{
|
||||||
isAnnotation: true,
|
isAnnotation: true,
|
||||||
typeDeChampsTypes: types_de_champ_types,
|
typeDeChampsTypes: TypeDeChamp.type_de_champ_types_for(procedure, current_user),
|
||||||
typeDeChamps: types_de_champ_as_json(procedure.types_de_champ_private),
|
typeDeChamps: procedure.types_de_champ_private.as_json_for_editor,
|
||||||
baseUrl: procedure_types_de_champ_path(procedure),
|
baseUrl: procedure_types_de_champ_path(procedure),
|
||||||
directUploadUrl: rails_direct_uploads_url
|
directUploadUrl: rails_direct_uploads_url
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
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
|
end
|
||||||
|
|
|
@ -115,10 +115,6 @@ class TypeDeChamp < ApplicationRecord
|
||||||
dynamic_type.build_champ
|
dynamic_type.build_champ
|
||||||
end
|
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
|
def check_mandatory
|
||||||
if non_fillable?
|
if non_fillable?
|
||||||
self.mandatory = false
|
self.mandatory = false
|
||||||
|
@ -162,6 +158,10 @@ class TypeDeChamp < ApplicationRecord
|
||||||
type_champ == TypeDeChamp.type_champs.fetch(:dossier_link)
|
type_champ == TypeDeChamp.type_champs.fetch(:dossier_link)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def legacy_number?
|
||||||
|
type_champ == TypeDeChamp.type_champs.fetch(:number)
|
||||||
|
end
|
||||||
|
|
||||||
def public?
|
def public?
|
||||||
!private?
|
!private?
|
||||||
end
|
end
|
||||||
|
@ -194,6 +194,54 @@ class TypeDeChamp < ApplicationRecord
|
||||||
GraphQL::Schema::UniqueWithinType.encode('Champ', stable_id)
|
GraphQL::Schema::UniqueWithinType.encode('Champ', stable_id)
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def set_default_drop_down_list
|
def set_default_drop_down_list
|
||||||
|
|
|
@ -162,6 +162,14 @@ FactoryBot.define do
|
||||||
end
|
end
|
||||||
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
|
trait :published do
|
||||||
after(:build) do |procedure, _evaluator|
|
after(:build) do |procedure, _evaluator|
|
||||||
procedure.path = generate(:published_path)
|
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
|
expect(messages.last.starts_with?("La liste doit commencer par")).to be_truthy
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue