summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2018-11-01 21:49:28 +0000
committerRobert Speicher <robert@gitlab.com>2018-11-01 21:49:28 +0000
commiteab26218e65c388b49cdc502ea25d80c41d5284a (patch)
treefa3a8fea0ab16715dcc358a99a73eb188932c5a8
parent392e3bfad3c39dc4e4e8237b71e2ed9fd9bffcb0 (diff)
parent3e6358585147a39b09cd639a75ffa3b2f13a2003 (diff)
downloadgitlab-ce-eab26218e65c388b49cdc502ea25d80c41d5284a.tar.gz
Merge branch 'user-model-merge-conflicts' into 'master'
Reduce merge conflicts in the User model See merge request gitlab-org/gitlab-ce!22697
-rw-r--r--app/models/key.rb4
-rw-r--r--app/models/user.rb9
2 files changed, 11 insertions, 2 deletions
diff --git a/app/models/key.rb b/app/models/key.rb
index bdb83e12793..8f93418b88b 100644
--- a/app/models/key.rb
+++ b/app/models/key.rb
@@ -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)
diff --git a/app/models/user.rb b/app/models/user.rb
index cc2cd1b7723..d3eb7162174 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -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
@@ -941,12 +941,17 @@ class User < ActiveRecord::Base
if !Gitlab.config.ldap.enabled
false
elsif ldap_user?
- !last_credential_check_at || (last_credential_check_at + 1.hour) < Time.now
+ !last_credential_check_at || (last_credential_check_at + ldap_sync_time) < Time.now
else
false
end
end
+ def ldap_sync_time
+ # This number resides in this method so it can be redefined in EE.
+ 1.hour
+ end
+
def try_obtain_ldap_lease
# After obtaining this lease LDAP checks will be blocked for 600 seconds
# (10 minutes) for this user.