Skip to content

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

[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.rb
index 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 attributes
def update_attributes
if user.new_record? || user.invited?
- user.assign_attributes user_attributes
user.register unless user.invited?
+
+ ::Users::SetAttributesService
+ .new(user: User.system, model: user, contract_class: ::Users::UpdateContract)
+ .call(user_attributes)
+ .result
else
# 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))
end
end
diff --git a/spec/services/authentication/omniauth_service_spec.rb b/spec/services/authentication/omniauth_service_spec.rb
index 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 do
it '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 do
expect(call).to be_success
expect(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)
end
end
@@ -149,7 +153,7 @@ describe Authentication::OmniauthService do
it '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 do
expect(call).to be_success
expect(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)
end
end
@@ -176,6 +184,9 @@ describe Authentication::OmniauthService do
# The user might get activated in the register service
expect(instance.user).not_to be_active
expect(instance.user).to be_new_record
+
+ # Expect notifications to be present (Regression #38066)
+ expect(instance.user.notification_settings).not_to be_empty
end
end
end