OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Always redirect to back_url when not in account routes
Oliver Günther9ab21b332877
diff --git a/app/controllers/concerns/accounts/omniauth_login.rb b/app/controllers/concerns/accounts/omniauth_login.rbindex 80af54e8fe6..3e882cc5d01 100644--- a/app/controllers/concerns/accounts/omniauth_login.rb+++ b/app/controllers/concerns/accounts/omniauth_login.rb@@ -47,12 +47,7 @@ module Accounts::OmniauthLoginenddef omniauth_login- # Remmember the back_url to redirect to after login- # only if we're in a direct login phase, so the user ends up- # in the original requested URL after logging in- if omniauth_direct_login?- params[:back_url] = request.env['omniauth.origin']- end+ params[:back_url] = request.env['omniauth.origin'] if remember_back_url?# Extract auth info and perform check / login or activate userauth_hash = request.env['omniauth.auth']@@ -78,6 +73,15 @@ module Accounts::OmniauthLoginonthefly_creation_failed(user, session_info)end+ # Avoid remembering the back_url if we're coming from the login page+ def remember_back_url?+ provided_back_url = request.env['omniauth.origin']+ return if provided_back_url.blank?++ account_routes = /\/(login|account)/+ omniauth_direct_login? || !provided_back_url.match?(account_routes)+ end+def show_error(error)flash[:error] = errorredirect_to action: 'login'diff --git a/spec/controllers/concerns/omniauth_login_spec.rb b/spec/controllers/concerns/omniauth_login_spec.rbindex de630119e77..9037116d4a7 100644--- a/spec/controllers/concerns/omniauth_login_spec.rb+++ b/spec/controllers/concerns/omniauth_login_spec.rb@@ -304,6 +304,28 @@ RSpec.describe AccountController, :skip_2fa_stage doexpect(user.last_login_on.utc.to_i).to be >= post_at.utc.to_iend+ context 'with a back_url present' do+ before do+ request.env['omniauth.origin'] = 'http://test.host/projects'+ post :omniauth_login, params: { provider: :google }+ end++ it 'redirects to that url', :aggregate_failures do+ expect(response).to redirect_to '/projects'+ end+ end++ context 'with a back_url from a login path' do+ before do+ request.env['omniauth.origin'] = 'http://test.host/login'+ post :omniauth_login, params: { provider: :google }+ end++ it 'redirects to that url', :aggregate_failures do+ expect(response).to redirect_to '/my/page'+ end+ end+context 'with a partially blank auth_hash' dolet(:omniauth_hash) doOmniAuth::AuthHash.new(