diff options
author | Alexis Reigel <mail@koffeinfrei.org> | 2017-02-28 17:25:12 +0300 |
---|---|---|
committer | Alexis Reigel <mail@koffeinfrei.org> | 2017-07-27 16:42:04 +0300 |
commit | 8bd94a7304d392ad030295b5dfcd84c0100eddd1 (patch) | |
tree | 0e08bcdb460ad21c25646f686a42f4b743bf0129 /app/models/gpg_key.rb | |
parent | c1281982bd7975b45bed5b8e2c5ef5e242ea18fd (diff) |
remove gpg from keychain when user's email changes
Diffstat (limited to 'app/models/gpg_key.rb')
-rw-r--r-- | app/models/gpg_key.rb | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/app/models/gpg_key.rb b/app/models/gpg_key.rb index 83a303ae953..8332ba3ee6e 100644 --- a/app/models/gpg_key.rb +++ b/app/models/gpg_key.rb @@ -21,9 +21,9 @@ class GpgKey < ActiveRecord::Base unless: -> { errors.has_key?(:key) } before_validation :extract_fingerprint - after_create :add_to_keychain + after_create :synchronize_keychain after_create :notify_user - after_destroy :remove_from_keychain + after_destroy :synchronize_keychain def key=(value) value.strip! unless value.blank? @@ -31,21 +31,32 @@ class GpgKey < ActiveRecord::Base end def emails - Gitlab::Gpg::CurrentKeyChain.emails(fingerprint) + @emails ||= Gitlab::Gpg.emails_from_key(key) end - def emails_with_verified_status - emails_in_key_chain = emails - emails_from_key = Gitlab::Gpg.emails_from_key(key) + def emails_in_keychain + @emails_in_keychain ||= Gitlab::Gpg::CurrentKeyChain.emails(fingerprint) + end - emails_from_key.map do |email| + def emails_with_verified_status + emails.map do |email| [ email, - email == user.email && emails_in_key_chain.include?(email) + email == user.email && emails_in_keychain.include?(email) ] end end + def synchronize_keychain + if emails.include?(user.email) + add_to_keychain + else + remove_from_keychain + end + + @emails_in_keychain = nil + end + private def extract_fingerprint @@ -55,10 +66,6 @@ class GpgKey < ActiveRecord::Base end def add_to_keychain - emails_from_key = Gitlab::Gpg.emails_from_key(key) - - return unless emails_from_key.include?(user.email) - Gitlab::Gpg::CurrentKeyChain.add(key) end |