2017-03-07 06:58:14 -05:00
|
|
|
class GroupMembersFinder
|
2017-02-08 10:02:25 -05:00
|
|
|
def initialize(group)
|
|
|
|
@group = group
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
group_members = @group.members
|
|
|
|
|
|
|
|
return group_members unless @group.parent
|
|
|
|
|
2017-06-21 09:48:12 -04:00
|
|
|
parents_members = GroupMember.non_request
|
|
|
|
.where(source_id: @group.ancestors.select(:id))
|
|
|
|
.where.not(user_id: @group.users.select(:id))
|
2017-02-08 10:02:25 -05:00
|
|
|
|
|
|
|
wheres = ["members.id IN (#{group_members.select(:id).to_sql})"]
|
|
|
|
wheres << "members.id IN (#{parents_members.select(:id).to_sql})"
|
|
|
|
|
|
|
|
GroupMember.where(wheres.join(' OR '))
|
|
|
|
end
|
|
|
|
end
|