@notification_count = ''
end
end
+
+ helper_method :my_folders
+ def my_folders
+ return @my_folders if @my_folders
+ @my_folders = []
+ root_of = {}
+ Group.filter([['group_class','=','folder']]).each do |g|
+ root_of[g.uuid] = g.owner_uuid
+ @my_folders << g
+ end
+ done = false
+ while not done
+ done = true
+ root_of = root_of.each_with_object({}) do |(child, parent), h|
+ if root_of[parent]
+ h[child] = root_of[parent]
+ done = false
+ else
+ h[child] = parent
+ end
+ end
+ end
+ @my_folders = @my_folders.select do |g|
+ root_of[g.uuid] == current_user.uuid
+ end
+ end
end
def render_editable_attribute(object, attr, attrvalue=nil, htmloptions={})
attrvalue = object.send(attr) if attrvalue.nil?
- return attrvalue if !object.attribute_editable? attr
+ if !object.attribute_editable?(attr, :ever) or
+ (!object.editable? and
+ !object.owner_uuid.in?(my_folders.collect(&:uuid)))
+ return attrvalue
+ end
input_type = 'text'
case object.class.attribute_info[attr.to_sym].andand[:type]
end
end
- unless object.andand.attribute_editable? attr
+ if !object or
+ !object.attribute_editable?(attr, :ever) or
+ (!object.editable? and
+ !object.owner_uuid.in?(my_folders.collect(&:uuid)))
return link_to_if_arvados_object attrvalue
end
class ApiClientAuthorization < ArvadosBase
- def attribute_editable?(attr)
+ def attribute_editable? attr, *args
['expires_at', 'default_owner_uuid'].index attr
end
def self.creatable?
(writable_by.include? current_user.uuid rescue false)))
end
- def attribute_editable?(attr)
+ def attribute_editable?(attr, ever=nil)
if "created_at modified_at modified_by_user_uuid modified_by_client_uuid updated_at".index(attr.to_s)
false
elsif not (current_user.andand.is_active)
false
elsif attr == 'uuid'
current_user.is_admin
+ elsif ever
+ true
else
editable?
end
class AuthorizedKey < ArvadosBase
- def attribute_editable?(attr)
+ def attribute_editable? attr, *args
if attr.to_s == 'authorized_user_uuid'
current_user and current_user.is_admin
else
- super(attr)
+ super
end
end
end
dir_to_tree.call('.')
end
- def attribute_editable?(attr)
+ def attribute_editable? attr, *args
false
end
true
end
- def attribute_editable?(attr)
+ def attribute_editable? attr, *args
false
end
end
end
- def attribute_editable?(attr)
- attr && (attr.to_sym == :name ||
- (attr.to_sym == :components and (self.state == 'New' || self.state == 'Ready')))
+ def attribute_editable? attr, *args
+ super && (attr.to_sym == :name ||
+ (attr.to_sym == :components and
+ (self.state == 'New' || self.state == 'Ready')))
end
def attributes_for_display
super.reject { |k,v| %w(owner_uuid default_owner_uuid identity_url prefs).index k }
end
- def attribute_editable?(attr)
- (not (self.uuid.andand.match(/000000000000000$/) and self.is_admin)) and super(attr)
+ def attribute_editable? attr, *args
+ (not (self.uuid.andand.match(/000000000000000$/) and self.is_admin)) and super
end
def friendly_link_name
def attributes_for_display
super.append ['current_user_logins', @current_user_logins]
end
- def attribute_editable?(attr)
+ def attribute_editable? attr, *args
attr != 'current_user_logins' and super
end
def self.attribute_info
offset_all = @offset
@orders = []
- [Group, Job, PipelineInstance, PipelineTemplate,
- Human, Specimen, Trait,
- Collection].each do |klass|
+ [Group,
+ Job, PipelineInstance, PipelineTemplate,
+ Collection,
+ Human, Specimen, Trait].each do |klass|
@objects = klass.readable_by(*@read_users)
cond_sql = "#{klass.table_name}.owner_uuid = ?"
cond_params = [@object.uuid]
class Arvados::V1::JobTasksController < ApplicationController
+ accept_attribute_as_json :parameters, Hash
end
class Arvados::V1::PipelineInstancesController < ApplicationController
- accept_attribute_as_json :components_summary, Hash
accept_attribute_as_json :components, Hash
accept_attribute_as_json :properties, Hash
+ accept_attribute_as_json :components_summary, Hash
end
class Arvados::V1::UsersController < ApplicationController
+ accept_attribute_as_json :prefs, Hash
+
skip_before_filter :find_object_by_uuid, only:
[:activate, :event_stream, :current, :system, :setup]
skip_before_filter :render_404_if_no_object, only:
class AdminNotifier < ActionMailer::Base
+ include AbstractController::Callbacks
+
default from: Rails.configuration.admin_notifier_email_from
+ before_filter :load_variables
- def after_create(model, *args)
- self.generic_callback('after_create', model, *args)
+ def new_user(user)
+ @user = user
+ if not Rails.configuration.new_user_notification_recipients.empty? then
+ @recipients = Rails.configuration.new_user_notification_recipients
+ logger.info "Sending mail to #{@recipients} about new user #{@user.uuid} (#{@user.full_name} <#{@user.email}>)"
+ mail(to: @recipients,
+ subject: "#{Rails.configuration.email_subject_prefix}New user notification"
+ )
+ end
end
- protected
-
- def generic_callback(callback_type, model, *args)
- model_specific_method = "#{callback_type}_#{model.class.to_s.underscore}".to_sym
- if self.respond_to? model_specific_method
- self.send model_specific_method, model, *args
+ def new_inactive_user(user)
+ @user = user
+ if not Rails.configuration.new_inactive_user_notification_recipients.empty? then
+ @recipients = Rails.configuration.new_inactive_user_notification_recipients
+ logger.info "Sending mail to #{@recipients} about new user #{@user.uuid} (#{@user.full_name} <#{@user.email}>)"
+ mail(to: @recipients,
+ subject: "#{Rails.configuration.email_subject_prefix}New inactive user notification"
+ )
end
end
- def all_admin_emails()
- User.
- where(is_admin: true).
- collect(&:email).
- compact.
- uniq.
- select { |e| e.match /\@/ }
+private
+ def load_variables
+ if Rails.configuration.respond_to?('workbench_address') and
+ not Rails.configuration.workbench_address.nil? and
+ not Rails.configuration.workbench_address.empty? then
+ @wb_address = Rails.configuration.workbench_address.sub(/\/$/,'') + '/users'
+ else
+ @wb_address = ''
+ end
end
- def after_create_user(user, *args)
- @new_user = user
- logger.info "Sending mail to #{@recipients} about new user #{@new_user.uuid} (#{@new_user.full_name}, #{@new_user.email})"
- mail({
- to: self.all_admin_emails,
- subject: "#{Rails.configuration.email_subject_prefix}New user: #{@new_user.full_name}, #{@new_user.email}"
- })
- end
end
after_destroy :maybe_invalidate_permissions_cache
attr_accessor :head_kind, :tail_kind
validate :name_link_has_valid_name
+ validate :name_link_owner_is_tail
api_accessible :user, extend: :common do |t|
t.add :tail_uuid
true
end
end
+
+ def name_link_owner_is_tail
+ if link_class == 'name'
+ self.owner_uuid = tail_uuid
+ ensure_owner_uuid_is_permitted
+ end
+ end
end
belongs_to :pipeline_template, :foreign_key => :pipeline_template_uuid, :primary_key => :uuid
before_validation :bootstrap_components
- before_validation :update_success
+ before_validation :update_state
before_validation :verify_status
before_create :set_state_before_save
before_save :set_state_before_save
t.add :pipeline_template, :if => :pipeline_template
t.add :name
t.add :components
- t.add :success
- t.add :active
t.add :dependencies
t.add :properties
t.add :state
else
row << 0.0
if step['failed']
- self.success = false
+ self.state = Failed
end
end
row << (step['warehousejob']['id'] rescue nil)
end
end
- def update_success
+ def update_state
if components and progress_ratio == 1.0
- self.success = true
+ self.state = Complete
end
end
def verify_status
changed_attributes = self.changed
- if 'state'.in? changed_attributes
- case self.state
- when New, Ready, Paused
- self.active = nil
- self.success = nil
- when RunningOnServer
- self.active = true
- self.success = nil
- when RunningOnClient
- self.active = nil
- self.success = nil
- when Failed
- self.active = false
- self.success = false
- self.state = Failed # before_validation will fail if false is returned in the previous line
- when Complete
- self.active = false
- self.success = true
- else
- return false
- end
- elsif 'success'.in? changed_attributes
- logger.info "pipeline_instance changed_attributes has success for #{self.uuid}"
- if self.success
- self.active = false
- self.state = Complete
- else
- self.active = false
- self.state = Failed
- end
- elsif 'active'.in? changed_attributes
- logger.info "pipeline_instance changed_attributes has active for #{self.uuid}"
- if self.active
- if self.state.in? [New, Ready, Paused]
- self.state = RunningOnServer
- end
- else
- if self.state == RunningOnServer # state was RunningOnServer
- self.active = nil
- self.state = Paused
- elsif self.components_look_ready?
- self.state = Ready
- else
- self.state = New
- end
- end
- elsif new_record? and self.state.nil?
- # No state, active, or success given
- self.state = New
- end
-
if new_record? or 'components'.in? changed_attributes
self.state ||= New
- if self.state == New and self.components_look_ready?
+ if (self.state == New) and self.components_look_ready?
self.state = Ready
end
end
end
def set_state_before_save
- if !self.state || self.state == New || self.state == Ready || self.state == Paused
- if self.active
- self.state = RunningOnServer
- elsif self.components_look_ready? && (!self.state || self.state == New)
- self.state = Ready
- end
+ if self.components_look_ready? && (!self.state || self.state == New)
+ self.state = Ready
end
end
before_update :prevent_inactive_admin
before_create :check_auto_admin
after_create :add_system_group_permission_link
- after_create AdminNotifier
+ after_create :send_admin_notifications
has_many :authorized_keys, :foreign_key => :authorized_user_uuid, :primary_key => :uuid
head_uuid: self.uuid)
end
end
+
+ # Send admin notifications
+ def send_admin_notifications
+ AdminNotifier.new_user(self).deliver
+ if not self.is_active then
+ AdminNotifier.new_inactive_user(self).deliver
+ end
+ end
end
+++ /dev/null
-A user has logged in for the first time.
-
-<%= @new_user.uuid %> -- <%= @new_user.full_name %>, <%= @new_user.email %>
-
-View or activate the user:
-
-<%= users_url %>
--- /dev/null
+
+A new user landed on the inactive user page:
+
+ <%= @user.full_name %> <<%= @user.email %>>
+
+<% if not @wb_address.empty? -%>
+Please see workbench for more information:
+
+ <%= @wb_address %>
+
+<% end -%>
+Thanks,
+Your friendly Arvados robot.
--- /dev/null
+
+A new user has been created:
+
+ <%= @user.full_name %> <<%= @user.email %>>
+
+This user is <%= @user.is_active ? '' : 'NOT ' %>active.
+
+<% if not @wb_address.empty? -%>
+Please see workbench for more information:
+
+ <%= @wb_address %>
+
+<% end -%>
+Thanks,
+Your friendly Arvados robot.
+
<% @objects.each do |o| %>
- <% status = o.success ? 'success' : (o.success == false ? 'failure' : 'pending') %>
+ <% status = (o.state == 'Complete') ? 'success' : ((o.state == 'Failed') ? 'failure' : 'pending') %>
<tr class="pipeline-instance-status pipeline-instance-status-<%= status %>" data-showhide-selector="tr#extra-info-<%= o.uuid %>" style="cursor:pointer">
<td>
<%= status %>
</td><td>
- <%= o.active ? 'yes' : '-' %>
+ <%= (o.state == 'RunningOnServer') ? 'yes' : '-' %>
</td><td>
<%= (o.progress_ratio * 1000).floor / 10 %>
</td><td>
admin_notifier_email_from: arvados@example.com
email_subject_prefix: "[ARVADOS] "
user_notifier_email_from: arvados@example.com
+ new_user_notification_recipients: [ ]
+ new_inactive_user_notification_recipients: [ ]
# Visitors to the API server will be redirected to the workbench
workbench_address: https://workbench.local:3001/
--- /dev/null
+class RemoveActiveAndSuccessFromPipelineInstances < ActiveRecord::Migration
+ include CurrentApiClient
+
+ def up
+ if column_exists?(:pipeline_instances, :active)
+ remove_column :pipeline_instances, :active
+ end
+
+ if column_exists?(:pipeline_instances, :success)
+ remove_column :pipeline_instances, :success
+ end
+ end
+
+ def down
+ if !column_exists?(:pipeline_instances, :success)
+ add_column :pipeline_instances, :success, :boolean, :null => true
+ end
+ if !column_exists?(:pipeline_instances, :active)
+ add_column :pipeline_instances, :active, :boolean, :default => false
+ end
+
+ act_as_system_user do
+ PipelineInstance.all.each do |pi|
+ case pi.state
+ when PipelineInstance::New, PipelineInstance::Ready, PipelineInstance::Paused, PipelineInstance::RunningOnClient
+ pi.active = nil
+ pi.success = nil
+ when PipelineInstance::RunningOnServer
+ pi.active = true
+ pi.success = nil
+ when PipelineInstance::Failed
+ pi.active = false
+ pi.success = false
+ when PipelineInstance::Complete
+ pi.active = false
+ pi.success = true
+ end
+ pi.save!
+ end
+ end
+ end
+end
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20140601022548) do
+ActiveRecord::Schema.define(:version => 20140602143352) do
create_table "api_client_authorizations", :force => true do |t|
t.string "api_token", :null => false
create_table "pipeline_instances", :force => true do |t|
t.string "uuid"
t.string "owner_uuid"
- t.datetime "created_at", :null => false
+ t.datetime "created_at", :null => false
t.string "modified_by_client_uuid"
t.string "modified_by_user_uuid"
t.datetime "modified_at"
t.string "pipeline_template_uuid"
t.string "name"
t.text "components"
- t.boolean "success"
- t.boolean "active", :default => false
- t.datetime "updated_at", :null => false
+ t.datetime "updated_at", :null => false
t.text "properties"
t.string "state"
t.text "components_summary"
require 'test_helper'
+load 'test/functional/arvados/v1/git_setup.rb'
class SerializedEncodingTest < ActionDispatch::IntegrationTest
+ include GitSetup
+
fixtures :all
- test "store json-encoded link with properties hash" do
- post "/arvados/v1/links", {
- :link => {
- :link_class => 'test',
- :name => 'test',
- :properties => {:foo => :bar}
- }.to_json,
- :format => :json
- }, auth(:active)
- assert_response :success
- end
+ {
+ api_client_authorization: {scopes: []},
+
+ human: {properties: {eye_color: 'gray'}},
+
+ job: {
+ repository: 'foo',
+ runtime_constraints: {docker_image: 'arvados/jobs'},
+ script: 'hash',
+ script_version: 'master',
+ script_parameters: {pattern: 'foobar'},
+ tasks_summary: {todo: 0},
+ },
+
+ job_task: {parameters: {pattern: 'foo'}},
+
+ link: {link_class: 'test', name: 'test', properties: {foo: :bar}},
+
+ node: {info: {uptime: 1234}},
+
+ pipeline_instance: {
+ components: {"job1" => {parameters: {pattern: "xyzzy"}}},
+ components_summary: {todo: 0},
+ properties: {test: true},
+ },
+
+ pipeline_template: {
+ components: {"job1" => {parameters: {pattern: "xyzzy"}}},
+ },
+
+ specimen: {properties: {eye_color: 'meringue'}},
+
+ trait: {properties: {eye_color: 'brown'}},
- test "store json-encoded pipeline instance with components_summary hash" do
- post "/arvados/v1/pipeline_instances", {
- :pipeline_instance => {
- :components_summary => {:todo => 0}
- }.to_json,
- :format => :json
- }, auth(:active)
- assert_response :success
+ user: {prefs: {cookies: 'thin mint'}},
+ }.each_pair do |resource, postdata|
+ test "create json-encoded #{resource.to_s}" do
+ post("/arvados/v1/#{resource.to_s.pluralize}",
+ {resource => postdata.to_json}, auth(:admin_trustedclient))
+ assert_response :success
+ end
end
end
test "check active and success for a pipeline in new state" do
pi = pipeline_instances :new_pipeline
- assert !pi.active, 'expected active to be false for :new_pipeline'
- assert !pi.success, 'expected success to be false for :new_pipeline'
assert_equal 'New', pi.state, 'expected state to be New for :new_pipeline'
# save the pipeline and expect state to be New
pi.save
pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
assert_equal PipelineInstance::New, pi.state, 'expected state to be New for new pipeline'
- assert !pi.active, 'expected active to be false for a new pipeline'
- assert !pi.success, 'expected success to be false for a new pipeline'
end
test "check active and success for a newly created pipeline" do
pi.save
assert pi.valid?, 'expected newly created empty pipeline to be valid ' + pi.errors.messages.to_s
- assert !pi.active, 'expected active to be false for a new pipeline'
- assert !pi.success, 'expected success to be false for a new pipeline'
assert_equal 'Ready', pi.state, 'expected state to be Ready for a new empty pipeline'
end
pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
assert_equal PipelineInstance::New, pi.state, 'expected state to be New after adding component with input'
assert_equal pi.components.size, 1, 'expected one component'
- assert !pi.active, 'expected active to be false after update'
- assert !pi.success, 'expected success to be false for a new pipeline'
# add a component with no input not required
component = {'script_parameters' => {"input_not_provided" => {"required" => false}}}
pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
assert_equal PipelineInstance::Ready, pi.state, 'expected state to be Ready after adding component with input'
assert_equal pi.components.size, 1, 'expected one component'
- assert !pi.active, 'expected active to be false after update'
- assert !pi.success, 'expected success to be false for a new pipeline'
# add a component with input and expect state to become Ready
component = {'script_parameters' => {"input" => "yyyad4b39ca5a924e481008009d94e32+210"}}
pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
assert_equal PipelineInstance::Ready, pi.state, 'expected state to be Ready after adding component with input'
assert_equal pi.components.size, 1, 'expected one component'
- assert !pi.active, 'expected active to be false after update'
- assert !pi.success, 'expected success to be false for a new pipeline'
-
- pi.active = true
- assert_equal true, pi.save, 'expected pipeline instance to save, but ' + pi.errors.messages.to_s
- pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
- assert_equal PipelineInstance::RunningOnServer, pi.state, 'expected state to be RunningOnServer after updating active to true'
- assert pi.active, 'expected active to be true after update'
- assert !pi.success, 'expected success to be false for a new pipeline'
-
- pi.success = false
- pi.save
- pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
- assert_equal PipelineInstance::Failed, pi.state, 'expected state to be Failed after updating success to false'
- assert !pi.active, 'expected active to be false after update'
- assert !pi.success, 'expected success to be false for a new pipeline'
pi.state = PipelineInstance::RunningOnServer
pi.save
pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
assert_equal PipelineInstance::RunningOnServer, pi.state, 'expected state to be RunningOnServer after updating state to RunningOnServer'
- assert pi.active, 'expected active to be true after update'
- assert !pi.success, 'expected success to be alse after update'
pi.state = PipelineInstance::Paused
pi.save
pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
assert_equal PipelineInstance::Paused, pi.state, 'expected state to be Paused after updating state to Paused'
- assert !pi.active, 'expected active to be false after update'
- assert !pi.success, 'expected success to be false after update'
pi.state = PipelineInstance::Complete
pi.save
pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
assert_equal PipelineInstance::Complete, pi.state, 'expected state to be Complete after updating state to Complete'
- assert !pi.active, 'expected active to be false after update'
- assert pi.success, 'expected success to be true after update'
pi.state = 'bogus'
pi.save
pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
assert_equal PipelineInstance::Complete, pi.state, 'expected state to be unchanged with set to a bogus value'
- assert !pi.active, 'expected active to be false after update'
- assert pi.success, 'expected success to be true after update'
pi.state = PipelineInstance::Failed
pi.save
pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
assert_equal PipelineInstance::Failed, pi.state, 'expected state to be Failed after updating state to Failed'
- assert !pi.active, 'expected active to be false after update'
- assert !pi.success, 'expected success to be false after update'
end
test "update attributes for pipeline with two components" do
pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
assert_equal PipelineInstance::New, pi.state, 'expected state to be New after adding component with input'
assert_equal pi.components.size, 2, 'expected two components'
- assert !pi.active, 'expected active to be false after update'
- assert !pi.success, 'expected success to be false for a new pipeline'
end
[:has_component_with_no_script_parameters,
pi = pipeline_instances pi_name
Thread.current[:user] = users(:active)
- # Make sure we go through the "active_changed? and active" code:
- assert_equal true, pi.update_attributes(active: true), pi.errors.messages
- assert_equal true, pi.update_attributes(active: false), pi.errors.messages
- assert_equal PipelineInstance::Paused, pi.state
+ assert_equal PipelineInstance::Ready, pi.state
end
end
end
setup do
# Make sure system_user exists before making "pre-test users" list
system_user
-
- @all_users = User.find(:all)
-
- @all_users.each do |user|
- if user.uuid == system_user_uuid
- @system_user = user
- elsif user.is_admin && user.is_active
- @admin_user = user
- elsif user.is_active && !user.is_admin
- @active_user = user
- elsif !user.is_active && !user.is_invited
- @uninvited_user = user
- end
- end
end
test "check non-admin active user properties" do
+ @active_user = users(:active) # get the active user
assert !@active_user.is_admin, 'is_admin should not be set for a non-admin user'
assert @active_user.is_active, 'user should be active'
assert @active_user.is_invited, 'is_invited should be set'
assert @active_user.groups_i_can(:read).size > 0, "active user should be able read at least one group"
# non-admin user cannot manage or write other user objects
+ @uninvited_user = users(:inactive_uninvited) # get the uninvited user
assert !(@active_user.can? :read=>"#{@uninvited_user.uuid}")
assert !(@active_user.can? :write=>"#{@uninvited_user.uuid}")
assert !(@active_user.can? :manage=>"#{@uninvited_user.uuid}")
end
test "check admin user properties" do
+ @admin_user = users(:admin) # get the admin user
assert @admin_user.is_admin, 'is_admin should be set for admin user'
assert @admin_user.is_active, 'admin user cannot be inactive'
assert @admin_user.is_invited, 'is_invited should be set'
assert @admin_user.groups_i_can(:manage).size > 0, "admin active user should be able manage at least one group"
# admin user can also write or manage other users
+ @uninvited_user = users(:inactive_uninvited) # get the uninvited user
assert @admin_user.can? :read=>"#{@uninvited_user.uuid}"
assert @admin_user.can? :write=>"#{@uninvited_user.uuid}"
assert @admin_user.can? :manage=>"#{@uninvited_user.uuid}"
end
test "check inactive and uninvited user properties" do
+ @uninvited_user = users(:inactive_uninvited) # get the uninvited user
assert !@uninvited_user.is_admin, 'is_admin should not be set for a non-admin user'
assert !@uninvited_user.is_active, 'user should be inactive'
assert !@uninvited_user.is_invited, 'is_invited should not be set'
end
test "full name should not contain spurious whitespace" do
- Thread.current[:user] = @admin_user # set admin user as the current user
+ set_user_from_auth :admin
user = User.create ({uuid: 'zzzzz-tpzed-abcdefghijklmno', email: 'foo@example.com' })
end
test "create new user" do
- Thread.current[:user] = @admin_user # set admin user as the current user
+ set_user_from_auth :admin
+
+ @all_users = User.find(:all)
user = User.new
user.first_name = "first_name_for_newly_created_user"
assert_equal(user.first_name, 'first_name_for_newly_created_user_updated')
end
+ test "create new user with notifications" do
+ set_user_from_auth :admin
+
+ user_notification_helper true, 'active-notify-address@example.com', 'inactive-notify-address@example.com'
+ user_notification_helper true, 'active-notify-address@example.com', []
+ user_notification_helper true, [], []
+ user_notification_helper false, 'active-notify-address@example.com', 'inactive-notify-address@example.com'
+ user_notification_helper false, [], 'inactive-notify-address@example.com'
+ user_notification_helper false, [], []
+ end
+
test "update existing user" do
- Thread.current[:user] = @active_user # set active user as current user
+ set_user_from_auth :active # set active user as current user
+
+ @active_user = users(:active) # get the active user
+
@active_user.first_name = "first_name_changed"
@active_user.save
assert_equal(@active_user.first_name, 'first_name_changed')
# admin user also should be able to update the "active" user info
- Thread.current[:user] = @admin_user # set admin user as current user
+ set_user_from_auth :admin # set admin user as current user
@active_user.first_name = "first_name_changed_by_admin_for_active_user"
@active_user.save
end
test "delete a user and verify" do
+ @active_user = users(:active) # get the active user
active_user_uuid = @active_user.uuid
- Thread.current[:user] = @admin_user
+ set_user_from_auth :admin
@active_user.delete
found_deleted_user = false
end
test "create new user as non-admin user" do
- Thread.current[:user] = @active_user
+ set_user_from_auth :active
begin
user = User.new
end
test "setup new user" do
- Thread.current[:user] = @admin_user
+ set_user_from_auth :admin
email = 'foo@example.com'
openid_prefix = 'http://openid/prefix'
end
test "setup new user with junk in database" do
- Thread.current[:user] = @admin_user
+ set_user_from_auth :admin
email = 'foo@example.com'
openid_prefix = 'http://openid/prefix'
test "setup new user in multiple steps" do
- Thread.current[:user] = @admin_user
+ set_user_from_auth :admin
email = 'foo@example.com'
openid_prefix = 'http://openid/prefix'
end
end
+ def user_notification_helper (active, active_recipients, inactive_recipients)
+ Rails.configuration.new_user_notification_recipients = active_recipients
+ Rails.configuration.new_inactive_user_notification_recipients = inactive_recipients
+
+ assert_equal active_recipients, Rails.configuration.new_user_notification_recipients
+ assert_equal inactive_recipients, Rails.configuration.new_inactive_user_notification_recipients
+
+ ActionMailer::Base.deliveries = []
+
+ user = User.new
+ user.first_name = "first_name_for_newly_created_user"
+ user.is_active = active
+ user.save
+
+ new_user_email = nil
+ new_inactive_user_email = nil
+
+ ActionMailer::Base.deliveries.each do |d|
+ if d.subject == "#{Rails.configuration.email_subject_prefix}New user notification" then
+ new_user_email = d
+ elsif d.subject == "#{Rails.configuration.email_subject_prefix}New inactive user notification" then
+ new_inactive_user_email = d
+ end
+ end
+
+ if not active
+ if not inactive_recipients.empty? then
+ assert_not_nil new_inactive_user_email, 'Expected new inactive user email after setup'
+ assert_equal Rails.configuration.user_notifier_email_from, new_inactive_user_email.from[0]
+ assert_equal inactive_recipients, new_inactive_user_email.to[0]
+ assert_equal "#{Rails.configuration.email_subject_prefix}New inactive user notification", new_inactive_user_email.subject
+ else
+ assert_nil new_inactive_user_email, 'Did not expect new inactive user email after setup'
+ end
+ end
+
+ if active
+ assert_nil new_inactive_user_email, 'Expected email after setup'
+ if not active_recipients.empty? then
+ assert_not_nil new_user_email, 'Expected new user email after setup'
+ assert_equal Rails.configuration.user_notifier_email_from, new_user_email.from[0]
+ assert_equal active_recipients, new_user_email.to[0]
+ assert_equal "#{Rails.configuration.email_subject_prefix}New user notification", new_user_email.subject
+ else
+ assert_nil new_user_email, 'Did not expect new user email after setup'
+ end
+ end
+ ActionMailer::Base.deliveries = []
+
+ end
+
end
def tearDown(self):
# llfuse.close is buggy, so use fusermount instead.
#llfuse.close(unmount=True)
- subprocess.call(["fusermount", "-u", self.mounttmp])
+ count = 0
+ success = 1
+ while (count < 9 and success != 0):
+ success = subprocess.call(["fusermount", "-u", self.mounttmp])
+ time.sleep(0.5)
+ count += 1
os.rmdir(self.mounttmp)
shutil.rmtree(self.keeptmp)