Merge branch '3448-keep-put-timestamps'
[arvados.git] / services / api / app / mailers / admin_notifier.rb
1 class AdminNotifier < ActionMailer::Base
2   include AbstractController::Callbacks
3
4   default from: Rails.configuration.admin_notifier_email_from
5   before_filter :load_variables
6
7   def new_user(user)
8     @user = user
9     if not Rails.configuration.new_user_notification_recipients.empty? then
10       @recipients = Rails.configuration.new_user_notification_recipients
11       logger.info "Sending mail to #{@recipients} about new user #{@user.uuid} (#{@user.full_name} <#{@user.email}>)"
12
13       add_to_subject = ''
14       if Rails.configuration.auto_setup_new_users
15         add_to_subject = @user.is_invited ? ' and setup' : ', but not setup'
16       end
17
18       mail(to: @recipients,
19            subject: "#{Rails.configuration.email_subject_prefix}New user created#{add_to_subject} notification"
20           )
21     end
22   end
23
24   def new_inactive_user(user)
25     @user = user
26     if not Rails.configuration.new_inactive_user_notification_recipients.empty? then
27       @recipients = Rails.configuration.new_inactive_user_notification_recipients
28       logger.info "Sending mail to #{@recipients} about new user #{@user.uuid} (#{@user.full_name} <#{@user.email}>)"
29       mail(to: @recipients,
30            subject: "#{Rails.configuration.email_subject_prefix}New inactive user notification"
31           )
32     end
33   end
34
35 private
36   def load_variables
37     if Rails.configuration.respond_to?('workbench_address') and
38        not Rails.configuration.workbench_address.nil? and
39        not Rails.configuration.workbench_address.empty? then
40       @wb_address = Rails.configuration.workbench_address.sub(/\/$/,'') + '/users'
41     else
42       @wb_address = ''
43     end
44   end
45
46 end