diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-17 12:07:48 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-17 12:07:48 +0300 |
commit | 5bd24a54ef4ce3a38a860eb53b66d062c2382971 (patch) | |
tree | 5f5e65571dfcb2c62c27600ee7655dec4b44c923 /app/finders | |
parent | 74673d04d25ffed35cbcf17cd42969bed0a4e705 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/finders')
-rw-r--r-- | app/finders/groups_finder.rb | 2 | ||||
-rw-r--r-- | app/finders/issues_finder.rb | 2 | ||||
-rw-r--r-- | app/finders/keys_finder.rb | 32 | ||||
-rw-r--r-- | app/finders/merge_request_target_project_finder.rb | 20 | ||||
-rw-r--r-- | app/finders/personal_access_tokens_finder.rb | 16 |
5 files changed, 58 insertions, 14 deletions
diff --git a/app/finders/groups_finder.rb b/app/finders/groups_finder.rb index 7d419103b1c..54715557399 100644 --- a/app/finders/groups_finder.rb +++ b/app/finders/groups_finder.rb @@ -45,7 +45,7 @@ class GroupsFinder < UnionFinder def all_groups return [owned_groups] if params[:owned] return [groups_with_min_access_level] if min_access_level? - return [Group.all] if current_user&.full_private_access? && all_available? + return [Group.all] if current_user&.can_read_all_resources? && all_available? groups = [] groups << Gitlab::ObjectHierarchy.new(groups_for_ancestors, groups_for_descendants).all_objects if current_user diff --git a/app/finders/issues_finder.rb b/app/finders/issues_finder.rb index 74e89a1e66c..641b4422db9 100644 --- a/app/finders/issues_finder.rb +++ b/app/finders/issues_finder.rb @@ -127,7 +127,7 @@ class IssuesFinder < IssuableFinder return @user_can_see_all_confidential_issues if defined?(@user_can_see_all_confidential_issues) return @user_can_see_all_confidential_issues = false if current_user.blank? - return @user_can_see_all_confidential_issues = true if current_user.full_private_access? + return @user_can_see_all_confidential_issues = true if current_user.can_read_all_resources? @user_can_see_all_confidential_issues = if project? && project 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 diff --git a/app/finders/merge_request_target_project_finder.rb b/app/finders/merge_request_target_project_finder.rb index 5f0589f6c8b..85a73e0c6ff 100644 --- a/app/finders/merge_request_target_project_finder.rb +++ b/app/finders/merge_request_target_project_finder.rb @@ -11,15 +11,23 @@ class MergeRequestTargetProjectFinder end # rubocop: disable CodeReuse/ActiveRecord - def execute - if @source_project.fork_network - @source_project.fork_network.projects - .public_or_visible_to_user(current_user) - .non_archived - .with_feature_available_for_user(:merge_requests, current_user) + def execute(include_routes: false) + if source_project.fork_network + include_routes ? projects.inc_routes : projects else Project.where(id: source_project) end end # rubocop: enable CodeReuse/ActiveRecord + + private + + def projects + source_project + .fork_network + .projects + .public_or_visible_to_user(current_user) + .non_archived + .with_feature_available_for_user(:merge_requests, current_user) + end end diff --git a/app/finders/personal_access_tokens_finder.rb b/app/finders/personal_access_tokens_finder.rb index bd95dcd323f..7b15a3b0c10 100644 --- a/app/finders/personal_access_tokens_finder.rb +++ b/app/finders/personal_access_tokens_finder.rb @@ -13,18 +13,26 @@ class PersonalAccessTokensFinder tokens = PersonalAccessToken.all tokens = by_user(tokens) tokens = by_impersonation(tokens) - by_state(tokens) + tokens = by_state(tokens) + + sort(tokens) end private - # rubocop: disable CodeReuse/ActiveRecord def by_user(tokens) return tokens unless @params[:user] - tokens.where(user: @params[:user]) + tokens.for_user(@params[:user]) + end + + def sort(tokens) + available_sort_orders = PersonalAccessToken.simple_sorts.keys + + return tokens unless available_sort_orders.include?(params[:sort]) + + tokens.order_by(params[:sort]) end - # rubocop: enable CodeReuse/ActiveRecord def by_impersonation(tokens) case @params[:impersonation] |