From 642dc4ba21194f12a75b0796e40b04f3b801145b Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Tue, 19 Dec 2017 15:08:08 +0100 Subject: [PATCH] [Fix #1118] New ui is the default ui for gestionnaire --- app/controllers/backoffice/avis_controller.rb | 2 +- .../gestionnaires/sessions_controller.rb | 5 ---- app/controllers/root_controller.rb | 27 +++++-------------- app/controllers/users/sessions_controller.rb | 2 +- app/views/layouts/_navbar.html.haml | 2 +- .../_switch_devise_profile_module.html.haml | 2 +- .../backoffice/avis_controller_spec.rb | 2 +- spec/controllers/root_controller_spec.rb | 21 +++++---------- spec/features/backoffice/connection_spec.rb | 4 +-- .../backoffice/navigate_to_dossier_spec.rb | 1 + .../new_gestionnaire/gestionnaire_spec.rb | 11 ++------ 11 files changed, 24 insertions(+), 55 deletions(-) diff --git a/app/controllers/backoffice/avis_controller.rb b/app/controllers/backoffice/avis_controller.rb index d2375e74f..f524fd4a8 100644 --- a/app/controllers/backoffice/avis_controller.rb +++ b/app/controllers/backoffice/avis_controller.rb @@ -39,7 +39,7 @@ class Backoffice::AvisController < ApplicationController sign_in(gestionnaire, scope: :gestionnaire) Avis.link_avis_to_gestionnaire(gestionnaire) avis = Avis.find(params[:id]) - redirect_to url_for(backoffice_dossier_path(avis.dossier_id)) + redirect_to url_for(avis_index_path) else flash[:alert] = gestionnaire.errors.full_messages redirect_to url_for(avis_sign_up_path(params[:id], email)) diff --git a/app/controllers/gestionnaires/sessions_controller.rb b/app/controllers/gestionnaires/sessions_controller.rb index 5a872c234..ed49b6185 100644 --- a/app/controllers/gestionnaires/sessions_controller.rb +++ b/app/controllers/gestionnaires/sessions_controller.rb @@ -8,9 +8,4 @@ class Gestionnaires::SessionsController < Sessions::SessionsController def create super end - - def after_sign_in_path_for(resource) - # stored_location_for(resource) || - backoffice_path - end end diff --git a/app/controllers/root_controller.rb b/app/controllers/root_controller.rb index 0cd686880..ab0e25c4a 100644 --- a/app/controllers/root_controller.rb +++ b/app/controllers/root_controller.rb @@ -2,32 +2,19 @@ class RootController < ApplicationController layout 'new_application' def index - if params[:new_ui] && gestionnaire_signed_in? # TODO delete new_ui when old UI is no longer used + # TODO delete new_ui when old UI is no longer used + if params[:new_ui].present? && gestionnaire_signed_in? return redirect_to procedures_path - end - - if administrateur_signed_in? + elsif administrateur_signed_in? return redirect_to admin_procedures_path - elsif gestionnaire_signed_in? - return redirect_to backoffice_invitations_path if current_gestionnaire.avis.any? - - procedure_id = current_gestionnaire.procedure_filter - if procedure_id.nil? - procedure_list = current_gestionnaire.procedures - - if procedure_list.count > 0 - return redirect_to backoffice_dossiers_procedure_path(id: procedure_list.first.id) - else - flash.alert = "Vous n'avez aucune procédure d'affectée" - end - else - return redirect_to backoffice_dossiers_procedure_path(id: procedure_id) + # to be removed when old ui is deleted + if params[:old_ui].present? + return redirect_to backoffice_path end - + return redirect_to procedures_path elsif user_signed_in? return redirect_to users_dossiers_path - elsif administration_signed_in? return redirect_to administrations_path end diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index b0c4743de..8c20bfdd8 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -26,7 +26,7 @@ class Users::SessionsController < Sessions::SessionsController if user_signed_in? redirect_to after_sign_in_path_for(:user) elsif gestionnaire_signed_in? - location = stored_location_for(:gestionnaire) || backoffice_path + location = stored_location_for(:gestionnaire) || procedures_path redirect_to location elsif administrateur_signed_in? redirect_to admin_path diff --git a/app/views/layouts/_navbar.html.haml b/app/views/layouts/_navbar.html.haml index d3d3e9db5..bc460d165 100644 --- a/app/views/layouts/_navbar.html.haml +++ b/app/views/layouts/_navbar.html.haml @@ -1,5 +1,5 @@ .col-xs-2 - %a#title-navbar{ href: '/' } + %a#title-navbar{ href: root_path(old_ui: 1) } .row#home .col-lg-6.no-padding = image_tag('marianne_small.png', class: 'logo') diff --git a/app/views/layouts/_switch_devise_profile_module.html.haml b/app/views/layouts/_switch_devise_profile_module.html.haml index ab51a0053..b8b0de852 100644 --- a/app/views/layouts/_switch_devise_profile_module.html.haml +++ b/app/views/layouts/_switch_devise_profile_module.html.haml @@ -12,7 +12,7 @@ Usager - if gestionnaire_signed_in? %li - = link_to(backoffice_dossiers_path) do + = link_to(procedures_path) do %i.fa.fa-user   Accompagnateur diff --git a/spec/controllers/backoffice/avis_controller_spec.rb b/spec/controllers/backoffice/avis_controller_spec.rb index 54d3c6143..15ce93bc6 100644 --- a/spec/controllers/backoffice/avis_controller_spec.rb +++ b/spec/controllers/backoffice/avis_controller_spec.rb @@ -177,7 +177,7 @@ describe Backoffice::AvisController, type: :controller do it { expect(Avis).to have_received(:link_avis_to_gestionnaire) } it { expect(subject.current_gestionnaire).to eq(created_gestionnaire) } - it { is_expected.to redirect_to backoffice_dossier_path(dossier) } + it { is_expected.to redirect_to avis_index_path } end context 'when the gestionnaire creation fails' do diff --git a/spec/controllers/root_controller_spec.rb b/spec/controllers/root_controller_spec.rb index f39c348db..37b83e26f 100644 --- a/spec/controllers/root_controller_spec.rb +++ b/spec/controllers/root_controller_spec.rb @@ -13,27 +13,20 @@ describe RootController, type: :controller do context 'when Gestionnaire is connected' do let(:gestionnaire) { create(:gestionnaire) } + let(:procedure) { create(:procedure, :published) } + let(:dossier) { create(:dossier, :en_construction, procedure: procedure) } before do + gestionnaire.procedures << procedure sign_in gestionnaire end - context 'when gestionnaire is affect to a procedure' do - before do - create :assign_to, procedure: (create :procedure, :published), gestionnaire: gestionnaire - end + it { expect(subject).to redirect_to(procedures_path) } - it { expect(subject).to redirect_to(backoffice_dossiers_procedure_path(id: Procedure.all.first.id)) } - end + context 'and coming with old_ui param' do + subject { get :index, params: { old_ui: 1 } } - context 'when gestionnaire is not affect to a procedure' do - render_views - - before do - subject - end - - it { expect(response.body).to have_css('.landing') } + it { expect(subject).to redirect_to(backoffice_path) } end end diff --git a/spec/features/backoffice/connection_spec.rb b/spec/features/backoffice/connection_spec.rb index 65a20af26..eacbc4a37 100644 --- a/spec/features/backoffice/connection_spec.rb +++ b/spec/features/backoffice/connection_spec.rb @@ -29,8 +29,8 @@ feature 'when gestionnaire come to /backoffice and is not authenticated' do page.find_by_id(:user_password).set gestionnaire.password page.click_on 'Se connecter' end - scenario 'he is redirected to /backoffice' do - expect(page).to have_css('#backoffice-index') + scenario 'he is redirected to /procedures' do + expect(current_path).to eq(procedures_path) end end end diff --git a/spec/features/backoffice/navigate_to_dossier_spec.rb b/spec/features/backoffice/navigate_to_dossier_spec.rb index a24295699..108862f72 100644 --- a/spec/features/backoffice/navigate_to_dossier_spec.rb +++ b/spec/features/backoffice/navigate_to_dossier_spec.rb @@ -22,6 +22,7 @@ feature 'on backoffice page', js: true do page.find_by_id(:user_email).set gestionnaire.email page.find_by_id(:user_password).set gestionnaire.password page.click_on 'Se connecter' + page.click_on 'Ancienne interface' end context 'when he click on first dossier' do before do diff --git a/spec/features/new_gestionnaire/gestionnaire_spec.rb b/spec/features/new_gestionnaire/gestionnaire_spec.rb index 431ac12a9..af836ab79 100644 --- a/spec/features/new_gestionnaire/gestionnaire_spec.rb +++ b/spec/features/new_gestionnaire/gestionnaire_spec.rb @@ -10,7 +10,6 @@ feature 'The gestionnaire part' do scenario 'A gestionnaire can accept a dossier' do log_in(gestionnaire.email, password) - click_on 'nouvelle interface' expect(page).to have_current_path(procedures_path) click_on procedure.libelle @@ -36,8 +35,6 @@ feature 'The gestionnaire part' do scenario 'A gestionnaire can follow/unfollow a dossier' do log_in(gestionnaire.email, password) - click_on 'nouvelle interface' - click_on procedure.libelle test_statut_bar(a_suivre: 1, tous_les_dossiers: 1) dossier_present?(dossier.id, 'en construction') @@ -62,7 +59,6 @@ feature 'The gestionnaire part' do log_in(gestionnaire.email, password) - click_on 'nouvelle interface' click_on procedure.libelle click_on dossier.user.email @@ -79,7 +75,6 @@ feature 'The gestionnaire part' do avis_sign_up(avis, expert_email, 'a good password') - click_on 'nouvelle interface' expect(page).to have_current_path(avis_index_path) expect(page).to have_text('avis à donner 1') expect(page).to have_text('avis donnés 0') @@ -104,7 +99,6 @@ feature 'The gestionnaire part' do log_in(gestionnaire.email, password) - click_on 'nouvelle interface' click_on procedure.libelle click_on dossier.user.email click_on 'Avis externes' @@ -117,7 +111,6 @@ feature 'The gestionnaire part' do log_in(gestionnaire.email, password) - click_on 'nouvelle interface' click_on procedure.libelle click_on dossier.user.email @@ -143,7 +136,7 @@ feature 'The gestionnaire part' do fill_in 'user_email', with: email fill_in 'user_password', with: password click_on 'Se connecter' - expect(page).to have_current_path(backoffice_dossiers_procedure_path(procedure)) + expect(page).to have_current_path(procedures_path) end def log_out @@ -178,7 +171,7 @@ feature 'The gestionnaire part' do visit avis_sign_up_path(avis, email) fill_in 'gestionnaire_password', with: 'a good password' click_on 'Créer un compte' - expect(page).to have_current_path(backoffice_dossier_path(dossier)) + expect(page).to have_current_path(avis_index_path) end def dossier_present?(id, statut)