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
Use SetAttributesService when retrieving user
Oliver Günther048e9476b3a8
diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rbindex abfd3e943c5..80b852b5ada 100644--- a/app/controllers/account_controller.rb+++ b/app/controllers/account_controller.rb@@ -270,7 +270,7 @@ class AccountController < ApplicationControllerdef auth_source_sso_failedfailure = session.delete :auth_source_sso_failurelogin = failure[:login]- user = find_user_from_auth_source(login) || create_user_from_auth_source(login)+ user = find_or_create_sso_user(login, save: false)if user.try(:new_record?)return onthefly_creation_failed user, login: user.login, auth_source_id: user.auth_source_iddiff --git a/app/controllers/concerns/auth_source_sso.rb b/app/controllers/concerns/auth_source_sso.rbindex 4be35a567ed..2b9b2dd06ba 100644--- a/app/controllers/concerns/auth_source_sso.rb+++ b/app/controllers/concerns/auth_source_sso.rb@@ -33,7 +33,7 @@ module AuthSourceSSORails.logger.debug { "Starting header-based auth source SSO for #{header_name}='#{op_auth_header_value}'" }- user = find_user_from_auth_source(login) || create_user_from_auth_source(login)+ user = find_or_create_sso_user(login, save: true)handle_sso_for! user, loginend@@ -106,6 +106,10 @@ module AuthSourceSSOendend+ def find_or_create_sso_user(login, save: false)+ find_user_from_auth_source(login) || create_user_from_auth_source(login, save: save)+ end+def find_user_from_auth_source(login)User.by_login(login)@@ -113,13 +117,22 @@ module AuthSourceSSO.firstend- def create_user_from_auth_source(login)+ def create_user_from_auth_source(login, save:)attrs = AuthSource.find_user(login)return unless attrs- call = Users::CreateService- .new(user: User.system)- .call(attrs.merge(login: login))+ attrs[:login] = login++ call =+ if save+ Users::CreateService+ .new(user: User.system)+ .call(attrs)+ else+ Users::SetAttributesService+ .new(model: User.new, user: User.system, contract_class: Users::CreateContract)+ .call(attrs)+ enduser = call.resultdiff --git a/spec/controllers/account_controller_spec.rb b/spec/controllers/account_controller_spec.rbindex 158603d6e34..0cf2e7d2318 100644--- a/spec/controllers/account_controller_spec.rb+++ b/spec/controllers/account_controller_spec.rb@@ -1010,7 +1010,7 @@ describe AccountController, type: :controller doallow(AuthSource).to receive(:find_user).and_return attrsend- it "should show the account creation form with an error" do+ it "shows the account creation form with an error" doget :auth_source_sso_failedexpect(session[:auth_source_sso_failure]).not_to be_present@@ -1031,7 +1031,7 @@ describe AccountController, type: :controller doallow(AuthSource).to receive(:find_user).and_return attrsend- it "should show the account creation form with an error" do+ it "shows the account creation form with an error" doget :auth_source_sso_failedexpect(session[:auth_source_sso_failure]).not_to be_present