From b68b340d81a646c13ab30972b4b2167c19f930e0 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Tue, 17 Sep 2024 15:59:24 +0200 Subject: [PATCH 1/2] fix(stats): nav bar profile logic when fallbacking on referer context without request --- app/controllers/concerns/nav_bar_profile_concern.rb | 6 ++++++ app/controllers/users/commencer_controller.rb | 4 +--- app/controllers/users/statistiques_controller.rb | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/controllers/concerns/nav_bar_profile_concern.rb b/app/controllers/concerns/nav_bar_profile_concern.rb index 4c856480f..96f4228b8 100644 --- a/app/controllers/concerns/nav_bar_profile_concern.rb +++ b/app/controllers/concerns/nav_bar_profile_concern.rb @@ -16,6 +16,12 @@ module NavBarProfileConcern private + def nav_bar_user_or_guest + # when instanciating manually the controller (see below), + # we don't have request and current_user would fail + request && current_user ? :user : :guest + end + # Shared controllers (search, errors, release notes…) don't have specific context # Simple attempt to try to re-use the profile from the previous page # so user does'not feel lost. diff --git a/app/controllers/users/commencer_controller.rb b/app/controllers/users/commencer_controller.rb index 76fbcf93e..7ab8c4c99 100644 --- a/app/controllers/users/commencer_controller.rb +++ b/app/controllers/users/commencer_controller.rb @@ -87,9 +87,7 @@ module Users retrieve_procedure end - def nav_bar_profile - current_user ? :user : :guest - end + def nav_bar_profile = nav_bar_user_or_guest def closing_details @procedure = Procedure.find_by(path: params[:path]) diff --git a/app/controllers/users/statistiques_controller.rb b/app/controllers/users/statistiques_controller.rb index acd6b9079..aa5019fe0 100644 --- a/app/controllers/users/statistiques_controller.rb +++ b/app/controllers/users/statistiques_controller.rb @@ -2,6 +2,8 @@ module Users class StatistiquesController < ApplicationController + def nav_bar_profile = nav_bar_user_or_guest + def statistiques @procedure = procedure return procedure_not_found if @procedure.blank? || @procedure.brouillon? From 79a1d9b99d5e77eda4f1965ab39f9f888b9927cb Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Tue, 17 Sep 2024 16:17:01 +0200 Subject: [PATCH 2/2] fix(navbar): never fail request on broken navbar logic --- app/controllers/concerns/nav_bar_profile_concern.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/controllers/concerns/nav_bar_profile_concern.rb b/app/controllers/concerns/nav_bar_profile_concern.rb index 96f4228b8..9201c2788 100644 --- a/app/controllers/concerns/nav_bar_profile_concern.rb +++ b/app/controllers/concerns/nav_bar_profile_concern.rb @@ -34,6 +34,10 @@ module NavBarProfileConcern controller_instance = controller_class.new controller_instance.try(:nav_bar_profile) + rescue StandardError => e # we don't want broken logic in nav bar profile to fail the request + Sentry.capture_exception(e) + + nil end # Fallback for shared controllers from user account