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
[38066] Use the services to update the user
Oliver Güntherc683af254c9b
diff --git a/app/services/authentication/omniauth_service.rb b/app/services/authentication/omniauth_service.rbindex b35c299f88c..63fbf8837c2 100644--- a/app/services/authentication/omniauth_service.rb+++ b/app/services/authentication/omniauth_service.rb@@ -155,11 +155,17 @@ module Authentication# Update or assign the user attributesdef update_attributesif user.new_record? || user.invited?- user.assign_attributes user_attributesuser.register unless user.invited?++ ::Users::SetAttributesService+ .new(user: User.system, model: user, contract_class: ::Users::UpdateContract)+ .call(user_attributes)+ .resultelse# Update the user, but never change the admin flag- user.update user_attributes.except(:admin)+ ::Users::UpdateService+ .new(user: User.system, model: user)+ .call(user_attributes.except(:admin))endenddiff --git a/spec/services/authentication/omniauth_service_spec.rb b/spec/services/authentication/omniauth_service_spec.rbindex 4c959dacffa..8ae669096ac 100644--- a/spec/services/authentication/omniauth_service_spec.rb+++ b/spec/services/authentication/omniauth_service_spec.rb@@ -98,7 +98,7 @@ describe Authentication::OmniauthService doit 'does not call register user service and logs in the user' do# should update the user attributes- expect(user).to receive(:update).with(user_attributes)+ allow(user).to receive(:save)expect(OpenProject::OmniAuth::Authorization).to(receive(:after_login!))@@ -106,6 +106,10 @@ describe Authentication::OmniauthService doexpect(call).to be_successexpect(call.result).to eq user+ expect(call.result.firstname).to eq 'foo'+ expect(call.result.lastname).to eq 'bar'+ expect(call.result.mail).to eq '[email protected]'+ expect(user).to have_received(:save)endend@@ -149,7 +153,7 @@ describe Authentication::OmniauthService doit 'does not call register user service and logs in the user' do# should update the user attributes- expect(user).to receive(:update).with(user_attributes)+ allow(user).to receive(:save)expect(OpenProject::OmniAuth::Authorization).to(receive(:after_login!))@@ -157,6 +161,10 @@ describe Authentication::OmniauthService doexpect(call).to be_successexpect(call.result).to eq user+ expect(call.result.firstname).to eq 'foo'+ expect(call.result.lastname).to eq 'bar'+ expect(call.result.mail).to eq '[email protected]'+ expect(user).to have_received(:save)endend@@ -176,6 +184,9 @@ describe Authentication::OmniauthService do# The user might get activated in the register serviceexpect(instance.user).not_to be_activeexpect(instance.user).to be_new_record++ # Expect notifications to be present (Regression #38066)+ expect(instance.user.notification_settings).not_to be_emptyendendend