diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-20 23:50:22 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-20 23:50:22 +0000 |
commit | 9dc93a4519d9d5d7be48ff274127136236a3adb3 (patch) | |
tree | 70467ae3692a0e35e5ea56bcb803eb512a10bedb /app/finders/group_members_finder.rb | |
parent | 4b0f34b6d759d6299322b3a54453e930c6121ff0 (diff) | |
download | gitlab-ce-13.11.0-rc43.tar.gz |
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc43
Diffstat (limited to 'app/finders/group_members_finder.rb')
-rw-r--r-- | app/finders/group_members_finder.rb | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/app/finders/group_members_finder.rb b/app/finders/group_members_finder.rb index 2417b1e0771..a6ecd835527 100644 --- a/app/finders/group_members_finder.rb +++ b/app/finders/group_members_finder.rb @@ -21,28 +21,13 @@ class GroupMembersFinder < UnionFinder end def execute(include_relations: DEFAULT_RELATIONS) - group_members = group_members_list - relations = [] + return filter_members(group_members_list) if include_relations == [:direct] - return filter_members(group_members) if include_relations == [:direct] + groups = groups_by_relations(include_relations) + return GroupMember.none unless groups - relations << group_members if include_relations.include?(:direct) + members = all_group_members(groups).distinct_on_user_with_max_access_level - if include_relations.include?(:inherited) && group.parent - parents_members = relation_group_members(group.ancestors) - - relations << parents_members - end - - if include_relations.include?(:descendants) - descendant_members = relation_group_members(group.descendants) - - relations << descendant_members - end - - return GroupMember.none if relations.empty? - - members = find_union(relations, GroupMember) filter_members(members) end @@ -50,6 +35,25 @@ class GroupMembersFinder < UnionFinder attr_reader :user, :group + def groups_by_relations(include_relations) + case include_relations.sort + when [:inherited] + group.ancestors + when [:descendants] + group.descendants + when [:direct, :inherited] + group.self_and_ancestors + when [:descendants, :direct] + group.self_and_descendants + when [:descendants, :inherited] + find_union([group.ancestors, group.descendants], Group) + when [:descendants, :direct, :inherited] + group.self_and_hierarchy + else + nil + end + end + def filter_members(members) members = members.search(params[:search]) if params[:search].present? members = members.sort_by_attribute(params[:sort]) if params[:sort].present? @@ -69,17 +73,13 @@ class GroupMembersFinder < UnionFinder group.members end - def relation_group_members(relation) - all_group_members(relation).non_minimal_access + def all_group_members(groups) + members_of_groups(groups).non_minimal_access end - # rubocop: disable CodeReuse/ActiveRecord - def all_group_members(relation) - GroupMember.non_request - .where(source_id: relation.select(:id)) - .where.not(user_id: group.users.select(:id)) + def members_of_groups(groups) + GroupMember.non_request.of_groups(groups) end - # rubocop: enable CodeReuse/ActiveRecord end GroupMembersFinder.prepend_if_ee('EE::GroupMembersFinder') |