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>2020-09-19 04:45:44 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-09-19 04:45:44 +0300
commit85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch)
tree9160f299afd8c80c038f08e1545be119f5e3f1e1 /lib/gitlab/group_search_results.rb
parent15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff)
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'lib/gitlab/group_search_results.rb')
-rw-r--r--lib/gitlab/group_search_results.rb30
1 files changed, 17 insertions, 13 deletions
diff --git a/lib/gitlab/group_search_results.rb b/lib/gitlab/group_search_results.rb
index eb4361cdc53..0cc3de297ba 100644
--- a/lib/gitlab/group_search_results.rb
+++ b/lib/gitlab/group_search_results.rb
@@ -4,28 +4,32 @@ module Gitlab
class GroupSearchResults < SearchResults
attr_reader :group
- def initialize(current_user, limit_projects, group, query, default_project_filter: false)
- super(current_user, limit_projects, query, default_project_filter: default_project_filter)
-
+ def initialize(current_user, query, limit_projects = nil, group:, default_project_filter: false, filters: {})
@group = group
+
+ super(current_user, query, limit_projects, default_project_filter: default_project_filter, filters: filters)
end
# rubocop:disable CodeReuse/ActiveRecord
def users
- # 1: get all groups the current user has access to
- groups = GroupsFinder.new(current_user).execute.joins(:users)
+ # get all groups the current user has access to
+ # ignore order inherited from GroupsFinder to improve performance
+ current_user_groups = GroupsFinder.new(current_user).execute.unscope(:order)
+
+ # the hierarchy of the current group
+ group_groups = @group.self_and_hierarchy.unscope(:order)
+
+ # the groups where the above hierarchies intersect
+ intersect_groups = group_groups.where(id: current_user_groups)
- # 2: Get the group's whole hierarchy
- group_users = @group.direct_and_indirect_users
+ # members of @group hierarchy where the user has access to the groups
+ members = GroupMember.where(group: intersect_groups).non_invite
- # 3: get all users the current user has access to (->
- # `SearchResults#users`), which also applies the query.
+ # get all users the current user has access to (-> `SearchResults#users`), which also applies the query
users = super
- # 4: filter for users that belong to the previously selected groups
- users
- .where(id: group_users.select('id'))
- .where(id: groups.select('members.user_id'))
+ # filter users that belong to the previously selected groups
+ users.where(id: members.select(:user_id))
end
# rubocop:enable CodeReuse/ActiveRecord