store attestation sociale and display
This commit is contained in:
parent
d74b14c205
commit
158b4802ab
9 changed files with 44 additions and 4 deletions
|
@ -112,7 +112,9 @@ module Users
|
||||||
return render_siret_error(t('errors.messages.siret_unknown'))
|
return render_siret_error(t('errors.messages.siret_unknown'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
attestation_sociale_url = etablissement_attributes.delete(:entreprise_attestation_sociale_url)
|
||||||
etablissement = @dossier.build_etablissement(etablissement_attributes)
|
etablissement = @dossier.build_etablissement(etablissement_attributes)
|
||||||
|
etablissement.upload_attestation_sociale(attestation_sociale_url) if attestation_sociale_url.present?
|
||||||
etablissement.save!
|
etablissement.save!
|
||||||
current_user.update!(siret: sanitized_siret)
|
current_user.update!(siret: sanitized_siret)
|
||||||
@dossier.update!(autorisation_donnees: true)
|
@dossier.update!(autorisation_donnees: true)
|
||||||
|
|
|
@ -86,6 +86,6 @@ class ApiEntreprise::API
|
||||||
|
|
||||||
def self.token_for_procedure(procedure_id)
|
def self.token_for_procedure(procedure_id)
|
||||||
procedure = Procedure.find(procedure_id)
|
procedure = Procedure.find(procedure_id)
|
||||||
procedure.api_entreprise_token.presence || Rails.application.secrets.api_entreprise[:key]
|
procedure.api_entreprise_token
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,6 +4,8 @@ class Etablissement < ApplicationRecord
|
||||||
has_one :champ, class_name: 'Champs::SiretChamp'
|
has_one :champ, class_name: 'Champs::SiretChamp'
|
||||||
has_many :exercices, dependent: :destroy
|
has_many :exercices, dependent: :destroy
|
||||||
|
|
||||||
|
has_one_attached :entreprise_attestation_sociale
|
||||||
|
|
||||||
accepts_nested_attributes_for :exercices
|
accepts_nested_attributes_for :exercices
|
||||||
|
|
||||||
validates :siret, presence: true
|
validates :siret, presence: true
|
||||||
|
@ -114,6 +116,19 @@ class Etablissement < ApplicationRecord
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def upload_attestation_sociale(url)
|
||||||
|
filename = File.basename(URI.parse(url).path)
|
||||||
|
response = Typhoeus.get(url)
|
||||||
|
|
||||||
|
if response.success?
|
||||||
|
entreprise_attestation_sociale.attach(
|
||||||
|
io: StringIO.new(response.body),
|
||||||
|
filename: filename,
|
||||||
|
metadata: { virus_scan_result: ActiveStorage::VirusScanner::SAFE }
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def dossier_id_for_export
|
def dossier_id_for_export
|
||||||
|
|
|
@ -552,7 +552,11 @@ class Procedure < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def api_entreprise_role?(role)
|
def api_entreprise_role?(role)
|
||||||
api_entreprise_roles&.include?(role)
|
api_entreprise_roles.include?(role)
|
||||||
|
end
|
||||||
|
|
||||||
|
def api_entreprise_token
|
||||||
|
self[:api_entreprise_token].presence || Rails.application.secrets.api_entreprise[:key]
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -67,6 +67,10 @@
|
||||||
- elsif etablissement.exercices.present?
|
- elsif etablissement.exercices.present?
|
||||||
= t('activemodel.models.exercices_summary', count: etablissement.exercices.count)
|
= t('activemodel.models.exercices_summary', count: etablissement.exercices.count)
|
||||||
|
|
||||||
|
- if etablissement.entreprise_attestation_sociale.attached?
|
||||||
|
%tr
|
||||||
|
%th.libelle Attestation sociale
|
||||||
|
%td= link_to "Consulter l'attestation", url_for(etablissement.entreprise_attestation_sociale)
|
||||||
- if etablissement.association?
|
- if etablissement.association?
|
||||||
%tr
|
%tr
|
||||||
%th.libelle Numéro RNA :
|
%th.libelle Numéro RNA :
|
||||||
|
|
|
@ -221,6 +221,9 @@ describe Users::DossiersController, type: :controller do
|
||||||
let(:api_association_status) { 200 }
|
let(:api_association_status) { 200 }
|
||||||
let(:api_association_body) { File.read('spec/fixtures/files/api_entreprise/associations.json') }
|
let(:api_association_body) { File.read('spec/fixtures/files/api_entreprise/associations.json') }
|
||||||
|
|
||||||
|
let(:api_entreprise_attestation_sociale_status) { 200 }
|
||||||
|
let(:api_entreprise_attestation_sociale_body) { File.read('spec/fixtures/files/api_entreprise/attestation_sociale.json') }
|
||||||
|
|
||||||
def stub_api_entreprise_requests
|
def stub_api_entreprise_requests
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*token=/)
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*token=/)
|
||||||
.to_return(status: api_etablissement_status, body: api_etablissement_body)
|
.to_return(status: api_etablissement_status, body: api_etablissement_body)
|
||||||
|
@ -234,11 +237,16 @@ describe Users::DossiersController, type: :controller do
|
||||||
.to_return(body: api_entreprise_effectifs_mensuels_body, status: api_entreprise_effectifs_mensuels_status)
|
.to_return(body: api_entreprise_effectifs_mensuels_body, status: api_entreprise_effectifs_mensuels_status)
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_annuels_acoss_covid\/#{siren}?.*token=/)
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_annuels_acoss_covid\/#{siren}?.*token=/)
|
||||||
.to_return(body: api_entreprise_effectifs_annuels_body, status: api_entreprise_effectifs_annuels_status)
|
.to_return(body: api_entreprise_effectifs_annuels_body, status: api_entreprise_effectifs_annuels_status)
|
||||||
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_sociales_acoss\/#{siren}?.*token=/)
|
||||||
|
.to_return(body: api_entreprise_attestation_sociale_body, status: api_entreprise_attestation_sociale_status)
|
||||||
|
stub_request(:get, "https://storage.entreprise.api.gouv.fr/siade/1569156881-f749d75e2bfd443316e2e02d59015f-attestation_vigilance_acoss.pdf")
|
||||||
|
.to_return(body: "body attestation", status: 200)
|
||||||
end
|
end
|
||||||
|
|
||||||
before do
|
before do
|
||||||
sign_in(user)
|
sign_in(user)
|
||||||
stub_api_entreprise_requests
|
stub_api_entreprise_requests
|
||||||
|
allow_any_instance_of(Procedure).to receive(:api_entreprise_roles).and_return(["entreprises", "attestations_sociales"])
|
||||||
end
|
end
|
||||||
before { Timecop.freeze(Time.zone.local(2020, 3, 14)) }
|
before { Timecop.freeze(Time.zone.local(2020, 3, 14)) }
|
||||||
after { Timecop.return }
|
after { Timecop.return }
|
||||||
|
@ -334,6 +342,7 @@ describe Users::DossiersController, type: :controller do
|
||||||
expect(dossier.etablissement.association?).to be(true)
|
expect(dossier.etablissement.association?).to be(true)
|
||||||
expect(dossier.etablissement.entreprise_effectif_mensuel).to be_present
|
expect(dossier.etablissement.entreprise_effectif_mensuel).to be_present
|
||||||
expect(dossier.etablissement.entreprise_effectif_annuel).to be_present
|
expect(dossier.etablissement.entreprise_effectif_annuel).to be_present
|
||||||
|
expect(dossier.etablissement.entreprise_attestation_sociale).to be_attached
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -78,6 +78,7 @@ feature 'Creating a new dossier:' do
|
||||||
.to_return(status: 404, body: '')
|
.to_return(status: 404, body: '')
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_annuels_acoss_covid\/#{siren}?.*token=/)
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_annuels_acoss_covid\/#{siren}?.*token=/)
|
||||||
.to_return(status: 404, body: '')
|
.to_return(status: 404, body: '')
|
||||||
|
allow_any_instance_of(Procedure).to receive(:api_entreprise_roles).and_return([])
|
||||||
end
|
end
|
||||||
before { Timecop.freeze(Time.zone.local(2020, 3, 14)) }
|
before { Timecop.freeze(Time.zone.local(2020, 3, 14)) }
|
||||||
after { Timecop.return }
|
after { Timecop.return }
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
describe ApiEntreprise::AttestationSocialeAdapter do
|
describe ApiEntreprise::AttestationSocialeAdapter do
|
||||||
let(:siren) { '418166096' }
|
let(:siren) { '418166096' }
|
||||||
let(:procedure_id) { 22 }
|
let(:procedure) { create(:procedure) }
|
||||||
let(:adapter) { described_class.new(siren, procedure_id) }
|
let(:adapter) { described_class.new(siren, procedure.id) }
|
||||||
subject { adapter.to_params }
|
subject { adapter.to_params }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_sociales_acoss\/#{siren}?.*token=/)
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_sociales_acoss\/#{siren}?.*token=/)
|
||||||
.to_return(body: body, status: status)
|
.to_return(body: body, status: status)
|
||||||
|
allow_any_instance_of(Procedure).to receive(:api_entreprise_roles).and_return(["attestations_sociales"])
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when the SIREN is valid" do
|
context "when the SIREN is valid" do
|
||||||
|
|
|
@ -53,6 +53,10 @@ describe ApiEntrepriseService do
|
||||||
let(:procedure) { create(:procedure, api_entreprise_token: 'un-jeton') }
|
let(:procedure) { create(:procedure, api_entreprise_token: 'un-jeton') }
|
||||||
let(:result) { ApiEntrepriseService.get_etablissement_params_for_siret(siret, procedure.id) }
|
let(:result) { ApiEntrepriseService.get_etablissement_params_for_siret(siret, procedure.id) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
allow_any_instance_of(Procedure).to receive(:api_entreprise_roles).and_return(["attestations_sociales"])
|
||||||
|
end
|
||||||
|
|
||||||
context 'when service is up' do
|
context 'when service is up' do
|
||||||
it 'should fetch etablissement params' do
|
it 'should fetch etablissement params' do
|
||||||
expect(result[:entreprise_siren]).to eq(siren)
|
expect(result[:entreprise_siren]).to eq(siren)
|
||||||
|
|
Loading…
Reference in a new issue