X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/cb775c17c561a60b975a97a97fc9c0153f6954d6..355fe24bf5a4ac9e45372333e8bbc8e39b5b86a1:/services/api/app/mailers/admin_notifier.rb diff --git a/services/api/app/mailers/admin_notifier.rb b/services/api/app/mailers/admin_notifier.rb index 5de70053dc..5dd36c047e 100644 --- a/services/api/app/mailers/admin_notifier.rb +++ b/services/api/app/mailers/admin_notifier.rb @@ -1,34 +1,34 @@ class AdminNotifier < ActionMailer::Base + include AbstractController::Callbacks + default from: Rails.configuration.admin_notifier_email_from - def after_create(model, *args) - self.generic_callback('after_create', model, *args) - end + 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}>)" - protected + add_to_subject = '' + if Rails.configuration.auto_setup_new_users + add_to_subject = @user.is_invited ? ' and setup' : ', but not setup' + end - 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 + mail(to: @recipients, + subject: "#{Rails.configuration.email_subject_prefix}New user created#{add_to_subject} notification" + ) end end - def all_admin_emails() - User. - where(is_admin: true). - collect(&:email). - compact. - uniq. - select { |e| e.match /\@/ } + 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 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