diff --git a/app/controllers/backoffice/dossiers_list_controller.rb b/app/controllers/backoffice/dossiers_list_controller.rb index 4f81dcfb3..2797203ea 100644 --- a/app/controllers/backoffice/dossiers_list_controller.rb +++ b/app/controllers/backoffice/dossiers_list_controller.rb @@ -7,6 +7,11 @@ class Backoffice::DossiersListController < ApplicationController def index cookies[:liste] = param_liste + unless DossiersListGestionnaireService.dossiers_list_libelle.include?(param_liste) + cookies[:liste] = 'a_traiter' + return redirect_to backoffice_dossiers_path + end + dossiers_list_facade param_liste dossiers_list_facade.service.change_sort! param_sort unless params[:dossiers_smart_listing].nil? diff --git a/app/facades/dossier_facades.rb b/app/facades/dossier_facades.rb index 0c0ef95e0..04ded4fd9 100644 --- a/app/facades/dossier_facades.rb +++ b/app/facades/dossier_facades.rb @@ -23,7 +23,7 @@ class DossierFacades end def pieces_justificatives - @dossier.pieces_justificatives + @dossier.ordered_pieces_justificatives end def commentaires diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 003ff7267..0a1d9611a 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -84,6 +84,10 @@ class Dossier < ActiveRecord::Base champs_private.joins(', types_de_champ').where("champs.type_de_champ_id = types_de_champ.id AND types_de_champ.procedure_id = #{procedure.id}").order('order_place') end + def ordered_pieces_justificatives + champs.joins(', types_de_piece_justificative').where("pieces_justificatives.type_de_piece_justificative_id = types_de_piece_justificative.id AND types_de_piece_justificative.procedure_id = #{procedure.id}").order('order_place ASC') + end + def ordered_commentaires commentaires.order(created_at: :desc) end @@ -282,9 +286,14 @@ class Dossier < ActiveRecord::Base def as_csv(options={}) dossier_attr = DossierSerializer.new(self).attributes - etablissement_attr = EtablissementCsvSerializer.new(self.etablissement).attributes.map { |k, v| ["etablissement.#{k}", v] }.to_h - entreprise_attr = EntrepriseSerializer.new(self.entreprise).attributes.map { |k, v| ["entreprise.#{k}", v] }.to_h - dossier_attr.merge(etablissement_attr).merge(entreprise_attr) + + unless entreprise.nil? + etablissement_attr = EtablissementCsvSerializer.new(self.etablissement).attributes.map { |k, v| ["etablissement.#{k}", v] }.to_h + entreprise_attr = EntrepriseSerializer.new(self.entreprise).attributes.map { |k, v| ["entreprise.#{k}", v] }.to_h + dossier_attr = dossier_attr.merge(etablissement_attr).merge(entreprise_attr) + end + + dossier_attr end def reset! diff --git a/app/services/dossiers_list_gestionnaire_service.rb b/app/services/dossiers_list_gestionnaire_service.rb index 73d25c734..3ee079f1f 100644 --- a/app/services/dossiers_list_gestionnaire_service.rb +++ b/app/services/dossiers_list_gestionnaire_service.rb @@ -14,6 +14,10 @@ class DossiersListGestionnaireService 'termine' => termine}[@liste] end + def self.dossiers_list_libelle + ['nouveaux', 'a_traiter', 'en_attente', 'deposes', 'a_instruire', 'termine'] + end + def nouveaux @nouveaux ||= filter_dossiers.nouveaux end diff --git a/app/views/dossiers/_pieces_justificatives.html.haml b/app/views/dossiers/_pieces_justificatives.html.haml index 18fedcae7..824a41aa7 100644 --- a/app/views/dossiers/_pieces_justificatives.html.haml +++ b/app/views/dossiers/_pieces_justificatives.html.haml @@ -19,7 +19,7 @@ - else = 'Pièce non fournie' - - @facade.dossier.types_de_piece_justificative.each do |type_de_piece_justificative| + - @facade.dossier.types_de_piece_justificative.order('order_place ASC').each do |type_de_piece_justificative| %tr{ id: "piece_justificative_#{type_de_piece_justificative.id}" } %th.col-lg-6 = type_de_piece_justificative.libelle diff --git a/app/views/users/description/_pieces_justificatives.html.haml b/app/views/users/description/_pieces_justificatives.html.haml index 83e292f91..f8f076666 100644 --- a/app/views/users/description/_pieces_justificatives.html.haml +++ b/app/views/users/description/_pieces_justificatives.html.haml @@ -12,7 +12,7 @@ -else %input{type: 'file', name:'cerfa_pdf', id:'cerfa_pdf', accept: PieceJustificative.accept_format, :max_file_size => 3.megabytes } - - @dossier.types_de_piece_justificative.each do |type_de_piece_justificative| + - @dossier.types_de_piece_justificative.order('order_place ASC').each do |type_de_piece_justificative| %tr %th.col-lg-6 = type_de_piece_justificative.libelle diff --git a/spec/controllers/backoffice/dossiers_controller_spec.rb b/spec/controllers/backoffice/dossiers_controller_spec.rb index bcc763f42..61c5c0428 100644 --- a/spec/controllers/backoffice/dossiers_controller_spec.rb +++ b/spec/controllers/backoffice/dossiers_controller_spec.rb @@ -89,6 +89,19 @@ describe Backoffice::DossiersController, type: :controller do end end + describe 'GET #list_fake' do + context 'when gestionnaire is connected' do + before do + sign_in gestionnaire + end + + it 'returns http success' do + get :index, liste: :list_fake + expect(response).to redirect_to(backoffice_dossiers_path) + end + end + end + describe 'POST #search' do before do sign_in gestionnaire diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 8e5611f34..5fb127019 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -689,6 +689,13 @@ describe Dossier do it { expect(subject['entreprise.date_creation']).to eq('Thu, 28 Jan 2016 10:16:29 UTC +00:0') } it { expect(subject['entreprise.nom']).to be_nil } it { expect(subject['entreprise.prenom']).to be_nil } + + context 'when dossier does not have enterprise' do + let(:dossier) { create(:dossier, user: user, procedure: procedure) } + subject { dossier.as_csv } + + it { expect(subject[:archived]).to be_falsey } + end end describe '#reset!' do