diff options
author | Rubén Dávila <ruben@gitlab.com> | 2017-09-28 00:11:42 +0300 |
---|---|---|
committer | Rubén Dávila <ruben@gitlab.com> | 2017-10-05 16:25:27 +0300 |
commit | a41e7e0105e238161ba697ebf26d8554ae59d295 (patch) | |
tree | 2569ea57cecdfeadb8584b721a255ae4d5f6dbc4 /app/models/gpg_key.rb | |
parent | d0572d9aad2c434a040f11956a4c3feac1afdcf8 (diff) |
Add ability to include subkeys when finding by fingerprint
Diffstat (limited to 'app/models/gpg_key.rb')
-rw-r--r-- | app/models/gpg_key.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/app/models/gpg_key.rb b/app/models/gpg_key.rb index ed09b44027c..6d3537b6fcf 100644 --- a/app/models/gpg_key.rb +++ b/app/models/gpg_key.rb @@ -40,6 +40,17 @@ class GpgKey < ActiveRecord::Base after_commit :update_invalid_gpg_signatures, on: :create after_create :generate_subkeys + def self.find_with_subkeys(fingerprint) + keys_table = arel_table + subkeys_table = GpgKeySubkey.arel_table + + condition = keys_table[:primary_keyid].eq(fingerprint).or( + subkeys_table[:keyid].eq(fingerprint) + ) + + joins(:subkeys).where(condition).first + end + def primary_keyid super&.upcase end |