profile.rb 1.57 KB
Newer Older
gfyoung's avatar
gfyoung committed
1
2
# frozen_string_literal: true

3
4
module Emails
  module Profile
5
    def new_user_email(user_id, token = nil)
Douwe Maan's avatar
Douwe Maan committed
6
      @current_user = @user = User.find(user_id)
7
      @target_url = user_url(@user)
8
      @token = token
9
      mail(to: @user.notification_email, subject: subject("Account was created for you"))
10
11
    end

12
    # rubocop: disable CodeReuse/ActiveRecord
13
    def new_ssh_key_email(key_id)
14
      @key = Key.find_by(id: key_id)
15
16
17

      return unless @key

Douwe Maan's avatar
Douwe Maan committed
18
      @current_user = @user = @key.user
19
      @target_url = user_url(@user)
20
      mail(to: @user.notification_email, subject: subject("SSH key was added to your account"))
21
    end
22
    # rubocop: enable CodeReuse/ActiveRecord
23

24
    # rubocop: disable CodeReuse/ActiveRecord
25
    def new_gpg_key_email(gpg_key_id)
26
      @gpg_key = GpgKey.find_by(id: gpg_key_id)
27
28
29
30
31
32
33

      return unless @gpg_key

      @current_user = @user = @gpg_key.user
      @target_url = user_url(@user)
      mail(to: @user.notification_email, subject: subject("GPG key was added to your account"))
    end
34
    # rubocop: enable CodeReuse/ActiveRecord
35
36
37
38
39
40
41
42
43
44
45
46

    def access_token_about_to_expire_email(user)
      return unless user

      @user = user
      @target_url = profile_personal_access_tokens_url
      @days_to_expire = PersonalAccessToken::DAYS_TO_EXPIRE

      Gitlab::I18n.with_locale(@user.preferred_language) do
        mail(to: @user.notification_email, subject: subject(_("Your Personal Access Tokens will expire in %{days_to_expire} days or less") % { days_to_expire: @days_to_expire }))
      end
    end
47
48
  end
end
49
50

Emails::Profile.prepend_if_ee('EE::Emails::Profile')