From b5ce814f260b908baaeb0616735d96e51016d47f Mon Sep 17 00:00:00 2001
From: Drew Blessing <drew@gitlab.com>
Date: Fri, 26 Jan 2024 09:33:58 -0600
Subject: [PATCH] Redirect to correct page after dashboard SAML reauth

After reauthenticating with SAML from a dashboard page, redirect
the user back to the same page rather than hardcoding to the
Todos dashboard page.

Changelog: fixed
EE: true
---
 ee/app/views/shared/dashboard/_saml_reauth_notice.html.haml   | 2 +-
 .../features/dashboard_saml_reauth_banner_shared_examples.rb  | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/ee/app/views/shared/dashboard/_saml_reauth_notice.html.haml b/ee/app/views/shared/dashboard/_saml_reauth_notice.html.haml
index 47bc4bcecc739..f9d9097a89b0f 100644
--- a/ee/app/views/shared/dashboard/_saml_reauth_notice.html.haml
+++ b/ee/app/views/shared/dashboard/_saml_reauth_notice.html.haml
@@ -6,5 +6,5 @@
   - c.with_actions do
     .gl-display-flex.gl-flex-wrap
       - groups_requiring_saml_reauth.each do |group|
-        = render Pajamas::ButtonComponent.new(href: sso_group_saml_providers_path(group, { token: group.saml_discovery_token, redirect: dashboard_todos_path }), button_options: { class: "gl-mr-3 gl-mb-3" }) do
+        = render Pajamas::ButtonComponent.new(href: sso_group_saml_providers_path(group, { token: group.saml_discovery_token, redirect: url_for }), button_options: { class: "gl-mr-3 gl-mb-3" }) do
           = group.path
diff --git a/ee/spec/support/shared_examples/features/dashboard_saml_reauth_banner_shared_examples.rb b/ee/spec/support/shared_examples/features/dashboard_saml_reauth_banner_shared_examples.rb
index 8ef0f3fa83206..93e6ddccf4e82 100644
--- a/ee/spec/support/shared_examples/features/dashboard_saml_reauth_banner_shared_examples.rb
+++ b/ee/spec/support/shared_examples/features/dashboard_saml_reauth_banner_shared_examples.rb
@@ -26,7 +26,9 @@
         s_('GroupSAML|Some items may be hidden because your SAML session has expired. Select the group’s path to reauthenticate and view any hidden items.') # rubocop:disable Layout/LineLength -- Single string
       )
 
-      expect(page).to have_link(restricted_group.path, href: /#{sso_group_saml_providers_path(restricted_group)}/)
+      link = page.find_link(restricted_group.path)
+      expect(link[:href]).to start_with(sso_group_saml_providers_path(restricted_group))
+      expect(link[:href]).to include("redirect=#{ERB::Util.url_encode(page_path)}")
     end
   end
 
-- 
GitLab