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-11-04 19:09:16 -05:00
|
|
|
def initialize(current_user, query, limit_projects = nil, group:, default_project_filter: false, order_by: nil, sort: nil, filters: {})
|
2018-08-15 09:25:17 -04:00
|
|
|
@group = group
|
2020-08-20 23:10:16 -04:00
|
|
|
|
2020-11-04 19:09:16 -05:00
|
|
|
super(current_user, query, limit_projects, default_project_filter: default_project_filter, order_by: order_by, sort: sort, filters: filters)
|
2018-08-15 09:25:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# rubocop:disable CodeReuse/ActiveRecord
|
|
|
|
def users
|
2020-08-28 14:10:51 -04:00
|
|
|
# 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)
|
2018-09-17 11:37:20 -04:00
|
|
|
|
2020-08-28 14:10:51 -04:00
|
|
|
# the hierarchy of the current group
|
|
|
|
group_groups = @group.self_and_hierarchy.unscope(:order)
|
2018-12-17 08:30:49 -05:00
|
|
|
|
2020-08-28 14:10:51 -04:00
|
|
|
# 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
|
2018-09-17 11:37:20 -04:00
|
|
|
users = super
|
|
|
|
|
2020-08-28 14:10:51 -04:00
|
|
|
# filter users that belong to the previously selected groups
|
|
|
|
users.where(id: members.select(: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
|
2020-09-29 23:09:46 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Gitlab::GroupSearchResults.prepend_mod_with('Gitlab::GroupSearchResults')
|