From 2b62223c9ba420208b9f293825e7f6ae3f50f95b Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Tue, 13 Jun 2017 21:02:17 -0400 Subject: [PATCH] 10557: Always run user setup procedure when is_active becomes true. Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- services/api/app/models/user.rb | 11 +++++++++++ .../arvados/v1/users_controller_test.rb | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/services/api/app/models/user.rb b/services/api/app/models/user.rb index b654b5a023..c4a4f92d30 100644 --- a/services/api/app/models/user.rb +++ b/services/api/app/models/user.rb @@ -20,6 +20,9 @@ class User < ArvadosModel before_update :verify_repositories_empty, :if => Proc.new { |user| user.username.nil? and user.username_changed? } + before_update :setup_on_activate, :if => Proc.new { |user| + ![system_user_uuid, anonymous_user_uuid].include?(user.uuid) + } before_create :check_auto_admin before_create :set_initial_username, :if => Proc.new { |user| user.username.nil? and user.email @@ -461,6 +464,14 @@ class User < ArvadosModel end end + # Automatically setup if is_active flag turns on + def setup_on_activate + return if [system_user_uuid, anonymous_user_uuid].include?(self.uuid) + if is_active && (new_record? || is_active_changed?) + setup(openid_prefix: Rails.configuration.default_openid_prefix) + end + end + # Automatically setup new user during creation def auto_setup_new_user setup(openid_prefix: Rails.configuration.default_openid_prefix) diff --git a/services/api/test/functional/arvados/v1/users_controller_test.rb b/services/api/test/functional/arvados/v1/users_controller_test.rb index f98e482dd8..789242f6e0 100644 --- a/services/api/test/functional/arvados/v1/users_controller_test.rb +++ b/services/api/test/functional/arvados/v1/users_controller_test.rb @@ -660,6 +660,24 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase assert (setup_email.body.to_s.include? "#{Rails.configuration.workbench_address}users/#{created['uuid']}/virtual_machines"), 'Expected virtual machines url in email body' end + test "setup inactive user by changing is_active to true" do + authorize_with :admin + active_user = users(:active) + + # invoke setup with a repository + put :update, { + id: active_user['uuid'], + user: { + is_active: true, + } + } + assert_response :success + assert_equal active_user['uuid'], json_response['uuid'] + updated = User.where(uuid: active_user['uuid']).first + assert_equal(true, updated.is_active) + assert_equal({read: true}, updated.group_permissions[all_users_group_uuid]) + end + test "non-admin user can get basic information about readable users" do authorize_with :spectator get(:index) -- 2.30.2