Check if France Connect User is a mandataire social of the enterprise
This commit is contained in:
parent
3f048d0709
commit
332eab3771
4 changed files with 43 additions and 2 deletions
|
@ -34,6 +34,7 @@ class Users::DossiersController < UsersController
|
|||
entreprise = Entreprise.new(SIADE::EntrepriseAdapter.new(siren).to_params)
|
||||
rna_information = SIADE::RNAAdapter.new(siret).to_params
|
||||
exercices = SIADE::ExercicesAdapter.new(siret).to_params
|
||||
mandataires_sociaux = SIADE::MandatairesSociauxAdapter.new(siren).to_params
|
||||
|
||||
unless exercices.nil?
|
||||
exercices.each_value do |exercice|
|
||||
|
@ -42,8 +43,17 @@ class Users::DossiersController < UsersController
|
|||
exercice.save
|
||||
end
|
||||
end
|
||||
mandataire_social = false
|
||||
|
||||
dossier = Dossier.create(user: current_user, state: 'draft', procedure_id: create_params[:procedure_id])
|
||||
mandataires_sociaux.each do |k, mandataire|
|
||||
break mandataire_social = true if !current_user.france_connect_particulier_id.nil? &&
|
||||
mandataire[:nom] == current_user.family_name &&
|
||||
mandataire[:prenom] == current_user.given_name &&
|
||||
mandataire[:date_naissance_timestamp] == current_user.birthdate.to_time.to_i
|
||||
|
||||
end
|
||||
|
||||
dossier = Dossier.create(user: current_user, state: 'draft', procedure_id: create_params[:procedure_id], mandataire_social: mandataire_social)
|
||||
|
||||
entreprise.dossier = dossier
|
||||
entreprise.save
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddMandataireSocialToDossier < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :dossiers, :mandataire_social, :boolean, default: false
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20151223101322) do
|
||||
ActiveRecord::Schema.define(version: 20160106100227) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -69,6 +69,7 @@ ActiveRecord::Schema.define(version: 20151223101322) do
|
|||
t.integer "user_id"
|
||||
t.text "json_latlngs"
|
||||
t.boolean "archived", default: false
|
||||
t.boolean "mandataire_social", default: false
|
||||
end
|
||||
|
||||
add_index "dossiers", ["procedure_id"], name: "index_dossiers_on_procedure_id", using: :btree
|
||||
|
|
|
@ -86,6 +86,7 @@ describe Users::DossiersController, type: :controller do
|
|||
|
||||
describe 'dossier attributs' do
|
||||
let(:user) { create(:user) }
|
||||
|
||||
context 'with valid siret ' do
|
||||
before do
|
||||
sign_in user
|
||||
|
@ -140,6 +141,30 @@ describe Users::DossiersController, type: :controller do
|
|||
expect(Dossier.last.state).to eq('draft')
|
||||
end
|
||||
|
||||
describe 'Mandataires Sociaux' do
|
||||
let(:user) { create(:user, given_name: given_name, family_name: family_name, birthdate: birthdate, france_connect_particulier_id: '1234567') }
|
||||
|
||||
before do
|
||||
subject
|
||||
end
|
||||
|
||||
context 'when user is present in mandataires sociaux' do
|
||||
let(:given_name) { 'GERARD' }
|
||||
let(:family_name) { 'DEGONSE' }
|
||||
let(:birthdate) { '1947-07-03' }
|
||||
|
||||
it { expect(Dossier.last.mandataire_social).to be_truthy }
|
||||
end
|
||||
|
||||
context 'when user is not present in mandataires sociaux' do
|
||||
let(:given_name) { 'plop' }
|
||||
let(:family_name) { 'plip' }
|
||||
let(:birthdate) { '1965-01-27' }
|
||||
|
||||
it { expect(Dossier.last.mandataire_social).to be_falsey }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'get rna informations' do
|
||||
context 'when siren have not rna informations' do
|
||||
let(:rna_status) { 404 }
|
||||
|
|
Loading…
Reference in a new issue