Merge pull request #4879 from betagouv/4822-fix-bug-entreprises-non-diffusables

- permet à un usager de type "entreprise" de s'inscrire à DS même si cette entreprise n'a pas souhaité que ses infos soient diffusables

- permet également à un usager d'ajouter dans un champ de type SIRET le siret d'une entreprise qui n'a pas souhaité que ses infos soient diffusables (ces infos ne seront visibles que par les instructeurs)
This commit is contained in:
krichtof 2020-03-17 17:40:05 +01:00 committed by GitHub
commit 2a9c34ae21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 189 additions and 78 deletions

View file

@ -62,6 +62,7 @@ class ApiEntreprise::API
context: "demarches-simplifiees.fr", context: "demarches-simplifiees.fr",
recipient: siret_or_siren, recipient: siret_or_siren,
object: "procedure_id: #{procedure_id}", object: "procedure_id: #{procedure_id}",
non_diffusables: true,
token: token token: token
} }
end end

View file

@ -24,7 +24,8 @@ class ApiEntreprise::EtablissementAdapter < ApiEntreprise::Adapter
:siret, :siret,
:siege_social, :siege_social,
:naf, :naf,
:libelle_naf :libelle_naf,
:diffusable_commercialement
] ]
end end

View file

@ -1,76 +1,80 @@
%table.table.vertical.dossier-champs %table.table.vertical.dossier-champs
%tbody %tbody
%tr - if etablissement.diffusable_commercialement == false && profile != 'instructeur'
%th.libelle Dénomination : %tr
%td= raison_sociale_or_name(etablissement) %td= t('warning_for_private_info', etablissement: raison_sociale_or_name(etablissement), scope: 'views.shared.dossiers.identite_entreprise')
%tr - else
%th.libelle SIRET : %tr
%td= etablissement.siret %th.libelle Dénomination :
%td= raison_sociale_or_name(etablissement)
%tr
%th.libelle SIRET :
%td= etablissement.siret
- if etablissement.siret != etablissement.entreprise.siret_siege_social - if etablissement.siret != etablissement.entreprise.siret_siege_social
%tr
%th.libelle SIRET du siège social:
%td= etablissement.entreprise.siret_siege_social
%tr %tr
%th.libelle SIRET du siège social: %th.libelle Forme juridique :
%td= etablissement.entreprise.siret_siege_social %td= sanitize(etablissement.entreprise.forme_juridique)
%tr
%th.libelle Forme juridique :
%td= sanitize(etablissement.entreprise.forme_juridique)
%tr
%th.libelle Libellé NAF :
%td= etablissement.libelle_naf
%tr
%th.libelle Code NAF :
%td= etablissement.naf
%tr
%th.libelle Date de création :
%td= try_format_date(etablissement.entreprise.date_creation)
%tr
%th.libelle Effectif de l'organisation :
%td= effectif(etablissement)
%tr
%th.libelle Code effectif :
%td= etablissement.entreprise.code_effectif_entreprise
%tr
%th.libelle Numéro de TVA intracommunautaire :
%td= etablissement.entreprise.numero_tva_intracommunautaire
%tr
%th.libelle Adresse :
%td
- etablissement.adresse.split("\n").each do |line|
= line
%br
%tr
%th.libelle Capital social :
%td= pretty_currency(etablissement.entreprise.capital_social)
%tr
%th.libelle Exercices :
%td
- if profile == 'instructeur'
- etablissement.exercices.each_with_index do |exercice, index|
= "#{exercice.date_fin_exercice.year} : "
= pretty_currency(exercice.ca)
%br
- elsif etablissement.exercices.present?
= t('activemodel.models.exercices_summary', count: etablissement.exercices.count)
- if etablissement.association?
%tr %tr
%th.libelle Numéro RNA : %th.libelle Libellé NAF :
%td= etablissement.association_rna %td= etablissement.libelle_naf
%tr %tr
%th.libelle Titre : %th.libelle Code NAF :
%td= etablissement.association_titre %td= etablissement.naf
%tr
%th.libelle Objet :
%td= etablissement.association_objet
%tr %tr
%th.libelle Date de création : %th.libelle Date de création :
%td= try_format_date(etablissement.association_date_creation) %td= try_format_date(etablissement.entreprise.date_creation)
%tr %tr
%th.libelle Date de publication : %th.libelle Effectif de l'organisation :
%td= try_format_date(etablissement.association_date_publication) %td= effectif(etablissement)
%tr %tr
%th.libelle Date de déclaration : %th.libelle Code effectif :
%td= try_format_date(etablissement.association_date_declaration) %td= etablissement.entreprise.code_effectif_entreprise
%tr
%th.libelle Numéro de TVA intracommunautaire :
%td= etablissement.entreprise.numero_tva_intracommunautaire
%tr
%th.libelle Adresse :
%td
- etablissement.adresse.split("\n").each do |line|
= line
%br
%tr
%th.libelle Capital social :
%td= pretty_currency(etablissement.entreprise.capital_social)
%tr
%th.libelle Exercices :
%td
- if profile == 'instructeur'
- etablissement.exercices.each_with_index do |exercice, index|
= "#{exercice.date_fin_exercice.year} : "
= pretty_currency(exercice.ca)
%br
- elsif etablissement.exercices.present?
= t('activemodel.models.exercices_summary', count: etablissement.exercices.count)
- if etablissement.association?
%tr
%th.libelle Numéro RNA :
%td= etablissement.association_rna
%tr
%th.libelle Titre :
%td= etablissement.association_titre
%tr
%th.libelle Objet :
%td= etablissement.association_objet
%tr
%th.libelle Date de création :
%td= try_format_date(etablissement.association_date_creation)
%tr
%th.libelle Date de publication :
%td= try_format_date(etablissement.association_date_publication)
%tr
%th.libelle Date de déclaration :
%td= try_format_date(etablissement.association_date_declaration)
%p %p
= link_to '➡ Autres informations sur lorganisme sur « entreprise.data.gouv.fr »', = link_to '➡ Autres informations sur lorganisme sur « entreprise.data.gouv.fr »',

