Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-17 12:07:48 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-17 12:07:48 +0300
commit5bd24a54ef4ce3a38a860eb53b66d062c2382971 (patch)
tree5f5e65571dfcb2c62c27600ee7655dec4b44c923 /app/finders/keys_finder.rb
parent74673d04d25ffed35cbcf17cd42969bed0a4e705 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/finders/keys_finder.rb')
-rw-r--r--app/finders/keys_finder.rb32
1 files changed, 30 insertions, 2 deletions
diff --git a/app/finders/keys_finder.rb b/app/finders/keys_finder.rb
index d6ba7cb290d..6fd914c88cd 100644
--- a/app/finders/keys_finder.rb
+++ b/app/finders/keys_finder.rb
@@ -15,15 +15,43 @@ class KeysFinder
def execute
raise GitLabAccessDeniedError unless current_user.admin?
- raise InvalidFingerprint unless valid_fingerprint_param?
- Key.where(fingerprint_query).first # rubocop: disable CodeReuse/ActiveRecord
+ keys = by_key_type
+ keys = by_user(keys)
+ keys = sort(keys)
+
+ by_fingerprint(keys)
end
private
attr_reader :current_user, :params
+ def by_key_type
+ if params[:key_type] == 'ssh'
+ Key.regular_keys
+ else
+ Key.all
+ end
+ end
+
+ def sort(keys)
+ keys.order_last_used_at_desc
+ end
+
+ def by_user(keys)
+ return keys unless params[:user]
+
+ keys.for_user(params[:user])
+ end
+
+ def by_fingerprint(keys)
+ return keys unless params[:fingerprint].present?
+ raise InvalidFingerprint unless valid_fingerprint_param?
+
+ keys.where(fingerprint_query).first # rubocop: disable CodeReuse/ActiveRecord
+ end
+
def valid_fingerprint_param?
if fingerprint_type == "sha256"
Base64.decode64(fingerprint).length == 32