From aa3b1e974d195abccf36a4e6626d43605919ccf9 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Wed, 5 Oct 2016 10:48:11 +0200 Subject: [PATCH 1/3] =?UTF-8?q?Can=20create=20proc=C3=A9dure=20individual?= =?UTF-8?q?=20with=20SIRET=20for=20later?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/javascripts/procedure.js | 11 ++++++++++ app/assets/stylesheets/procedure.scss | 4 ++++ .../admin/procedures_controller.rb | 2 +- .../admin/procedures/_informations.html.haml | 21 ++++++++++++------- ..._add_individual_with_siret_in_procedure.rb | 5 +++++ db/schema.rb | 17 ++++++++------- 6 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 db/migrate/20161005082113_add_individual_with_siret_in_procedure.rb diff --git a/app/assets/javascripts/procedure.js b/app/assets/javascripts/procedure.js index 875e5f504..b3fa21dd3 100644 --- a/app/assets/javascripts/procedure.js +++ b/app/assets/javascripts/procedure.js @@ -4,6 +4,7 @@ $(document).ready(button_edit_procedure_init); function button_edit_procedure_init(){ buttons_api_carto(); button_cerfa(); + button_individual(); } function buttons_api_carto () { @@ -24,4 +25,14 @@ function button_cerfa () { if ($('#procedure_cerfa_flag').is(':checked')) $("#procedure_lien_demarche").show(); +} + +function button_individual () { + + $("#procedure_for_individual").on('change', function() { + $("#individual_with_siret").toggle() + }); + + if ($('#procedure_for_individual').is(':checked')) + $("#individual_with_siret").show(); } \ No newline at end of file diff --git a/app/assets/stylesheets/procedure.scss b/app/assets/stylesheets/procedure.scss index c35fb74aa..95cb96de8 100644 --- a/app/assets/stylesheets/procedure.scss +++ b/app/assets/stylesheets/procedure.scss @@ -4,4 +4,8 @@ #procedure_lien_demarche{ display: none; +} + +#individual_with_siret { + display: none; } \ No newline at end of file diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index 3c5e013e8..0e51c2097 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -187,7 +187,7 @@ class Admin::ProceduresController < AdminController private def create_procedure_params - params.require(:procedure).permit(:libelle, :description, :organisation, :direction, :lien_demarche, :lien_site_web, :lien_notice, :euro_flag, :logo, :cerfa_flag, :for_individual, module_api_carto_attributes: [:id, :use_api_carto, :quartiers_prioritaires, :cadastre]).merge(administrateur_id: current_administrateur.id) + params.require(:procedure).permit(:libelle, :description, :organisation, :direction, :lien_demarche, :lien_site_web, :lien_notice, :euro_flag, :logo, :cerfa_flag, :for_individual, :individual_with_siret, module_api_carto_attributes: [:id, :use_api_carto, :quartiers_prioritaires, :cadastre]).merge(administrateur_id: current_administrateur.id) end def create_module_api_carto_params diff --git a/app/views/admin/procedures/_informations.html.haml b/app/views/admin/procedures/_informations.html.haml index 7c14e2941..d22e32166 100644 --- a/app/views/admin/procedures/_informations.html.haml +++ b/app/views/admin/procedures/_informations.html.haml @@ -25,7 +25,7 @@ %h4 Drapeau européen %label =f.check_box :euro_flag - Afficher le drapeau européen + Afficher le drapeau européen %br @@ -60,9 +60,16 @@ .row .col-md-6.col-lg-6 %h4 Particuliers - %label - =f.check_box :for_individual - Cette procédure s'adresse à un public qui - %b - ne possède pas de numéro SIRET, - qui doivent donc s'identifier en tant que personne physique. + %div + %label + =f.check_box :for_individual + Cette procédure s'adresse à un public qui + %b + ne possède pas (ou pas encore) de numéro SIRET, + qui doivent donc s'identifier en tant que personne physique. + + %ul#individual_with_siret{style:'margin-top: 8px'} + %li + %label + =f.check_box :individual_with_siret + Donner la possibilité de renseigner un SIRET au cours de la construction du dossier. diff --git a/db/migrate/20161005082113_add_individual_with_siret_in_procedure.rb b/db/migrate/20161005082113_add_individual_with_siret_in_procedure.rb new file mode 100644 index 000000000..408a7c13f --- /dev/null +++ b/db/migrate/20161005082113_add_individual_with_siret_in_procedure.rb @@ -0,0 +1,5 @@ +class AddIndividualWithSiretInProcedure < ActiveRecord::Migration + def change + add_column :procedures, :individual_with_siret, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 09ad2760b..7c51cbbe0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20161004175442) do +ActiveRecord::Schema.define(version: 20161005082113) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -282,19 +282,20 @@ ActiveRecord::Schema.define(version: 20161004175442) do t.string "organisation" t.string "direction" t.string "lien_demarche" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.boolean "test" t.integer "administrateur_id" - t.boolean "archived", default: false - t.boolean "euro_flag", default: false + t.boolean "archived", default: false + t.boolean "euro_flag", default: false t.string "logo" - t.boolean "cerfa_flag", default: false + t.boolean "cerfa_flag", default: false t.string "logo_secure_token" - t.boolean "published", default: false, null: false + t.boolean "published", default: false, null: false t.string "lien_site_web" t.string "lien_notice" - t.boolean "for_individual", default: false + t.boolean "for_individual", default: false + t.boolean "individual_with_siret", default: false end create_table "quartier_prioritaires", force: :cascade do |t| From 8160d4d0dfeec55bdddba5d2840765d8b9a79682 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Wed, 5 Oct 2016 14:28:10 +0200 Subject: [PATCH 2/3] User can be add siret when is procedure at the attribut individual and individual_with_siret --- .../users/dossiers/add_siret_controller.rb | 13 ++++++++++ app/controllers/users/dossiers_controller.rb | 12 +++++++-- app/models/dossier.rb | 5 ++-- app/models/entreprise.rb | 1 + app/models/etablissement.rb | 2 ++ app/views/backoffice/dossiers/show.html.haml | 2 +- app/views/dossiers/_infos_dossier.html.haml | 3 +++ app/views/dossiers/add_siret.js.erb | 12 +++++++++ app/views/dossiers/new_siret.js.erb | 1 - .../users/dossiers/add_siret/show.html.haml | 2 ++ config/routes.rb | 2 ++ .../dossiers/add_siret_controller_spec.rb | 25 +++++++++++++++++++ .../recapitulatif/show.html.haml_spec.rb | 8 +++++- 13 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 app/controllers/users/dossiers/add_siret_controller.rb create mode 100644 app/views/dossiers/add_siret.js.erb create mode 100644 app/views/users/dossiers/add_siret/show.html.haml create mode 100644 spec/controllers/users/dossiers/add_siret_controller_spec.rb diff --git a/app/controllers/users/dossiers/add_siret_controller.rb b/app/controllers/users/dossiers/add_siret_controller.rb new file mode 100644 index 000000000..5e6591197 --- /dev/null +++ b/app/controllers/users/dossiers/add_siret_controller.rb @@ -0,0 +1,13 @@ +class Users::Dossiers::AddSiretController < ApplicationController + def show + @facade = DossierFacades.new params[:dossier_id], current_user.email + + raise ActiveRecord::RecordNotFound unless @facade.procedure.individual_with_siret? + + @siret = current_user.siret unless current_user.siret.nil? + + rescue ActiveRecord::RecordNotFound + flash.alert = t('errors.messages.dossier_not_found') + redirect_to url_for users_dossiers_path + end +end \ No newline at end of file diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index bf81eae8c..a0dac2e30 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -65,8 +65,12 @@ class Users::DossiersController < UsersController end @facade = facade params[:dossier_id] - render '/dossiers/new_siret', formats: 'js' + if @facade.procedure.individual_with_siret? + render '/dossiers/add_siret', formats: 'js' + else + render '/dossiers/new_siret', formats: 'js' + end rescue RestClient::ResourceNotFound, RestClient::BadRequest errors_valid_siret @@ -80,7 +84,11 @@ class Users::DossiersController < UsersController @facade = facade params[:dossier_id] - render '/dossiers/new_siret', formats: :js + if @facade.procedure.individual_with_siret? + render '/dossiers/add_siret', formats: 'js' + else + render '/dossiers/new_siret', formats: 'js' + end end def update diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 9306e2e3e..3a17e04a7 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -73,8 +73,6 @@ class Dossier < ActiveRecord::Base def build_default_individual Individual.new(dossier_id: id).save(validate: false) - Entreprise.new(dossier_id: id).save(validate: false) - Etablissement.new(dossier_id: id, entreprise_id: entreprise.id).save(validate: false) end def ordered_champs @@ -289,7 +287,8 @@ class Dossier < ActiveRecord::Base end def reset! - entreprise.destroy unless entreprise.nil? + entreprise.destroy + etablissement.destroy update_attributes(autorisation_donnees: false) end diff --git a/app/models/entreprise.rb b/app/models/entreprise.rb index 8218f75e4..5e24a31bb 100644 --- a/app/models/entreprise.rb +++ b/app/models/entreprise.rb @@ -4,6 +4,7 @@ class Entreprise < ActiveRecord::Base has_one :rna_information, dependent: :destroy validates_presence_of :siren + validates_uniqueness_of :dossier_id before_save :default_values diff --git a/app/models/etablissement.rb b/app/models/etablissement.rb index 9d09b9787..44e840205 100644 --- a/app/models/etablissement.rb +++ b/app/models/etablissement.rb @@ -4,6 +4,8 @@ class Etablissement < ActiveRecord::Base has_many :exercices, dependent: :destroy + validates_uniqueness_of :dossier_id + def geo_adresse [numero_voie, type_voie, nom_voie, complement_adresse, code_postal, localite].join(' ') end diff --git a/app/views/backoffice/dossiers/show.html.haml b/app/views/backoffice/dossiers/show.html.haml index 6eaa95dde..9d0288dd9 100644 --- a/app/views/backoffice/dossiers/show.html.haml +++ b/app/views/backoffice/dossiers/show.html.haml @@ -7,7 +7,7 @@ = @facade.dossier.display_state = render partial: 'follow_action' - - unless @facade.procedure.for_individual? + - unless @facade.entreprise.nil? = render partial: '/dossiers/infos_entreprise' = render partial: '/dossiers/infos_dossier' diff --git a/app/views/dossiers/_infos_dossier.html.haml b/app/views/dossiers/_infos_dossier.html.haml index 539f09e05..2b349ef4b 100644 --- a/app/views/dossiers/_infos_dossier.html.haml +++ b/app/views/dossiers/_infos_dossier.html.haml @@ -54,6 +54,9 @@ = render partial: 'users/recapitulatif/modal_upload_pj' + -if @facade.procedure.individual_with_siret + %a#add_siret.btn.btn-success{href: users_dossier_add_siret_path(dossier_id: @facade.dossier.id)} + = "Renseigner un SIRET" -if @facade.dossier.procedure.module_api_carto.use_api_carto %a#maj_carte.btn.btn-primary{href: "/users/dossiers/#{@facade.dossier.id}/carte"} = 'Modifier la carte' diff --git a/app/views/dossiers/add_siret.js.erb b/app/views/dossiers/add_siret.js.erb new file mode 100644 index 000000000..72bb92d20 --- /dev/null +++ b/app/views/dossiers/add_siret.js.erb @@ -0,0 +1,12 @@ +<% if flash.empty? %> +$('.row.etape.etape_2').hide(300, render_new_siret); +$('.row.etape.etape_2').slideDown(400, the_terms); +<% else %> +error_form_siret('<%= invalid_siret %>'); +<% end %> + +<% flash.clear %> + +function render_new_siret(){ + $('.row.etape.etape_2').html("<%= escape_javascript(render partial: '/dossiers/etapes/etape_2/entreprise', locals: { facade: @facade } ) %>"); +} \ No newline at end of file diff --git a/app/views/dossiers/new_siret.js.erb b/app/views/dossiers/new_siret.js.erb index c3d7503cf..dcb6ce2b2 100644 --- a/app/views/dossiers/new_siret.js.erb +++ b/app/views/dossiers/new_siret.js.erb @@ -8,7 +8,6 @@ error_form_siret('<%= invalid_siret %>'); <% flash.clear %> - function render_new_siret(){ $('.row.etape.etape_2').html("<%= escape_javascript(render partial: '/dossiers/etapes/etape2', locals: { facade: @facade } ) %>"); } \ No newline at end of file diff --git a/app/views/users/dossiers/add_siret/show.html.haml b/app/views/users/dossiers/add_siret/show.html.haml new file mode 100644 index 000000000..56d7c3162 --- /dev/null +++ b/app/views/users/dossiers/add_siret/show.html.haml @@ -0,0 +1,2 @@ +.row.etape.etape_2 + = render partial: 'dossiers/etapes/etape_2/entreprise' \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 8fe43d22d..744c3ea61 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -62,6 +62,8 @@ Rails.application.routes.draw do end resources :dossiers do + get '/add_siret' => 'dossiers/add_siret#show' + get '/description' => 'description#show' get '/description/error' => 'description#error' post 'description' => 'description#create' diff --git a/spec/controllers/users/dossiers/add_siret_controller_spec.rb b/spec/controllers/users/dossiers/add_siret_controller_spec.rb new file mode 100644 index 000000000..44083e035 --- /dev/null +++ b/spec/controllers/users/dossiers/add_siret_controller_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +describe Users::Dossiers::AddSiretController, type: :controller do + describe '#GET show' do + + let(:dossier) { create :dossier } + + before do + sign_in dossier.user + end + + subject { get :show, dossier_id: dossier.id } + + context 'when dossier is not attached at a procedure with individual siret attribut' do + it { is_expected.to redirect_to users_dossiers_path } + end + + context 'when dossier is attached at a procedure with individual siret attribut' do + let(:procedure) { create :procedure, individual_with_siret: true } + let(:dossier) { create :dossier, procedure: procedure } + + it { expect(subject.status).to eq 200 } + end + end +end diff --git a/spec/views/users/recapitulatif/show.html.haml_spec.rb b/spec/views/users/recapitulatif/show.html.haml_spec.rb index f5a7bd92a..e70e3723b 100644 --- a/spec/views/users/recapitulatif/show.html.haml_spec.rb +++ b/spec/views/users/recapitulatif/show.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe 'users/recapitulatif/show.html.haml', type: :view do - let(:dossier) { create(:dossier, :with_entreprise, state: state, procedure: create(:procedure, :with_api_carto, :with_two_type_de_piece_justificative)) } + let(:dossier) { create(:dossier, :with_entreprise, state: state, procedure: create(:procedure, :with_api_carto, :with_two_type_de_piece_justificative, for_individual: true, individual_with_siret: true)) } let(:dossier_id) { dossier.id } let(:state) { 'draft' } @@ -46,6 +46,12 @@ describe 'users/recapitulatif/show.html.haml', type: :view do end end + context 'lien carte' do + it 'le lien vers le renseignement un SIRET est présent' do + expect(rendered).to have_css('#add_siret') + end + end + context 'lien carte' do it 'le lien vers carte est présent' do expect(rendered).to have_css('#maj_carte') From d78b64982ba4b65b6e7ec4f1ce710a407724a82f Mon Sep 17 00:00:00 2001 From: Xavier J Date: Wed, 5 Oct 2016 15:01:31 +0200 Subject: [PATCH 3/3] Fix tests --- app/models/dossier.rb | 2 +- app/models/type_de_champ.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 3a17e04a7..47a28e823 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -287,8 +287,8 @@ class Dossier < ActiveRecord::Base end def reset! - entreprise.destroy etablissement.destroy + entreprise.destroy update_attributes(autorisation_donnees: false) end diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 91ae22e30..027c6cf13 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -28,7 +28,7 @@ class TypeDeChamp < ActiveRecord::Base before_validation :change_header_section_mandatory def self.type_de_champs_list_fr - type_champs.map { |champ| [ I18n.t("activerecord.attributes.type_de_champ.type_champs.#{champ.last}"), champ.first ] } + type_champs.map { |champ| [I18n.t("activerecord.attributes.type_de_champ.type_champs.#{champ.last}"), champ.first] } end def field_for_list? @@ -37,5 +37,6 @@ class TypeDeChamp < ActiveRecord::Base def change_header_section_mandatory self.mandatory = false if self.type_champ == 'header_section' + true end end \ No newline at end of file