Class: Gitlab::GroupSearchResults

Inherits:
SearchResults show all
Defined in:
lib/gitlab/group_search_results.rb

Constant Summary

Constants inherited from SearchResults

SearchResults::COUNT_LIMIT, SearchResults::COUNT_LIMIT_MESSAGE, SearchResults::DEFAULT_PAGE, SearchResults::DEFAULT_PER_PAGE, SearchResults::SCOPE_ONLY_SORT

Instance Attribute Summary collapse

Attributes inherited from SearchResults

#current_user, #default_project_filter, #filters, #limit_projects, #order_by, #query, #sort

Instance Method Summary collapse

Methods inherited from SearchResults

#aggregations, #count_limit, #formatted_count, #formatted_limited_count, #highlight_map, #limited_issues_count, #limited_merge_requests_count, #limited_milestones_count, #limited_projects_count, #limited_users_count, #objects

Constructor Details

#initialize(current_user, query, limit_projects = nil, group:, default_project_filter: false, order_by: nil, sort: nil, filters: {}) ⇒ GroupSearchResults

Returns a new instance of GroupSearchResults.


7
8
9
10
11
# File 'lib/gitlab/group_search_results.rb', line 7

def initialize(current_user, query, limit_projects = nil, group:, default_project_filter: false, order_by: nil, sort: nil, filters: {})
  @group = group

  super(current_user, query, limit_projects, default_project_filter: default_project_filter, order_by: order_by, sort: sort, filters: filters)
end

Instance Attribute Details

#groupObject (readonly)

Returns the value of attribute group.


5
6
7
# File 'lib/gitlab/group_search_results.rb', line 5

def group
  @group
end

Instance Method Details

#issuable_paramsObject

rubocop:enable CodeReuse/ActiveRecord


36
37
38
# File 'lib/gitlab/group_search_results.rb', line 36

def issuable_params
  super.merge(group_id: group.id, include_subgroups: true)
end

#usersObject

rubocop:disable CodeReuse/ActiveRecord


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gitlab/group_search_results.rb', line 14

def 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)

  # members of @group hierarchy where the user has access to the groups
  members = GroupMember.where(group: intersect_groups).non_invite

  # get all users the current user has access to (-> `SearchResults#users`), which also applies the query
  users = super

  #  filter users that belong to the previously selected groups
  users.where(id: members.select(:user_id))
end