Use a method for the has_many :keys in Project
This moves the `where` in the `has_many :keys` association in Project to the Key model. This allows EE to override this method, instead of modifying the source code directly.
This commit is contained in:
parent
0345b68330
commit
3e63585851
|
|
@ -34,6 +34,10 @@ class Key < ActiveRecord::Base
|
|||
after_destroy :post_destroy_hook
|
||||
after_destroy :refresh_user_cache
|
||||
|
||||
def self.regular_keys
|
||||
where(type: ['Key', nil])
|
||||
end
|
||||
|
||||
def key=(value)
|
||||
write_attribute(:key, value.present? ? Gitlab::SSHPublicKey.sanitize(value) : nil)
|
||||
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ class User < ActiveRecord::Base
|
|||
has_one :namespace, -> { where(type: nil) }, dependent: :destroy, foreign_key: :owner_id, inverse_of: :owner, autosave: true # rubocop:disable Cop/ActiveRecordDependent
|
||||
|
||||
# Profile
|
||||
has_many :keys, -> { where(type: ['Key', nil]) }, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
|
||||
has_many :keys, -> { regular_keys }, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
|
||||
has_many :deploy_keys, -> { where(type: 'DeployKey') }, dependent: :nullify # rubocop:disable Cop/ActiveRecordDependent
|
||||
has_many :gpg_keys
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue