18004: Fixes a couple of race condition bugs related to caching remote users.
[arvados.git] / services / api / app / mailers / admin_notifier.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 class AdminNotifier < ActionMailer::Base
6   include AbstractController::Callbacks
7
8   default from: Rails.configuration.Users.AdminNotifierEmailFrom
9
10   def new_user(user)
11     @user = user
12     if not Rails.configuration.Users.NewUserNotificationRecipients.empty? then
13       @recipients = Rails.configuration.Users.NewUserNotificationRecipients.keys
14       logger.info "Sending mail to #{@recipients} about new user #{@user.uuid} (#{@user.full_name} <#{@user.email}>)"
15
16       add_to_subject = ''
17       if Rails.configuration.Users.AutoSetupNewUsers
18         add_to_subject = @user.is_invited ? ' and setup' : ', but not setup'
19       end
20
21       mail(to: @recipients,
22            subject: "#{Rails.configuration.Users.EmailSubjectPrefix}New user created#{add_to_subject} notification"
23           )
24     end
25   end
26
27   def new_inactive_user(user)
28     @user = user
29     if not Rails.configuration.Users.NewInactiveUserNotificationRecipients.empty? then
30       @recipients = Rails.configuration.Users.NewInactiveUserNotificationRecipients.keys
31       logger.info "Sending mail to #{@recipients} about new user #{@user.uuid} (#{@user.full_name} <#{@user.email}>)"
32       mail(to: @recipients,
33            subject: "#{Rails.configuration.Users.EmailSubjectPrefix}New inactive user notification"
34           )
35     end
36   end
37
38 end