X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/726f65153228eb81aa526df078f4fca6045e1779..60542dcecbffe14a43098d9e68ee6ae05868df1e:/services/api/app/controllers/arvados/v1/users_controller.rb?ds=inline diff --git a/services/api/app/controllers/arvados/v1/users_controller.rb b/services/api/app/controllers/arvados/v1/users_controller.rb index 82594c1eb3..2353f67c1a 100644 --- a/services/api/app/controllers/arvados/v1/users_controller.rb +++ b/services/api/app/controllers/arvados/v1/users_controller.rb @@ -10,7 +10,7 @@ class Arvados::V1::UsersController < ApplicationController [:activate, :current, :system, :setup, :merge, :batch_update] skip_before_action :render_404_if_no_object, only: [:activate, :current, :system, :setup, :merge, :batch_update] - before_action :admin_required, only: [:setup, :unsetup, :update_uuid, :batch_update] + before_action :admin_required, only: [:setup, :unsetup, :batch_update] # Internal API used by controller to update local cache of user # records from LoginCluster. @@ -30,16 +30,22 @@ class Arvados::V1::UsersController < ApplicationController end if needupdate.length > 0 begin - u.update_attributes!(needupdate) + u.update!(needupdate) rescue ActiveRecord::RecordInvalid loginCluster = Rails.configuration.Login.LoginCluster if u.uuid[0..4] == loginCluster && !needupdate[:username].nil? local_user = User.find_by_username(needupdate[:username]) - # A cached user record from the LoginCluster is stale, reset its username - # and retry the update operation. - if local_user.andand.uuid[0..4] == loginCluster && local_user.uuid != u.uuid - Rails.logger.warn("cached username '#{needupdate[:username]}' collision with user '#{local_user.uuid}' - resetting") - local_user.update_attributes!({username: nil}) + # The username of this record conflicts with an existing, + # different user record. This can happen because the + # username changed upstream on the login cluster, or + # because we're federated with another cluster with a user + # by the same username. The login cluster is the source + # of truth, so change the username on the conflicting + # record and retry the update operation. + if local_user.uuid != u.uuid + new_username = "#{needupdate[:username]}#{rand(99999999)}" + Rails.logger.warn("cached username '#{needupdate[:username]}' collision with user '#{local_user.uuid}' - renaming to '#{new_username}' before retrying") + local_user.update!({username: new_username}) retry end end @@ -102,7 +108,7 @@ class Arvados::V1::UsersController < ApplicationController collect(&:head_uuid) todo_uuids = required_uuids - signed_uuids if todo_uuids.empty? - @object.update_attributes is_active: true + @object.update is_active: true logger.info "User #{@object.uuid} activated" else logger.warn "User #{@object.uuid} called users.activate " + @@ -160,13 +166,6 @@ class Arvados::V1::UsersController < ApplicationController show end - # Change UUID to a new (unused) uuid and transfer all owned/linked - # objects accordingly. - def update_uuid - @object.update_uuid(new_uuid: params[:new_uuid]) - show - end - def merge if (params[:old_user_uuid] || params[:new_user_uuid]) if !current_user.andand.is_admin @@ -276,19 +275,11 @@ class Arvados::V1::UsersController < ApplicationController }) end - def self._update_uuid_requires_parameters - { - new_uuid: { - type: 'string', required: true, - }, - } - end - def apply_filters(model_class=nil) return super if @read_users.any?(&:is_admin) if params[:uuid] != current_user.andand.uuid # Non-admin index/show returns very basic information about readable users. - safe_attrs = ["uuid", "is_active", "email", "first_name", "last_name", "username"] + safe_attrs = ["uuid", "is_active", "email", "first_name", "last_name", "username", "can_write", "can_manage", "kind"] if @select @select = @select & safe_attrs else @@ -296,6 +287,13 @@ class Arvados::V1::UsersController < ApplicationController end @filters += [['is_active', '=', true]] end + # This gets called from within find_object_by_uuid. + # find_object_by_uuid stores the original value of @select in + # @preserve_select, edits the value of @select, calls + # find_objects_for_index, then restores @select from the value + # of @preserve_select. So if we want our updated value of + # @select here to stick, we have to set @preserve_select. + @preserve_select = @select super end