diff options
author | Alexis Reigel <mail@koffeinfrei.org> | 2017-02-28 10:49:59 +0100 |
---|---|---|
committer | Alexis Reigel <mail@koffeinfrei.org> | 2017-07-27 15:40:41 +0200 |
commit | c1281982bd7975b45bed5b8e2c5ef5e242ea18fd (patch) | |
tree | a4a76d4cd9ab0d4ca324902355fa60ced1ecdb9b /app | |
parent | f0fe1b9d4397e6c1c6aa2da6e371e234db774fe2 (diff) | |
download | gitlab-ce-c1281982bd7975b45bed5b8e2c5ef5e242ea18fd.tar.gz |
notification email on add new gpg key
Diffstat (limited to 'app')
-rw-r--r-- | app/mailers/emails/profile.rb | 10 | ||||
-rw-r--r-- | app/models/gpg_key.rb | 7 | ||||
-rw-r--r-- | app/services/notification_service.rb | 10 | ||||
-rw-r--r-- | app/views/notify/new_gpg_key_email.html.haml | 10 | ||||
-rw-r--r-- | app/views/notify/new_gpg_key_email.text.erb | 7 |
5 files changed, 44 insertions, 0 deletions
diff --git a/app/mailers/emails/profile.rb b/app/mailers/emails/profile.rb index 256cbcd73a1..4580e1c83bd 100644 --- a/app/mailers/emails/profile.rb +++ b/app/mailers/emails/profile.rb @@ -22,5 +22,15 @@ module Emails @target_url = user_url(@user) mail(to: @user.notification_email, subject: subject("SSH key was added to your account")) end + + def new_gpg_key_email(gpg_key_id) + @gpg_key = GpgKey.find_by_id(gpg_key_id) + + 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 end end diff --git a/app/models/gpg_key.rb b/app/models/gpg_key.rb index 04c7ce2e79f..83a303ae953 100644 --- a/app/models/gpg_key.rb +++ b/app/models/gpg_key.rb @@ -1,4 +1,6 @@ class GpgKey < ActiveRecord::Base + include AfterCommitQueue + KEY_PREFIX = '-----BEGIN PGP PUBLIC KEY BLOCK-----'.freeze belongs_to :user @@ -20,6 +22,7 @@ class GpgKey < ActiveRecord::Base before_validation :extract_fingerprint after_create :add_to_keychain + after_create :notify_user after_destroy :remove_from_keychain def key=(value) @@ -62,4 +65,8 @@ class GpgKey < ActiveRecord::Base def remove_from_keychain Gitlab::Gpg::CurrentKeyChain.remove(fingerprint) end + + def notify_user + run_after_commit { NotificationService.new.new_gpg_key(self) } + end end diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index 3a98a5f6b64..b94921d2a08 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -17,6 +17,16 @@ class NotificationService end end + # Always notify the user about gpg key added + # + # This is a security email so it will be sent even if the user user disabled + # notifications + def new_gpg_key(gpg_key) + if gpg_key.user + mailer.new_gpg_key_email(gpg_key.id).deliver_later + end + end + # Always notify user about email added to profile def new_email(email) if email.user diff --git a/app/views/notify/new_gpg_key_email.html.haml b/app/views/notify/new_gpg_key_email.html.haml new file mode 100644 index 00000000000..4b9350c4e88 --- /dev/null +++ b/app/views/notify/new_gpg_key_email.html.haml @@ -0,0 +1,10 @@ +%p + Hi #{@user.name}! +%p + A new GPG key was added to your account: +%p + Fingerprint: + %code= @gpg_key.fingerprint +%p + If this key was added in error, you can remove it under + = link_to "GPG Keys", profile_gpg_keys_url diff --git a/app/views/notify/new_gpg_key_email.text.erb b/app/views/notify/new_gpg_key_email.text.erb new file mode 100644 index 00000000000..80b5a1fd7ff --- /dev/null +++ b/app/views/notify/new_gpg_key_email.text.erb @@ -0,0 +1,7 @@ +Hi <%= @user.name %>! + +A new GPG key was added to your account: + +Fingerprint: <%= @gpg_key.fingerprint %> + +If this key was added in error, you can remove it at <%= profile_gpg_keys_url %> |