X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/dc021c3b57dcdebe464c148d55f9990a74e8246b..1fb68cf0a5f6ad058a54d4f822385983b3504987:/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 65a23f1fe7..76e8da0c72 100644 --- a/services/api/app/controllers/arvados/v1/users_controller.rb +++ b/services/api/app/controllers/arvados/v1/users_controller.rb @@ -22,7 +22,15 @@ class Arvados::V1::UsersController < ApplicationController rescue ActiveRecord::RecordNotUnique retry end - u.update_attributes!(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 + u.update_attributes!(needupdate) + end @objects << u end @offset = 0 @@ -45,13 +53,20 @@ class Arvados::V1::UsersController < ApplicationController end def activate + if params[:id] and params[:id].match(/\D/) + params[:uuid] = params.delete :id + end if current_user.andand.is_admin && params[:uuid] - @object = User.find params[:uuid] + @object = User.find_by_uuid params[:uuid] else @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." @@ -120,8 +135,12 @@ class Arvados::V1::UsersController < ApplicationController vm_uuid: params[:vm_uuid]) # setup succeeded. send email to user - if params[:send_notification_email] - UserNotifier.account_is_setup(@object).deliver_now + if params[:send_notification_email] && !Rails.configuration.Users.UserSetupMailText.empty? + begin + UserNotifier.account_is_setup(@object).deliver_now + rescue => e + logger.warn "Failed to send email to #{@object.email}: #{e}" + end end send_json kind: "arvados#HashList", items: @response.as_api_response(nil) @@ -242,6 +261,14 @@ class Arvados::V1::UsersController < ApplicationController } end + def self._update_requires_parameters + super.merge({ + bypass_federation: { + type: 'boolean', required: false, + }, + }) + end + def self._update_uuid_requires_parameters { new_uuid: { @@ -264,4 +291,8 @@ class Arvados::V1::UsersController < ApplicationController end super end + + def nullable_attributes + super + [:email, :first_name, :last_name, :username] + end end