[ARVADOS] created: 2b62223c9ba420208b9f293825e7f6ae3f50f95b
Git user
git at public.curoverse.com
Tue Jun 13 21:03:56 EDT 2017
at 2b62223c9ba420208b9f293825e7f6ae3f50f95b (commit)
commit 2b62223c9ba420208b9f293825e7f6ae3f50f95b
Author: Tom Clegg <tom at curoverse.com>
Date: Tue Jun 13 21:02:17 2017 -0400
10557: Always run user setup procedure when is_active becomes true.
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at curoverse.com>
diff --git a/services/api/app/models/user.rb b/services/api/app/models/user.rb
index b654b5a..c4a4f92 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 f98e482..789242f 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)
commit 28cf4975bf3a72ff11ab4044a54b434857b1b95e
Author: Tom Clegg <tom at curoverse.com>
Date: Tue Jun 13 21:01:41 2017 -0400
10557: Tidy up some user setup code.
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at curoverse.com>
diff --git a/services/api/app/controllers/arvados/v1/users_controller.rb b/services/api/app/controllers/arvados/v1/users_controller.rb
index 7a1f699..0e95042 100644
--- a/services/api/app/controllers/arvados/v1/users_controller.rb
+++ b/services/api/app/controllers/arvados/v1/users_controller.rb
@@ -113,16 +113,12 @@ class Arvados::V1::UsersController < ApplicationController
full_repo_name = "#{@object.username}/#{params[:repo_name]}"
end
- if object_found
- @response = @object.setup_repo_vm_links full_repo_name,
- params[:vm_uuid], params[:openid_prefix]
- else
- @response = User.setup @object, params[:openid_prefix],
- full_repo_name, params[:vm_uuid]
- end
+ @response = @object.setup(repo_name: full_repo_name,
+ vm_uuid: params[:vm_uuid],
+ openid_prefix: params[:openid_prefix])
# setup succeeded. send email to user
- if params[:send_notification_email] == true || params[:send_notification_email] == 'true'
+ if params[:send_notification_email]
UserNotifier.account_is_setup(@object).deliver_now
end
diff --git a/services/api/app/models/user.rb b/services/api/app/models/user.rb
index d944474..b654b5a 100644
--- a/services/api/app/models/user.rb
+++ b/services/api/app/models/user.rb
@@ -182,15 +182,11 @@ class User < ArvadosModel
r
end
- def self.setup(user, openid_prefix, repo_name=nil, vm_uuid=nil)
- return user.setup_repo_vm_links(repo_name, vm_uuid, openid_prefix)
- end
-
# create links
- def setup_repo_vm_links(repo_name, vm_uuid, openid_prefix)
+ def setup(openid_prefix:, repo_name: nil, vm_uuid: nil)
oid_login_perm = create_oid_login_perm openid_prefix
repo_perm = create_user_repo_link repo_name
- vm_login_perm = create_vm_login_permission_link vm_uuid, username
+ vm_login_perm = create_vm_login_permission_link(vm_uuid, username) if vm_uuid
group_perm = create_user_group_link
return [oid_login_perm, repo_perm, vm_login_perm, group_perm, self].compact
@@ -364,13 +360,12 @@ class User < ArvadosModel
merged
end
- def create_oid_login_perm (openid_prefix)
- login_perm_props = { "identity_url_prefix" => openid_prefix}
-
+ def create_oid_login_perm(openid_prefix)
# Check oid_login_perm
oid_login_perms = Link.where(tail_uuid: self.email,
- link_class: 'permission',
- name: 'can_login').where("head_uuid = ?", self.uuid)
+ head_uuid: self.uuid,
+ link_class: 'permission',
+ name: 'can_login')
if !oid_login_perms.any?
# create openid login permission
@@ -378,8 +373,9 @@ class User < ArvadosModel
name: 'can_login',
tail_uuid: self.email,
head_uuid: self.uuid,
- properties: login_perm_props
- )
+ properties: {
+ "identity_url_prefix" => openid_prefix,
+ })
logger.info { "openid login permission: " + oid_login_perm[:uuid] }
else
oid_login_perm = oid_login_perms.first
@@ -407,15 +403,12 @@ class User < ArvadosModel
# create login permission for the given vm_uuid, if it does not already exist
def create_vm_login_permission_link(vm_uuid, repo_name)
# vm uuid is optional
- if vm_uuid
- vm = VirtualMachine.where(uuid: vm_uuid).first
+ return if !vm_uuid
- if not vm
- logger.warn "Could not find virtual machine for #{vm_uuid.inspect}"
- raise "No vm found for #{vm_uuid}"
- end
- else
- return
+ vm = VirtualMachine.where(uuid: vm_uuid).first
+ if !vm
+ logger.warn "Could not find virtual machine for #{vm_uuid.inspect}"
+ raise "No vm found for #{vm_uuid}"
end
logger.info { "vm uuid: " + vm[:uuid] }
@@ -470,7 +463,7 @@ class User < ArvadosModel
# Automatically setup new user during creation
def auto_setup_new_user
- setup_repo_vm_links(nil, nil, Rails.configuration.default_openid_prefix)
+ setup(openid_prefix: Rails.configuration.default_openid_prefix)
if username
create_vm_login_permission_link(Rails.configuration.auto_setup_new_users_with_vm_uuid,
username)
diff --git a/services/api/test/unit/user_test.rb b/services/api/test/unit/user_test.rb
index 742deda..d617873 100644
--- a/services/api/test/unit/user_test.rb
+++ b/services/api/test/unit/user_test.rb
@@ -447,7 +447,9 @@ class UserTest < ActiveSupport::TestCase
vm = VirtualMachine.create
- response = User.setup user, openid_prefix, 'foo/testrepo', vm.uuid
+ response = user.setup(openid_prefix: openid_prefix,
+ repo_name: 'foo/testrepo',
+ vm_uuid: vm.uuid)
resp_user = find_obj_in_resp response, 'User'
verify_user resp_user, email
@@ -490,7 +492,9 @@ class UserTest < ActiveSupport::TestCase
verify_link resp_link, 'permission', 'can_login', email, bad_uuid
- response = User.setup user, openid_prefix, 'foo/testrepo', vm.uuid
+ response = user.setup(openid_prefix: openid_prefix,
+ repo_name: 'foo/testrepo',
+ vm_uuid: vm.uuid)
resp_user = find_obj_in_resp response, 'User'
verify_user resp_user, email
@@ -522,7 +526,7 @@ class UserTest < ActiveSupport::TestCase
user = User.create ({uuid: 'zzzzz-tpzed-abcdefghijklmno', email: email})
- response = User.setup user, openid_prefix
+ response = user.setup(openid_prefix: openid_prefix)
resp_user = find_obj_in_resp response, 'User'
verify_user resp_user, email
@@ -537,7 +541,8 @@ class UserTest < ActiveSupport::TestCase
verify_link group_perm, 'permission', 'can_read', resp_user[:uuid], nil
# invoke setup again with repo_name
- response = User.setup user, openid_prefix, 'foo/testrepo'
+ response = user.setup(openid_prefix: openid_prefix,
+ repo_name: 'foo/testrepo')
resp_user = find_obj_in_resp response, 'User', nil
verify_user resp_user, email
assert_equal user.uuid, resp_user[:uuid], 'expected uuid not found'
@@ -551,7 +556,9 @@ class UserTest < ActiveSupport::TestCase
# invoke setup again with a vm_uuid
vm = VirtualMachine.create
- response = User.setup user, openid_prefix, 'foo/testrepo', vm.uuid
+ response = user.setup(openid_prefix: openid_prefix,
+ repo_name: 'foo/testrepo',
+ vm_uuid: vm.uuid)
resp_user = find_obj_in_resp response, 'User', nil
verify_user resp_user, email
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list