X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/3aaefcb3c76ff470b475d950398d01255e87712a..ffe48ca94f89f3d7b71305b394e1f57ee633efed:/services/api/app/controllers/arvados/v1/users_controller.rb diff --git a/services/api/app/controllers/arvados/v1/users_controller.rb b/services/api/app/controllers/arvados/v1/users_controller.rb index f4d42edf6c..031dd2e4f9 100644 --- a/services/api/app/controllers/arvados/v1/users_controller.rb +++ b/services/api/app/controllers/arvados/v1/users_controller.rb @@ -10,27 +10,19 @@ 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. def batch_update @objects = [] - params[:updates].andand.each do |uuid, attrs| - begin - u = User.find_or_create_by(uuid: uuid) - rescue ActiveRecord::RecordNotUnique - retry - end - needupdate = {} - nullify_attrs(attrs).each do |k,v| - if !v.nil? && u.send(k) != v - needupdate[k] = v - end - end - if needupdate.length > 0 - u.update_attributes!(needupdate) - end + # update_remote_user takes a row lock on the User record, so sort + # the keys so we always lock them in the same order. + sorted = params[:updates].keys.sort + sorted.each do |uuid| + attrs = params[:updates][uuid] + attrs[:uuid] = uuid + u = User.update_remote_user nullify_attrs(attrs) @objects << u end @offset = 0 @@ -87,7 +79,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 " + @@ -145,13 +137,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 @@ -261,19 +246,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", "is_admin", "is_invited", "email", "first_name", "last_name", "username", "can_write", "can_manage", "kind"] if @select @select = @select & safe_attrs else @@ -281,6 +258,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