def setup(repo_name: nil, vm_uuid: nil, send_notification_email: nil)
newly_invited = Link.where(tail_uuid: self.uuid,
head_uuid: all_users_group_uuid,
- link_class: 'permission',
- name: 'can_read').empty?
+ link_class: 'permission').empty?
# Add can_read link from this user to "all users" which makes this
# user "invited", and (depending on config) a link in the opposite
def self.update_remote_user remote_user
remote_user = remote_user.symbolize_keys
+ remote_user_prefix = remote_user[:uuid][0..4]
+
begin
- user = User.find_or_create_by(uuid: remote_user[:uuid])
+ user = User.create_with(email: remote_user[:email],
+ first_name: remote_user[:first_name],
+ last_name: remote_user[:last_name],
+ ).find_or_create_by(uuid: remote_user[:uuid])
rescue ActiveRecord::RecordNotUnique
retry
end
- remote_user_prefix = user.uuid[0..4]
user.with_lock do
needupdate = {}
[:email, :username, :first_name, :last_name, :prefs].each do |k|
end
end
- if user.is_invited && remote_user[:is_invited] == false
- # Remote user is not "invited" state, they should be unsetup, which
- # also makes them inactive.
+ if user.is_invited && (remote_user[:is_invited] == false || remote_user[:is_active] == false)
+ # Remote user is not "invited" or "active" state on their home
+ # cluster, so they should be unsetup, which also makes them
+ # inactive.
user.unsetup
else
if !user.is_invited && remote_user[:is_invited] and
# Send admin notifications
def send_admin_notifications
- AdminNotifier.new_user(self).deliver_now
- if not self.is_active then
+ if self.is_invited then
+ AdminNotifier.new_user(self).deliver_now
+ else
AdminNotifier.new_inactive_user(self).deliver_now
end
end
}
@stub_token_status = 200
@stub_token_scopes = ["all"]
+ ActionMailer::Base.deliveries = []
end
teardown do
test 'get user from Login cluster' do
Rails.configuration.Login.LoginCluster = 'zbbbb'
+ email_dest = ActiveSupport::OrderedOptions.new
+ email_dest[:'arvados-admin@example.com'] = ActiveSupport::OrderedOptions.new
+ Rails.configuration.Users.UserNotifierEmailBcc = email_dest
+ Rails.configuration.Users.NewUserNotificationRecipients = email_dest
+ Rails.configuration.Users.NewInactiveUserNotificationRecipients = email_dest
+
get '/arvados/v1/users/current',
params: {format: 'json'},
headers: auth(remote: 'zbbbb')
assert_equal true, json_response['is_active']
assert_equal 'foo@example.com', json_response['email']
assert_equal 'barney', json_response['username']
+
+ ActionMailer::Base.deliveries.each do |d|
+ puts "--- delivery #{d.inspect}"
+ end
+
+ assert_equal 2, ActionMailer::Base.deliveries.length
+ assert_equal "Welcome to Arvados - account enabled", ActionMailer::Base.deliveries[0].subject
+ assert_equal "[ARVADOS] New user created notification", ActionMailer::Base.deliveries[1].subject
end
[true, false].each do |trusted|