Commit 25a39e87 authored by Yorick Peterse's avatar Yorick Peterse

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.
parent 4df97b08
...@@ -37,6 +37,10 @@ class Key < ActiveRecord::Base ...@@ -37,6 +37,10 @@ class Key < ActiveRecord::Base
after_destroy :post_destroy_hook after_destroy :post_destroy_hook
after_destroy :refresh_user_cache after_destroy :refresh_user_cache
def self.regular_keys
where(type: ['Key', nil])
end
def key=(value) def key=(value)
write_attribute(:key, value.present? ? Gitlab::SSHPublicKey.sanitize(value) : nil) write_attribute(:key, value.present? ? Gitlab::SSHPublicKey.sanitize(value) : nil)
...@@ -134,3 +138,5 @@ class Key < ActiveRecord::Base ...@@ -134,3 +138,5 @@ class Key < ActiveRecord::Base
"type is forbidden. Must be #{allowed_types}" "type is forbidden. Must be #{allowed_types}"
end end
end end
Key.prepend(EE::Key)
...@@ -88,7 +88,7 @@ class User < ActiveRecord::Base ...@@ -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 has_one :namespace, -> { where(type: nil) }, dependent: :destroy, foreign_key: :owner_id, inverse_of: :owner, autosave: true # rubocop:disable Cop/ActiveRecordDependent
# Profile # Profile
has_many :keys, -> { where(type: ['LDAPKey', '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 :deploy_keys, -> { where(type: 'DeployKey') }, dependent: :nullify # rubocop:disable Cop/ActiveRecordDependent
has_many :gpg_keys has_many :gpg_keys
......
# frozen_string_literal: true
module EE
module Key
extend ActiveSupport::Concern
class_methods do
def regular_keys
where(type: ['LDAPKey', 'Key', nil])
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment