2018-08-15 09:25:17 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
class GroupSearchResults < SearchResults
|
2019-05-07 07:08:25 -04:00
|
|
|
attr_reader :group
|
|
|
|
|
2020-05-07 17:09:26 -04:00
|
|
|
def initialize(current_user, limit_projects, group, query, default_project_filter: false)
|
|
|
|
super(current_user, limit_projects, query, default_project_filter: default_project_filter)
|
2018-08-15 09:25:17 -04:00
|
|
|
|
|
|
|
@group = group
|
|
|
|
end
|
|
|
|
|
|
|
|
# rubocop:disable CodeReuse/ActiveRecord
|
|
|
|
def users
|
2018-09-17 11:37:20 -04:00
|
|
|
# 1: get all groups the current user has access to
|
|
|
|
groups = GroupsFinder.new(current_user).execute.joins(:users)
|
|
|
|
|
2018-12-17 08:30:49 -05:00
|
|
|
# 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.
|
2018-09-17 11:37:20 -04:00
|
|
|
users = super
|
|
|
|
|
2018-12-17 08:30:49 -05:00
|
|
|
# 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'))
|
2018-08-15 09:25:17 -04:00
|
|
|
end
|
|
|
|
# rubocop:enable CodeReuse/ActiveRecord
|
2019-05-07 07:08:25 -04:00
|
|
|
|
|
|
|
def issuable_params
|
2020-01-15 13:08:34 -05:00
|
|
|
super.merge(group_id: group.id, include_subgroups: true)
|
2019-05-07 07:08:25 -04:00
|
|
|
end
|
2018-08-15 09:25:17 -04:00
|
|
|
end
|
|
|
|
end
|