View file

@ -7,20 +7,25 @@
.container .container
%h1 Informations sur létablissement %h1 Informations sur létablissement
%p - etablissement = @dossier.etablissement
Nous avons récupéré auprès de lINSEE et dInfogreffe les informations suivantes concernant votre établissement. - if etablissement.diffusable_commercialement == false
%p= t('warning_for_private_info', etablissement: raison_sociale_or_name(etablissement), scope: 'views.shared.dossiers.identite_entreprise')
%p - else
Ces informations seront jointes à votre dossier. %p
Nous avons récupéré auprès de lINSEE et dInfogreffe les informations suivantes concernant votre établissement.
.etablissement-infos.card.featured %p
- etablissement = @dossier.etablissement Ces informations seront jointes à votre dossier.
%h2.card-title= raison_sociale_or_name(etablissement)
= render partial: 'users/dossiers/etablissement/infos_entreprise', locals: { etablissement: etablissement } .etablissement-infos.card.featured
- if etablissement.association? %h2.card-title= raison_sociale_or_name(etablissement)
= render partial: 'users/dossiers/etablissement/infos_association', locals: { etablissement: etablissement }
= render partial: 'users/dossiers/etablissement/infos_entreprise', locals: { etablissement: etablissement }
- if etablissement.association?
= render partial: 'users/dossiers/etablissement/infos_association', locals: { etablissement: etablissement }
.actions .actions
= link_to 'Utiliser un autre numéro SIRET', siret_dossier_path(@dossier), class: 'button' = link_to 'Utiliser un autre numéro SIRET', siret_dossier_path(@dossier), class: 'button'

View file

@ -0,0 +1,6 @@
fr:
views:
shared:
dossiers:
identite_entreprise:
warning_for_private_info: "L'établissement %{etablissement} a exercé son droit à la non publication des informations relatives à son identité. Les informations ne seront donc visibles que de la part des services instructeurs"

View file

@ -0,0 +1,5 @@
class AddDiffusableCommercialementToEtablissements < ActiveRecord::Migration[5.2]
def change
add_column :etablissements, :diffusable_commercialement, :boolean
end
end

View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_02_27_100001) do ActiveRecord::Schema.define(version: 2020_03_04_155418) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -304,6 +304,7 @@ ActiveRecord::Schema.define(version: 2020_02_27_100001) do
t.date "association_date_publication" t.date "association_date_publication"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.boolean "diffusable_commercialement"
t.index ["dossier_id"], name: "index_etablissements_on_dossier_id" t.index ["dossier_id"], name: "index_etablissements_on_dossier_id"
end end

View file

@ -29,6 +29,10 @@ FactoryBot.define do
create(:exercice, etablissement: etablissement) create(:exercice, etablissement: etablissement)
end end
end end
trait :non_diffusable do
diffusable_commercialement { false }
end
end end
trait :is_association do trait :is_association do

View file

