From 37dcfb6e31a65d487424c0bf73874aabb2e69020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20D=C3=A1vila?= Date: Tue, 26 Sep 2017 22:10:10 -0500 Subject: [PATCH] Delegate #key to parent when working with a GPG subkey The content returned by #key is important when veryfying the signature, so given we don't want to repeat it in the database for GPG subkeys we need to delegate it to the parent. --- app/models/gpg_key.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/models/gpg_key.rb b/app/models/gpg_key.rb index cbf01183969..683efcebee9 100644 --- a/app/models/gpg_key.rb +++ b/app/models/gpg_key.rb @@ -8,6 +8,7 @@ class GpgKey < ActiveRecord::Base sha_attribute :fingerprint belongs_to :user + belongs_to :parent, class_name: 'GpgKey' has_many :gpg_signatures has_many :subkeys, class_name: 'GpgKey', foreign_key: :parent_id, dependent: :destroy @@ -48,6 +49,10 @@ class GpgKey < ActiveRecord::Base super&.upcase end + def key + parent_id? ? parent.key : super + end + def key=(value) super(value&.strip) end -- GitLab