debian-mirror-gitlab/app/finders/group_members_finder.rb

39 lines
1.1 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2019-10-12 21:52:04 +05:30
class GroupMembersFinder < UnionFinder
2017-08-17 22:00:37 +05:30
def initialize(group)
@group = group
end
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2020-01-01 13:55:28 +05:30
def execute(include_relations: [:inherited, :direct])
2017-08-17 22:00:37 +05:30
group_members = @group.members
2019-10-12 21:52:04 +05:30
relations = []
2017-08-17 22:00:37 +05:30
2020-01-01 13:55:28 +05:30
return group_members if include_relations == [:direct]
2017-08-17 22:00:37 +05:30
2020-01-01 13:55:28 +05:30
relations << group_members if include_relations.include?(:direct)
2017-08-17 22:00:37 +05:30
2020-01-01 13:55:28 +05:30
if include_relations.include?(:inherited) && @group.parent
2018-11-08 19:23:39 +05:30
parents_members = GroupMember.non_request
.where(source_id: @group.ancestors.select(:id))
.where.not(user_id: @group.users.select(:id))
2019-10-12 21:52:04 +05:30
relations << parents_members
2018-11-08 19:23:39 +05:30
end
2020-01-01 13:55:28 +05:30
if include_relations.include?(:descendants)
2018-11-08 19:23:39 +05:30
descendant_members = GroupMember.non_request
.where(source_id: @group.descendants.select(:id))
.where.not(user_id: @group.users.select(:id))
2019-10-12 21:52:04 +05:30
relations << descendant_members
2018-11-08 19:23:39 +05:30
end
2017-08-17 22:00:37 +05:30
2019-10-12 21:52:04 +05:30
find_union(relations, GroupMember)
2017-08-17 22:00:37 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2017-08-17 22:00:37 +05:30
end
2019-12-04 20:38:33 +05:30
GroupMembersFinder.prepend_if_ee('EE::GroupMembersFinder')