From c09ec8260b02c4767c82bcb5b346899193329828 Mon Sep 17 00:00:00 2001 From: radhika chippada Date: Thu, 20 Mar 2014 20:49:14 -0400 Subject: [PATCH 1/1] setup-new-user script using the setup method. --- .../arvados/v1/users_controller.rb | 8 ------- services/api/script/setup-new-user.rb | 10 +++------ .../arvados/v1/users_controller_test.rb | 21 +++++++++---------- 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/services/api/app/controllers/arvados/v1/users_controller.rb b/services/api/app/controllers/arvados/v1/users_controller.rb index 92b84f46ac..adad309fda 100644 --- a/services/api/app/controllers/arvados/v1/users_controller.rb +++ b/services/api/app/controllers/arvados/v1/users_controller.rb @@ -153,14 +153,6 @@ class Arvados::V1::UsersController < ApplicationController if !@object[:email] return end -=begin - if found_objects.size > 1 - logger.warn ("Found #{found_objects.size} users with email #{user_email}. Stop.") - raise ArgumentError.new "Found #{found_objects.size} users with email #{user_email}. Stop." - elsif found_objects.size == 1 - found_object = found_objects.first - end -=end found_objects = User.where('email=?', @object[:email]) found_object = found_objects.first diff --git a/services/api/script/setup-new-user.rb b/services/api/script/setup-new-user.rb index fbdb0b0547..bc0fd4b8aa 100755 --- a/services/api/script/setup-new-user.rb +++ b/services/api/script/setup-new-user.rb @@ -15,10 +15,6 @@ opts = Trollop::options do banner '' opt :debug, <<-eos Show debug messages. - eos - opt :create, <<-eos -Create a new user with the given email address if an existing user \ -is not found. eos opt :openid_prefix, <<-eos, default: 'https://www.google.com/accounts/o8/id' If creating a new user record, require authentication from an OpenID \ @@ -58,9 +54,9 @@ rescue Arvados::TransactionFailedError "with uuid or email #{user_arg.inspect}. Stop." else user = found.first - # Found user. Update ther user links - user = arv.user.setup(repo_name: user_repo_name, vm_uuid: vm_uuid, - user: {email: user[:uuid]}) + # Found user. Update the user links + user = arv.user.setup(user: {email: user[:uuid]}, repo_name: user_repo_name, + vm_uuid: vm_uuid, openid_prefix: opts.openid_prefix) end puts "USER = #{user.inspect}" 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 d4e25ddbdb..319f515721 100644 --- a/services/api/test/functional/arvados/v1/users_controller_test.rb +++ b/services/api/test/functional/arvados/v1/users_controller_test.rb @@ -101,9 +101,9 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase authorize_with :admin post :setup, { + user: {uuid: 'not_an_existing_uuid_and_not_email_format'}, repo_name: 'test_repo', - vm_uuid: 'no_such_vm', - user: {uuid: 'not_an_existing_uuid_and_not_email_format'} + vm_uuid: 'no_such_vm' } response_body = JSON.parse(@response.body) response_errors = response_body['errors'] @@ -121,9 +121,9 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase authorize_with :admin post :setup, { + user: {uuid: inactive_user['uuid']}, repo_name: 'test_repo', - vm_uuid: 'no_such_vm', - user: {uuid: inactive_user['uuid']} + vm_uuid: 'no_such_vm' } assert_response :success @@ -184,9 +184,9 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase authorize_with :admin post :setup, { - repo_name: 'test_repo', + user: {email: 'abc@xyz.com'}, vm_uuid: 'no_such_vm', - user: {email: 'abc@xyz.com'} + repo_name: 'test_repo' } assert_response :success @@ -197,10 +197,9 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase # create again post :setup, { - user_param: 'abc@xyz.com', repo_name: 'test_repo', vm_uuid: 'no_such_vm', - user: {} + user: {email: 'abc@xyz.com'} } assert_response :success @@ -279,13 +278,13 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase authorize_with :admin post :setup, { - repo_name: 'test_repo', - vm_uuid: @vm_uuid, user: { first_name: "in_create_test_first_name", last_name: "test_last_name", email: "test@abc.com" - } + }, + repo_name: 'test_repo', + vm_uuid: @vm_uuid } assert_response :success created = JSON.parse(@response.body) -- 2.30.2