@ -26,7 +26,7 @@
"code": null, "code": null,
"value": null "value": null
}, },
"diffusable_commercialement": null, "diffusable_commercialement": true,
"adresse": { "adresse": {
"l1": "OCTO TECHNOLOGY", "l1": "OCTO TECHNOLOGY",
"l2": null, "l2": null,

View file

@ -0,0 +1,49 @@
{
"etablissement": {
"siege_social": true,
"siret": "41816609600051",
"naf": "6202A",
"libelle_naf": "Conseil en systèmes et logiciels informatiques",
"date_mise_a_jour": 1449183600,
"tranche_effectif_salarie_etablissement": {
"de": 200,
"a": 249,
"code": "31",
"date_reference": "2014",
"intitule": "200 à 249 salariés"
},
"date_creation_etablissement": 1108594800,
"enseigne": null,
"region_implantation": {
"code": "11",
"value": "Île-de-France"
},
"commune_implantation": {
"code": "75108",
"value": "PARIS 8"
},
"pays_implantation": {
"code": null,
"value": null
},
"diffusable_commercialement": false,
"adresse": {
"l1": "OCTO TECHNOLOGY",
"l2": null,
"l3": null,
"l4": "50 AVENUE DES CHAMPS ELYSEES",
"l5": null,
"l6": "75008 PARIS",
"l7": "FRANCE",
"numero_voie": "50",
"type_voie": "AV",
"nom_voie": "DES CHAMPS ELYSEES",
"complement_adresse": "complement_adresse",
"code_postal": "75008",
"localite": "PARIS 8",
"code_insee_localite": "75108",
"cedex": null
}
},
"gateway_error": false
}

View file

@ -55,7 +55,7 @@ describe ApiEntreprise::API do
describe '.etablissement' do describe '.etablissement' do
subject { described_class.etablissement(siret, procedure_id) } subject { described_class.etablissement(siret, procedure_id) }
before do before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*token=/) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*non_diffusables=true&.*token=/)
.to_return(status: status, body: body) .to_return(status: status, body: body)
end end

View file

@ -3,7 +3,7 @@ require 'spec_helper'
describe ApiEntreprise::EtablissementAdapter do describe ApiEntreprise::EtablissementAdapter do
let(:procedure_id) { 33 } let(:procedure_id) { 33 }
context 'SIRET valide' do context 'SIRET valide avec infos diffusables' do
let(:siret) { '41816609600051' } let(:siret) { '41816609600051' }
subject { described_class.new(siret, procedure_id).to_params } subject { described_class.new(siret, procedure_id).to_params }
@ -33,6 +33,10 @@ describe ApiEntreprise::EtablissementAdapter do
expect(subject[:libelle_naf]).to eq('Conseil en systèmes et logiciels informatiques') expect(subject[:libelle_naf]).to eq('Conseil en systèmes et logiciels informatiques')
end end
it 'L\'entreprise contient bien un diffusable_commercialement qui vaut true' do
expect(subject[:diffusable_commercialement]).to eq(true)
end
context 'Concaténation lignes adresse' do context 'Concaténation lignes adresse' do
it 'L\'entreprise contient bien une adresse sur plusieurs lignes' do it 'L\'entreprise contient bien une adresse sur plusieurs lignes' do
expect(subject[:adresse]).to eq("OCTO TECHNOLOGY\r\n50 AVENUE DES CHAMPS ELYSEES\r\n75008 PARIS\r\nFRANCE") expect(subject[:adresse]).to eq("OCTO TECHNOLOGY\r\n50 AVENUE DES CHAMPS ELYSEES\r\n75008 PARIS\r\nFRANCE")
@ -70,6 +74,20 @@ describe ApiEntreprise::EtablissementAdapter do
end end
end end
context 'SIRET valide avec infos non diffusables' do
let(:siret) { '41816609600051' }
subject { described_class.new(siret, procedure_id).to_params }
before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*token=/)
.to_return(body: File.read('spec/fixtures/files/api_entreprise/etablissements_private.json', status: 200))
end
it 'L\'entreprise contient bien un diffusable_commercialement qui vaut false' do
expect(subject[:diffusable_commercialement]).to eq(false)
end
end
context 'when siret is not found' do context 'when siret is not found' do
let(:bad_siret) { 11_111_111_111_111 } let(:bad_siret) { 11_111_111_111_111 }
subject { described_class.new(bad_siret, 12).to_params } subject { described_class.new(bad_siret, 12).to_params }

View file

@ -12,4 +12,13 @@ describe 'shared/dossiers/identite_entreprise.html.haml', type: :view do
end end
end end
end end
context "for an entreprise with private infos" do
let(:etablissement) { create(:etablissement, :non_diffusable) }
it "displays only public infos" do
expect(rendered).to have_text(etablissement.entreprise_raison_sociale)
expect(rendered).not_to have_text(etablissement.entreprise.forme_juridique)
end
end
end end

View file

@ -29,6 +29,14 @@ describe 'users/dossiers/etablissement.html.haml', type: :view do
end end
end end
context 'etablissement avec infos non diffusables' do
let(:etablissement) { create(:etablissement, :with_exercices, :non_diffusable) }
it "affiche uniquement le nom de l'établissement si infos non diffusables" do
expect(rendered).to have_text(etablissement.entreprise_raison_sociale)
expect(rendered).not_to have_text(etablissement.entreprise.forme_juridique)
end
end
it 'prépare le footer' do it 'prépare le footer' do
expect(footer).to have_selector('footer') expect(footer).to have_selector('footer')
end end