Read about our upcoming Code of Conduct on this issue

group_search_results.rb 1.08 KB
Newer Older
1
2
3
4
# frozen_string_literal: true

module Gitlab
  class GroupSearchResults < SearchResults
5
6
    attr_reader :group

7
8
9
10
11
12
13
14
    def initialize(current_user, limit_projects, group, query, default_project_filter: false, per_page: 20)
      super(current_user, limit_projects, query, default_project_filter: default_project_filter, per_page: per_page)

      @group = group
    end

    # rubocop:disable CodeReuse/ActiveRecord
    def users
15
16
17
      # 1: get all groups the current user has access to
      groups = GroupsFinder.new(current_user).execute.joins(:users)

18
19
20
21
22
      # 2: Get the group's whole hierarchy
      group_users = @group.direct_and_indirect_users

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

25
26
27
28
      # 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'))
29
30
    end
    # rubocop:enable CodeReuse/ActiveRecord
31
32
33
34

    def issuable_params
      super.merge(group_id: group.id)
    end
35
36
  end
end