From f9f313e990b449f4462b5ef452990cad358c14ba Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 6 Jul 2017 16:33:36 +0200 Subject: [PATCH] =?UTF-8?q?Add=20identit=C3=A9=20demandeur=20for=20entrepr?= =?UTF-8?q?ise=20on=20dossier=20detail=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/stylesheets/new_design/card.scss | 2 +- .../new_gestionnaire/dossiers_controller.rb | 6 +- .../dossiers/_identite_entreprise.html.haml | 49 ++++++++++ .../new_gestionnaire/dossiers/show.html.haml | 5 + .../procedures/_dossier_actions.html.haml | 8 +- .../procedures/show.html.haml | 6 +- config/routes.rb | 14 +-- .../dossiers_controller_spec.rb | 95 +++++++++++++------ 8 files changed, 139 insertions(+), 46 deletions(-) create mode 100644 app/views/new_gestionnaire/dossiers/_identite_entreprise.html.haml create mode 100644 app/views/new_gestionnaire/dossiers/show.html.haml diff --git a/app/assets/stylesheets/new_design/card.scss b/app/assets/stylesheets/new_design/card.scss index 1b5791288..c7c982d3c 100644 --- a/app/assets/stylesheets/new_design/card.scss +++ b/app/assets/stylesheets/new_design/card.scss @@ -17,6 +17,6 @@ .card-title { font-weight: bold; font-size: 20px; - margin-bottom: $default-spacer; + margin-bottom: $default-spacer * 2; } } diff --git a/app/controllers/new_gestionnaire/dossiers_controller.rb b/app/controllers/new_gestionnaire/dossiers_controller.rb index 2e29102ce..9d314106d 100644 --- a/app/controllers/new_gestionnaire/dossiers_controller.rb +++ b/app/controllers/new_gestionnaire/dossiers_controller.rb @@ -4,6 +4,10 @@ module NewGestionnaire send_data(dossier.attestation.pdf.read, filename: 'attestation.pdf', type: 'application/pdf') end + def show + @dossier = dossier + end + def follow current_gestionnaire.followed_dossiers << dossier redirect_back(fallback_location: procedures_url) @@ -27,7 +31,7 @@ module NewGestionnaire private def dossier - Dossier.find(params[:dossier_id]) + current_gestionnaire.dossiers.find(params[:dossier_id]) end end end diff --git a/app/views/new_gestionnaire/dossiers/_identite_entreprise.html.haml b/app/views/new_gestionnaire/dossiers/_identite_entreprise.html.haml new file mode 100644 index 000000000..6caa8fbba --- /dev/null +++ b/app/views/new_gestionnaire/dossiers/_identite_entreprise.html.haml @@ -0,0 +1,49 @@ +- entreprise = entreprise.decorate +- etablissement = entreprise.etablissement +%h4= entreprise.raison_sociale_or_name + +%table.table + %tbody + %tr + %th SIRET : + %td= entreprise.siret_siege_social + %tr + %th Forme juridique : + %td= entreprise.forme_juridique + - if etablissement.present? + %tr + %th Libellé NAF : + %td= etablissement.libelle_naf + %tr + %th Code NAF : + %td= etablissement.naf + %tr + %th Date de création : + %td= Time.at(entreprise.date_creation).localtime.strftime("%d/%m/%Y") + %tr + %th Effectif de l'organisation : + %td= entreprise.effectif + %tr + %th Code effectif : + %td= entreprise.code_effectif_entreprise + %tr + %th Numéro de TVA intracommunautaire : + %td= entreprise.numero_tva_intracommunautaire + - if etablissement.present? + %tr + %th Adresse : + %td + - etablissement.adresse.split("\n").each do |line| + = line + %br + %tr + %th Capital social : + %td= entreprise.pretty_capital_social + - if etablissement.present? + %tr + %th Exercices : + %td + - etablissement.exercices.each_with_index do |exercice, index| + = "#{exercice.dateFinExercice.year} : " + = number_to_currency(exercice.ca) + %br diff --git a/app/views/new_gestionnaire/dossiers/show.html.haml b/app/views/new_gestionnaire/dossiers/show.html.haml new file mode 100644 index 000000000..fd77534c8 --- /dev/null +++ b/app/views/new_gestionnaire/dossiers/show.html.haml @@ -0,0 +1,5 @@ +.container + .card + .card-title Identité du demandeur + - if @dossier.entreprise.present? + = render partial: "identite_entreprise", locals: { entreprise: @dossier.entreprise } diff --git a/app/views/new_gestionnaire/procedures/_dossier_actions.html.haml b/app/views/new_gestionnaire/procedures/_dossier_actions.html.haml index d3fb1feb9..608671c6e 100644 --- a/app/views/new_gestionnaire/procedures/_dossier_actions.html.haml +++ b/app/views/new_gestionnaire/procedures/_dossier_actions.html.haml @@ -1,19 +1,19 @@ - if dossier.en_construction_ou_instruction? - if current_gestionnaire.follow?(dossier) - = link_to dossier_unfollow_path(procedure, dossier), method: :patch, class: 'button' do + = link_to unfollow_dossier_path(procedure, dossier), method: :patch, class: 'button' do %i.unfollow> ne plus suivre - else - = link_to dossier_follow_path(procedure, dossier), method: :patch, class: 'button' do + = link_to follow_dossier_path(procedure, dossier), method: :patch, class: 'button' do %i.follow> suivre le dossier - elsif dossier.termine? - if dossier.archived - = link_to dossier_unarchive_path(procedure, dossier), method: :patch, class: 'button' do + = link_to unarchive_dossier_path(procedure, dossier), method: :patch, class: 'button' do %i.unarchive> désarchiver le dossier - else - = link_to dossier_archive_path(procedure, dossier), method: :patch, class: 'button' do + = link_to archive_dossier_path(procedure, dossier), method: :patch, class: 'button' do %i.archive> archiver le dossier diff --git a/app/views/new_gestionnaire/procedures/show.html.haml b/app/views/new_gestionnaire/procedures/show.html.haml index 4b240158c..a8de5fff6 100644 --- a/app/views/new_gestionnaire/procedures/show.html.haml +++ b/app/views/new_gestionnaire/procedures/show.html.haml @@ -42,10 +42,10 @@ %th.follow-col - @dossiers.each do |dossier| %tr - %td.number-col= link_to(dossier.id, backoffice_dossier_path(dossier), class: 'big-link') - %td= link_to(dossier.user.email, backoffice_dossier_path(dossier), class: 'big-link') + %td.number-col= link_to(dossier.id, dossier_path(@procedure, dossier), class: 'big-link') + %td= link_to(dossier.user.email, dossier_path(@procedure, dossier), class: 'big-link') %td.status-col - = link_to(backoffice_dossier_path(dossier), class: 'big-link') do + = link_to(dossier_path(@procedure, dossier), class: 'big-link') do = render partial: 'status', locals: { dossier: dossier } %td.follow-col= render partial: 'dossier_actions', locals: { procedure: @procedure, dossier: dossier } - else diff --git a/config/routes.rb b/config/routes.rb index 8ff672bb3..b275f6afe 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -240,12 +240,14 @@ Rails.application.routes.draw do scope module: 'new_gestionnaire' do resources :procedures, only: [:index, :show], param: :procedure_id do member do - resources :dossiers, only: [] do - get 'attestation' - patch 'follow' - patch 'unfollow' - patch 'archive' - patch 'unarchive' + resources :dossiers, only: [:show], param: :dossier_id do + member do + get 'attestation' + patch 'follow' + patch 'unfollow' + patch 'archive' + patch 'unarchive' + end end end end diff --git a/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb b/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb index 51100ab65..6d967184a 100644 --- a/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb +++ b/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb @@ -3,14 +3,16 @@ require 'spec_helper' describe NewGestionnaire::DossiersController, type: :controller do let(:gestionnaire) { create(:gestionnaire) } let(:procedure) { create(:procedure, gestionnaires: [gestionnaire]) } - let(:dossier) { create(:dossier, procedure: procedure) } - - before { sign_in(gestionnaire) } + let(:dossier) { create(:dossier, :replied, procedure: procedure) } describe 'attestation' do + before { sign_in(gestionnaire) } + context 'when a dossier has an attestation' do let(:fake_pdf) { double(read: 'pdf content') } - let!(:dossier) { create(:dossier, attestation: Attestation.new, procedure: procedure) } + let!(:dossier) { create(:dossier, :replied, attestation: Attestation.new, procedure: procedure) } + let!(:procedure) { create(:procedure, gestionnaires: [gestionnaire]) } + let!(:dossier) { create(:dossier, :replied, attestation: Attestation.new, procedure: procedure) } it 'returns the attestation pdf' do allow_any_instance_of(Attestation).to receive(:pdf).and_return(fake_pdf) @@ -26,42 +28,73 @@ describe NewGestionnaire::DossiersController, type: :controller do end end - describe 'follow' do - before { patch :follow, params: { procedure_id: procedure.id, dossier_id: dossier.id } } + context "when gestionnaire is signed in" do + before { sign_in(gestionnaire) } - it { expect(gestionnaire.followed_dossiers).to match([dossier]) } - it { expect(response).to redirect_to(procedures_url) } - end - describe 'unfollow' do - before do - gestionnaire.followed_dossiers << dossier - patch :unfollow, params: { procedure_id: procedure.id, dossier_id: dossier.id } - gestionnaire.reload + describe 'follow' do + before { patch :follow, params: { procedure_id: procedure.id, dossier_id: dossier.id } } + + it { expect(gestionnaire.followed_dossiers).to match([dossier]) } + it { expect(response).to redirect_to(procedures_url) } end - it { expect(gestionnaire.followed_dossiers).to match([]) } - it { expect(response).to redirect_to(procedures_url) } - end + describe 'unfollow' do + before do + gestionnaire.followed_dossiers << dossier + patch :unfollow, params: { procedure_id: procedure.id, dossier_id: dossier.id } + gestionnaire.reload + end - describe 'archive' do - before do - patch :archive, params: { procedure_id: procedure.id, dossier_id: dossier.id } - dossier.reload + it { expect(gestionnaire.followed_dossiers).to match([]) } + it { expect(response).to redirect_to(procedures_url) } end - it { expect(dossier.archived).to be true } - it { expect(response).to redirect_to(procedures_url) } - end + describe 'archive' do + before do + patch :archive, params: { procedure_id: procedure.id, dossier_id: dossier.id } + dossier.reload + end - describe 'unarchive' do - before do - dossier.update_attributes(archived: true) - patch :unarchive, params: { procedure_id: procedure.id, dossier_id: dossier.id } - dossier.reload + it { expect(dossier.archived).to be true } + it { expect(response).to redirect_to(procedures_url) } end - it { expect(dossier.archived).to be false } - it { expect(response).to redirect_to(procedures_url) } + describe 'unarchive' do + before do + dossier.update_attributes(archived: true) + patch :unarchive, params: { procedure_id: procedure.id, dossier_id: dossier.id } + dossier.reload + end + + it { expect(dossier.archived).to be false } + it { expect(response).to redirect_to(procedures_url) } + end + end + + describe "#show" do + let(:procedure) { create(:procedure, gestionnaires: [gestionnaire]) } + let(:dossier){ create(:dossier, :replied, procedure: procedure) } + + subject { get :show, params: { procedure_id: procedure.id, dossier_id: dossier.id } } + + context "when gestionnaire is not logged in" do + before { subject } + it { expect(response).to redirect_to(new_user_session_path) } + end + + context "when gestionnaire is logged in" do + before { sign_in(gestionnaire) } + + it do + subject + expect(response).to have_http_status(:success) + end + + context "when gestionnaire is not affected on procedure" do + let(:dossier){ create(:dossier, :replied) } + it { expect{ subject }.to raise_error(ActiveRecord::RecordNotFound) } + end + end end end