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

Remove not only nil, but also blank values

Oliver Günther4062356e45fa
diff --git a/app/services/authentication/omniauth_service.rb b/app/services/authentication/omniauth_service.rb
index 050ad018eac..5f8e7b8e1aa 100644
--- a/app/services/authentication/omniauth_service.rb
+++ b/app/services/authentication/omniauth_service.rb
@@ -231,7 +231,7 @@ module Authentication
# Remove any nil values to avoid
# overriding existing attributes
- attribute_map.compact!
+ attribute_map.compact_blank!
Rails.logger.debug { "Mapped auth_hash user attributes #{attribute_map.inspect}" }
attribute_map
diff --git a/spec/controllers/concerns/omniauth_login_spec.rb b/spec/controllers/concerns/omniauth_login_spec.rb
index fae5fc1d5a3..e588497fa19 100644
--- a/spec/controllers/concerns/omniauth_login_spec.rb
+++ b/spec/controllers/concerns/omniauth_login_spec.rb
@@ -306,6 +306,28 @@ describe AccountController,
expect(user.last_login_on.utc.to_i).to be >= post_at.utc.to_i
end
+ context 'with a partially blank auth_hash' do
+ let(:omniauth_hash) do
+ OmniAuth::AuthHash.new(
+ provider: 'google',
+ uid: '123545',
+ info: { name: 'foo',
+ first_name: '',
+ last_name: 'newLastname',
+ email: '[email protected]' }
+ )
+ end
+
+ it 'signs in the user after successful external authentication' do
+ expect { post :omniauth_login, params: { provider: :google } }
+ .not_to change { user.reload.firstname }
+
+ expect(response).to redirect_to my_page_path
+
+ expect(user.lastname).to eq 'newLastname'
+ end
+ end
+
describe 'authorization' do
let(:config) do
Struct.new(:google_name, :global_email).new 'foo', '[email protected]'