From: Peter Amstutz Date: Fri, 2 Feb 2024 16:17:03 +0000 (-0500) Subject: 21304: Handle user record updates with empty string username X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/972b62e2bb581832cb7cfafce71e3cc6794e4361?ds=sidebyside 21304: Handle user record updates with empty string username Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- diff --git a/lib/controller/integration_test.go b/lib/controller/integration_test.go index fc1f705175..4bf7a03447 100644 --- a/lib/controller/integration_test.go +++ b/lib/controller/integration_test.go @@ -971,8 +971,8 @@ func (s *IntegrationSuite) TestSetupUserWithVM(c *check.C) { "hostname": "example", }, }) + c.Assert(err, check.IsNil) c.Check(outVM.UUID[0:5], check.Equals, "z3333") - c.Check(err, check.IsNil) // Make sure z3333 user list is up to date _, err = conn3.UserList(rootctx3, arvados.ListOptions{Limit: 1000}) diff --git a/services/api/app/models/user.rb b/services/api/app/models/user.rb index 212b0b6ce3..5a95fb0b88 100644 --- a/services/api/app/models/user.rb +++ b/services/api/app/models/user.rb @@ -656,13 +656,16 @@ SELECT target_uuid, perm_level remote_should_be_active = should_activate && remote_user[:is_invited] != false && remote_user[:is_active] == true + # Make sure blank username is nil + remote_user[:username] = nil if remote_user[:username] == "" + begin user = User.create_with(email: remote_user[:email], username: remote_user[:username], first_name: remote_user[:first_name], last_name: remote_user[:last_name], - is_active: remote_should_be_active - ).find_or_create_by(uuid: remote_user[:uuid]) + is_active: remote_should_be_active, + ).find_or_create_by(uuid: remote_user[:uuid]) rescue ActiveRecord::RecordNotUnique retry end @@ -711,6 +714,14 @@ SELECT target_uuid, perm_level end raise # Not the issue we're handling above end + elsif user.new_record? + begin + user.save! + rescue => e + Rails.logger.debug "Error saving user record: #{$!}" + Rails.logger.debug "Backtrace:\n\t#{e.backtrace.join("\n\t")}" + raise + end end if remote_should_be_unsetup