[#2179] Generate denormalized search terms value for Dossier
This commit is contained in:
parent
01ca8cc3cc
commit
0e639030f9
16 changed files with 354 additions and 0 deletions
|
@ -20,6 +20,10 @@ class Champ < ApplicationRecord
|
|||
mandatory? && value.blank?
|
||||
end
|
||||
|
||||
def search_terms
|
||||
[ to_s ]
|
||||
end
|
||||
|
||||
def to_s
|
||||
if value.present?
|
||||
string_value
|
||||
|
|
|
@ -1,2 +1,7 @@
|
|||
class Champs::CheckboxChamp < Champ
|
||||
def search_terms
|
||||
if value == 'on'
|
||||
[ libelle ]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
class Champs::DateChamp < Champ
|
||||
before_save :format_before_save
|
||||
|
||||
def search_terms
|
||||
# Text search is pretty useless for dates so we’re not including these champs
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def format_before_save
|
||||
|
|
|
@ -9,6 +9,10 @@ class Champs::DatetimeChamp < Champ
|
|||
same_date?(num, '%M')
|
||||
end
|
||||
|
||||
def search_terms
|
||||
# Text search is pretty useless for datetimes so we’re not including these champs
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def same_date?(num, compare)
|
||||
|
|
|
@ -1,2 +1,7 @@
|
|||
class Champs::EngagementChamp < Champs::CheckboxChamp
|
||||
def search_terms
|
||||
if value == 'on'
|
||||
[ libelle ]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,2 +1,5 @@
|
|||
class Champs::ExplicationChamp < Champs::TextChamp
|
||||
def search_terms
|
||||
# The user cannot enter any information here so it doesn’t make much sense to search
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,2 +1,5 @@
|
|||
class Champs::HeaderSectionChamp < Champ
|
||||
def search_terms
|
||||
# The user cannot enter any information here so it doesn’t make much sense to search
|
||||
end
|
||||
end
|
||||
|
|
|
@ -37,6 +37,10 @@ class Champs::LinkedDropDownListChamp < Champ
|
|||
mandatory? && (primary_value.blank? || secondary_value.blank?)
|
||||
end
|
||||
|
||||
def search_terms
|
||||
[ primary_value, secondary_value ]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def string_value
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
class Champs::MultipleDropDownListChamp < Champ
|
||||
before_save :format_before_save
|
||||
|
||||
def search_terms
|
||||
drop_down_list.selected_options_without_decorator(self)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def format_before_save
|
||||
|
|
|
@ -18,6 +18,10 @@ class Champs::PieceJustificativeChamp < Champ
|
|||
"image/jpeg"
|
||||
]
|
||||
|
||||
def search_terms
|
||||
# We don’t know how to search inside documents yet
|
||||
end
|
||||
|
||||
def mandatory_and_blank?
|
||||
mandatory? && !piece_justificative_file.attached?
|
||||
end
|
||||
|
|
|
@ -39,4 +39,8 @@ class Champs::SiretChamp < Champ
|
|||
|
||||
belongs_to :etablissement, dependent: :destroy
|
||||
accepts_nested_attributes_for :etablissement, allow_destroy: true, update_only: true
|
||||
|
||||
def search_terms
|
||||
etablissement.present? ? etablissement.search_terms : [ value ]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
class Champs::YesNoChamp < Champs::CheckboxChamp
|
||||
def search_terms
|
||||
if value == 'true'
|
||||
[ libelle ]
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def value_for_export
|
||||
|
|
|
@ -69,6 +69,7 @@ class Dossier < ApplicationRecord
|
|||
delegate :france_connect_information, to: :user
|
||||
|
||||
before_validation :update_state_dates, if: -> { state_changed? }
|
||||
before_save :update_search_terms
|
||||
|
||||
after_save :build_default_champs, if: Proc.new { saved_change_to_procedure_id? }
|
||||
after_save :build_default_individual, if: Proc.new { procedure.for_individual? }
|
||||
|
@ -78,6 +79,19 @@ class Dossier < ApplicationRecord
|
|||
|
||||
validates :user, presence: true
|
||||
|
||||
def update_search_terms
|
||||
self.search_terms = [
|
||||
user&.email,
|
||||
france_connect_information&.given_name,
|
||||
france_connect_information&.family_name,
|
||||
*ordered_champs.flat_map(&:search_terms),
|
||||
*etablissement&.search_terms,
|
||||
individual&.nom,
|
||||
individual&.prenom
|
||||
].compact.join(' ')
|
||||
self.private_search_terms = ordered_champs_private.flat_map(&:search_terms).compact.join(' ')
|
||||
end
|
||||
|
||||
def was_piece_justificative_uploaded_for_type_id?(type_id)
|
||||
pieces_justificatives.where(type_de_piece_justificative_id: type_id).count > 0
|
||||
end
|
||||
|
|
|
@ -11,6 +11,30 @@ class Etablissement < ApplicationRecord
|
|||
|
||||
validate :validate_signature
|
||||
|
||||
def search_terms
|
||||
[
|
||||
entreprise_siren,
|
||||
entreprise_numero_tva_intracommunautaire,
|
||||
entreprise_forme_juridique,
|
||||
entreprise_forme_juridique_code,
|
||||
entreprise_nom_commercial,
|
||||
entreprise_raison_sociale,
|
||||
entreprise_siret_siege_social,
|
||||
entreprise_nom,
|
||||
entreprise_prenom,
|
||||
association_rna,
|
||||
association_titre,
|
||||
association_objet,
|
||||
siret,
|
||||
naf,
|
||||
libelle_naf,
|
||||
adresse,
|
||||
code_postal,
|
||||
localite,
|
||||
code_insee_localite
|
||||
]
|
||||
end
|
||||
|
||||
def siren
|
||||
entreprise_siren
|
||||
end
|
||||
|
|
|
@ -120,6 +120,254 @@ describe Champ do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#search_terms' do
|
||||
let(:champ) { type_de_champ.champ.build(value: value) }
|
||||
subject { champ.search_terms }
|
||||
|
||||
context 'for adresse champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_address) }
|
||||
let(:value) { "10 rue du Pinson qui Piaille" }
|
||||
|
||||
it { is_expected.to eq([ value ]) }
|
||||
end
|
||||
|
||||
context 'for checkbox champ' do
|
||||
let(:libelle) { 'majeur' }
|
||||
let(:type_de_champ) { build(:type_de_champ_checkbox, libelle: libelle) }
|
||||
|
||||
context 'when the box is checked' do
|
||||
let(:value) { 'on' }
|
||||
|
||||
it { is_expected.to eq([ libelle ]) }
|
||||
end
|
||||
|
||||
context 'when the box is unchecked' do
|
||||
let(:value) { 'off' }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
end
|
||||
|
||||
context 'for civilite champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_civilite) }
|
||||
let(:value) { "M." }
|
||||
|
||||
it { is_expected.to eq([ value ]) }
|
||||
end
|
||||
|
||||
context 'for date champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_date) }
|
||||
let(:value) { "2018-07-30" }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
context 'for date time champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_datetime) }
|
||||
let(:value) { "2018-04-29 09:00" }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
context 'for département champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_departements) }
|
||||
let(:value) { "69 - Rhône" }
|
||||
|
||||
it { is_expected.to eq([ value ]) }
|
||||
end
|
||||
|
||||
context 'for dossier link champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_dossier_link) }
|
||||
let(:value) { "9103132886" }
|
||||
|
||||
it { is_expected.to eq([ value ]) }
|
||||
end
|
||||
|
||||
context 'for drop down list champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_dossier_link) }
|
||||
let(:value) { "HLM" }
|
||||
|
||||
it { is_expected.to eq([ value ]) }
|
||||
end
|
||||
|
||||
context 'for email champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_email) }
|
||||
let(:value) { "machin@example.com" }
|
||||
|
||||
it { is_expected.to eq([ value ]) }
|
||||
end
|
||||
|
||||
context 'for engagement champ' do
|
||||
let(:libelle) { 'je consens' }
|
||||
let(:type_de_champ) { build(:type_de_champ_engagement, libelle: libelle) }
|
||||
|
||||
context 'when the box is checked' do
|
||||
let(:value) { 'on' }
|
||||
|
||||
it { is_expected.to eq([ libelle ]) }
|
||||
end
|
||||
|
||||
context 'when the box is unchecked' do
|
||||
let(:value) { 'off' }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
end
|
||||
|
||||
context 'for explication champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_explication) }
|
||||
let(:value) { nil }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
context 'for header section champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_header_section) }
|
||||
let(:value) { nil }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
context 'for linked drop down list champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_linked_drop_down_list) }
|
||||
let(:champ) { type_de_champ.champ.build(primary_value: "hello", secondary_value: "world") }
|
||||
|
||||
it { is_expected.to eq(["hello", "world"]) }
|
||||
end
|
||||
|
||||
context 'for multiple drop down list champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_multiple_drop_down_list) }
|
||||
|
||||
context 'when there are multiple values selected' do
|
||||
let(:value) { JSON.generate([ 'goodbye', 'cruel', 'world' ]) }
|
||||
|
||||
it { is_expected.to eq(["goodbye", "cruel", "world"]) }
|
||||
end
|
||||
|
||||
context 'when there is no value selected' do
|
||||
let(:value) { nil }
|
||||
|
||||
it { is_expected.to eq([]) }
|
||||
end
|
||||
end
|
||||
|
||||
context 'for number champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_number) }
|
||||
let(:value) { "1234" }
|
||||
|
||||
it { is_expected.to eq([ value ]) }
|
||||
end
|
||||
|
||||
context 'for pays champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_pays) }
|
||||
let(:value) { "FRANCE" }
|
||||
|
||||
it { is_expected.to eq([ value ]) }
|
||||
end
|
||||
|
||||
context 'for phone champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_phone) }
|
||||
let(:value) { "0606060606" }
|
||||
|
||||
it { is_expected.to eq([ value ]) }
|
||||
end
|
||||
|
||||
context 'for pièce justificative champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_piece_justificative) }
|
||||
let(:value) { nil }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
context 'for region champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_regions) }
|
||||
let(:value) { "Île-de-France" }
|
||||
|
||||
it { is_expected.to eq([ value ]) }
|
||||
end
|
||||
|
||||
context 'for siret champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_siret) }
|
||||
|
||||
context 'when there is an etablissement' do
|
||||
let(:etablissement) do
|
||||
build(
|
||||
:etablissement,
|
||||
siret: "35130347400024",
|
||||
siege_social: true,
|
||||
naf: "9004Z",
|
||||
libelle_naf: "Gestion de salles de spectacles",
|
||||
adresse: "MAISON JEUNES CULTURE FABRIQUE\r\n98 RUE DE PARIS\r\n59200 TOURCOING\r\nFRANCE\r\n",
|
||||
numero_voie: "98",
|
||||
type_voie: "RUE",
|
||||
nom_voie: "DE PARIS",
|
||||
code_postal: "59200",
|
||||
localite: "TOURCOING",
|
||||
code_insee_localite: "59599",
|
||||
entreprise_siren: "351303474",
|
||||
entreprise_numero_tva_intracommunautaire: "FR02351303474",
|
||||
entreprise_forme_juridique: "Association déclarée ",
|
||||
entreprise_forme_juridique_code: "9220",
|
||||
entreprise_nom_commercial: "",
|
||||
entreprise_raison_sociale: "MAISON DES JEUNES ET DE LA CULTURE DE LA FABRIQUE",
|
||||
entreprise_siret_siege_social: "35130347400024",
|
||||
entreprise_nom: 'Martin',
|
||||
entreprise_prenom: 'Guillaume',
|
||||
entreprise_code_effectif_entreprise: "12",
|
||||
entreprise_date_creation: "1989-07-09",
|
||||
association_rna: "W595004053",
|
||||
association_titre: "MAISON DES JEUNES ET DE LA CULTURE DE LA FABRIQUE",
|
||||
association_objet: "Création, gestion et animation de la Maison des Jeunes et de la Culture de la Fabrique, qui constitue un élément essentiel de la vie sociale et culturelle d'un territoire de vie : pays, agglomération, ville, communauté de communes, village, quartier ...",
|
||||
association_date_creation: "1962-05-23",
|
||||
association_date_declaration: "2016-12-02",
|
||||
association_date_publication: "1962-05-31"
|
||||
)
|
||||
end
|
||||
let(:champ) { type_de_champ.champ.build(value: etablissement.siret, etablissement: etablissement) }
|
||||
|
||||
it { is_expected.to eq([ etablissement.entreprise_siren, etablissement.entreprise_numero_tva_intracommunautaire, etablissement.entreprise_forme_juridique, etablissement.entreprise_forme_juridique_code, etablissement.entreprise_nom_commercial, etablissement.entreprise_raison_sociale, etablissement.entreprise_siret_siege_social, etablissement.entreprise_nom, etablissement.entreprise_prenom, etablissement.association_rna, etablissement.association_titre, etablissement.association_objet, etablissement.siret, etablissement.naf, etablissement.libelle_naf, etablissement.adresse, etablissement.code_postal, etablissement.localite, etablissement.code_insee_localite ]) }
|
||||
end
|
||||
|
||||
context 'when there is no etablissement' do
|
||||
let(:siret) { "35130347400024" }
|
||||
let(:champ) { type_de_champ.champ.build(value: siret) }
|
||||
|
||||
it { is_expected.to eq([ siret ]) }
|
||||
end
|
||||
end
|
||||
|
||||
context 'for text champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_text) }
|
||||
let(:value) { "Blah" }
|
||||
|
||||
it { is_expected.to eq([ value ]) }
|
||||
end
|
||||
|
||||
context 'for text area champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_textarea) }
|
||||
let(:value) { "Bla\nBlah de bla." }
|
||||
|
||||
it { is_expected.to eq([ value ]) }
|
||||
end
|
||||
|
||||
context 'for yes/no champ' do
|
||||
let(:type_de_champ) { build(:type_de_champ_yes_no, libelle: libelle) }
|
||||
let(:libelle) { 'avec enfant à charge' }
|
||||
|
||||
context 'when the box is checked' do
|
||||
let(:value) { "true" }
|
||||
|
||||
it { is_expected.to eq([ libelle ]) }
|
||||
end
|
||||
|
||||
context 'when the box is unchecked' do
|
||||
let(:value) { "false" }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when type_de_champ is multiple_drop_down_list' do
|
||||
let(:type_de_champ) { create(:type_de_champ_multiple_drop_down_list) }
|
||||
let(:value) { '["Crétinier", "Mousserie"]' }
|
||||
|
|
|
@ -33,6 +33,24 @@ describe Dossier do
|
|||
|
||||
subject { dossier }
|
||||
|
||||
describe '#update_search_terms' do
|
||||
let(:etablissement) { build(:etablissement, entreprise_nom: 'Dupont', entreprise_prenom: 'Thomas', association_rna: '12345', association_titre: 'asso de test', association_objet: 'tests unitaires') }
|
||||
let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private) }
|
||||
let(:dossier) { create(:dossier, etablissement: etablissement, user: user, procedure: procedure) }
|
||||
let(:france_connect_information) { build(:france_connect_information, given_name: 'Chris', family_name: 'Harrisson') }
|
||||
let(:user) { build(:user, france_connect_information: france_connect_information) }
|
||||
|
||||
before do
|
||||
dossier.champs.each { |c| c.update_attribute(:value, "champ public") }
|
||||
dossier.champs_private.each { |c| c.update_attribute(:value, "champ privé") }
|
||||
|
||||
dossier.update_search_terms
|
||||
end
|
||||
|
||||
it { expect(dossier.search_terms).to eq("#{user.email} #{france_connect_information.given_name} #{france_connect_information.family_name} champ public #{etablissement.entreprise_siren} #{etablissement.entreprise_numero_tva_intracommunautaire} #{etablissement.entreprise_forme_juridique} #{etablissement.entreprise_forme_juridique_code} #{etablissement.entreprise_nom_commercial} #{etablissement.entreprise_raison_sociale} #{etablissement.entreprise_siret_siege_social} #{etablissement.entreprise_nom} #{etablissement.entreprise_prenom} #{etablissement.association_rna} #{etablissement.association_titre} #{etablissement.association_objet} #{etablissement.siret} #{etablissement.naf} #{etablissement.libelle_naf} #{etablissement.adresse} #{etablissement.code_postal} #{etablissement.localite} #{etablissement.code_insee_localite}") }
|
||||
it { expect(dossier.private_search_terms).to eq('champ privé') }
|
||||
end
|
||||
|
||||
describe '#types_de_piece_justificative' do
|
||||
subject { dossier.types_de_piece_justificative }
|
||||
it 'returns list of required piece justificative' do
|
||||
|
|
Loading…
Reference in a new issue