2872: Merge branch 'master' into 2872-folder-nav
[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       mail(to: @recipients,
13            subject: "#{Rails.configuration.email_subject_prefix}New user notification"
14           )
15     end
16   end
17
18   def new_inactive_user(user)
19     @user = user
20     if not Rails.configuration.new_inactive_user_notification_recipients.empty? then
21       @recipients = Rails.configuration.new_inactive_user_notification_recipients
22       logger.info "Sending mail to #{@recipients} about new user #{@user.uuid} (#{@user.full_name} <#{@user.email}>)"
23       mail(to: @recipients,
24            subject: "#{Rails.configuration.email_subject_prefix}New inactive user notification"
25           )
26     end
27   end
28
29 private
30   def load_variables
31     if Rails.configuration.respond_to?('workbench_address') and
32        not Rails.configuration.workbench_address.nil? and
33        not Rails.configuration.workbench_address.empty? then
34       @wb_address = Rails.configuration.workbench_address.sub(/\/$/,'') + '/users'
35     else
36       @wb_address = ''
37     end
38   end
39
40 end