Merge branch 'master' into 2272-setup-user-in-workbench
[arvados.git] / services / api / app / mailers / admin_notifier.rb
1 class AdminNotifier < ActionMailer::Base
2   default from: Rails.configuration.admin_notifier_email_from
3
4   def after_create(model, *args)
5     self.generic_callback('after_create', model, *args)
6   end
7
8   protected
9
10   def generic_callback(callback_type, model, *args)
11     model_specific_method = "#{callback_type}_#{model.class.to_s.underscore}".to_sym
12     if self.respond_to? model_specific_method
13       self.send model_specific_method, model, *args
14     end
15   end
16
17   def all_admin_emails()
18     User.
19       where(is_admin: true).
20       collect(&:email).
21       compact.
22       uniq.
23       select { |e| e.match /\@/ }
24   end
25
26   def after_create_user(user, *args)
27     @new_user = user
28     logger.info "Sending mail to #{@recipients} about new user #{@new_user.uuid} (#{@new_user.full_name}, #{@new_user.email})"
29     mail({
30            to: self.all_admin_emails,
31            subject: "#{Rails.configuration.email_subject_prefix}New user: #{@new_user.full_name}, #{@new_user.email}"
32          })
33   end
34 end