[: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.
rescue ActiveRecord::RecordNotUnique
retry
end
- u.update_attributes!(nullify_attrs(attrs))
+ needupdate = {}
+ nullify_attrs(attrs).each do |k,v|
+ if !v.nil? && u.send(k) != v
+ needupdate[k] = v
+ end
+ end
+ if needupdate.length > 0
+ begin
+ u.update_attributes!(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
+ new_username = "#{needupdate[:username]}conflict#{rand(99999999)}"
+ Rails.logger.warn("cached username '#{needupdate[:username]}' collision with user '#{local_user.uuid}' - renaming to '#{new_username}' before retrying")
+ local_user.update_attributes!({username: new_username})
+ retry
+ end
+ end
+ raise # Not the issue we're handling above
+ end
+ end
@objects << u
end
@offset = 0
@object = current_user
end
if not @object.is_active
- if not (current_user.is_admin or @object.is_invited)
+ if @object.uuid[0..4] == Rails.configuration.Login.LoginCluster &&
+ @object.uuid[0..4] != Rails.configuration.ClusterID
+ logger.warn "Local user #{@object.uuid} called users#activate but only LoginCluster can do that"
+ raise ArgumentError.new "cannot activate user #{@object.uuid} here, only the #{@object.uuid[0..4]} cluster can do that"
+ elsif not (current_user.is_admin or @object.is_invited)
logger.warn "User #{@object.uuid} called users.activate " +
"but is not invited"
raise ArgumentError.new "Cannot activate without being invited."
end
@response = @object.setup(repo_name: full_repo_name,
- vm_uuid: params[:vm_uuid])
-
- # setup succeeded. send email to user
- if params[:send_notification_email]
- begin
- UserNotifier.account_is_setup(@object).deliver_now
- rescue => e
- logger.warn "Failed to send email to #{@object.email}: #{e}"
- end
- end
+ vm_uuid: params[:vm_uuid],
+ send_notification_email: params[:send_notification_email])
send_json kind: "arvados#HashList", items: @response.as_api_response(nil)
end
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
type: 'string', required: false,
},
redirect_to_new_user: {
- type: 'boolean', required: false,
+ type: 'boolean', required: false, default: false,
},
old_user_uuid: {
type: 'string', required: false,
def self._setup_requires_parameters
{
uuid: {
- type: 'string', required: false
+ type: 'string', required: false,
},
user: {
- type: 'object', required: false
+ type: 'object', required: false,
},
repo_name: {
- type: 'string', required: false
+ type: 'string', required: false,
},
vm_uuid: {
- type: 'string', required: false
+ type: 'string', required: false,
},
send_notification_email: {
- type: 'boolean', required: false, default: false
+ type: 'boolean', required: false, default: false,
},
}
end
def self._update_requires_parameters
super.merge({
bypass_federation: {
- type: 'boolean', required: false,
+ type: 'boolean', required: false, default: false,
},
})
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