From fe6f6ebad35b861ba15f86e3172f956b0eaf5079 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Tue, 11 Oct 2016 18:05:49 +0200 Subject: [PATCH] Bug fix cookie for user --- .../backoffice/dossiers_list_controller.rb | 2 +- app/controllers/users/dossiers_controller.rb | 14 +++++++++++--- app/services/dossiers_list_gestionnaire_service.rb | 2 +- app/services/dossiers_list_user_service.rb | 4 ++++ spec/controllers/users/dossiers_controller_spec.rb | 14 ++++++++++++++ 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/app/controllers/backoffice/dossiers_list_controller.rb b/app/controllers/backoffice/dossiers_list_controller.rb index 535056b0c..9a98d7e45 100644 --- a/app/controllers/backoffice/dossiers_list_controller.rb +++ b/app/controllers/backoffice/dossiers_list_controller.rb @@ -7,7 +7,7 @@ class Backoffice::DossiersListController < ApplicationController def index cookies[:liste] = param_liste - unless DossiersListGestionnaireService.dossiers_list_libelle.include?(param_liste) + unless DossiersListGestionnaireService.dossiers_liste_libelle.include?(param_liste) cookies[:liste] = 'a_traiter' return redirect_to backoffice_dossiers_path end diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 91020bc73..83a12d83b 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -10,10 +10,14 @@ class Users::DossiersController < UsersController end def index - liste = params[:liste] || cookies[:liste] || 'a_traiter' - cookies[:liste] = liste + cookies[:liste] = param_liste - @dossiers_list_facade = DossiersListFacades.new current_user, liste + @dossiers_list_facade = DossiersListFacades.new current_user, param_liste + + unless DossiersListUserService.dossiers_liste_libelle.include?(param_liste) + cookies[:liste] = 'a_traiter' + return redirect_to users_dossiers_path + end @dossiers = smart_listing_create :dossiers, @dossiers_list_facade.dossiers_to_display, @@ -169,4 +173,8 @@ class Users::DossiersController < UsersController def facade id = params[:id] DossierFacades.new id, current_user.email end + + def param_liste + @liste ||= params[:liste] || cookies[:liste] || 'a_traiter' + end end diff --git a/app/services/dossiers_list_gestionnaire_service.rb b/app/services/dossiers_list_gestionnaire_service.rb index 5ed7a7419..ee5620f98 100644 --- a/app/services/dossiers_list_gestionnaire_service.rb +++ b/app/services/dossiers_list_gestionnaire_service.rb @@ -14,7 +14,7 @@ class DossiersListGestionnaireService 'termine' => termine}[@liste] end - def self.dossiers_list_libelle + def self.dossiers_liste_libelle ['nouveaux', 'a_traiter', 'en_attente', 'deposes', 'a_instruire', 'termine'] end diff --git a/app/services/dossiers_list_user_service.rb b/app/services/dossiers_list_user_service.rb index 784232cbb..429497fa6 100644 --- a/app/services/dossiers_list_user_service.rb +++ b/app/services/dossiers_list_user_service.rb @@ -15,6 +15,10 @@ class DossiersListUserService 'invite' => invite}[@liste] end + def self.dossiers_liste_libelle + ['brouillon', 'nouveaux', 'a_traiter', 'en_attente', 'valides', 'en_instruction', 'termine', 'invite'] + end + def brouillon @brouillon ||= @current_devise_profil.dossiers.brouillon end diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index 8234c3668..58ff40a4b 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -456,4 +456,18 @@ describe Users::DossiersController, type: :controller do end end end + + describe 'GET #list_fake' do + context 'when user is connected' do + before do + sign_in user + end + + it 'returns http success' do + get :index, liste: :list_fake + expect(response).to redirect_to(users_dossiers_path) + end + end + end + end \ No newline at end of file