2016-03-20 20:03:53 +00:00
|
|
|
class JoinedGroupsFinder < UnionFinder
|
2016-03-16 22:44:33 +00:00
|
|
|
def initialize(user)
|
2016-03-09 00:01:33 +00:00
|
|
|
@user = user
|
|
|
|
end
|
|
|
|
|
|
|
|
# Finds the groups of the source user, optionally limited to those visible to
|
|
|
|
# the current user.
|
|
|
|
def execute(current_user = nil)
|
2016-03-20 20:03:53 +00:00
|
|
|
segments = all_groups(current_user)
|
2016-03-09 00:01:33 +00:00
|
|
|
|
2016-03-20 20:03:53 +00:00
|
|
|
find_union(segments, Group).order_id_desc
|
2016-03-09 00:01:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-03-20 20:03:53 +00:00
|
|
|
def all_groups(current_user)
|
|
|
|
groups = []
|
2016-03-09 00:01:33 +00:00
|
|
|
|
2016-03-20 20:03:53 +00:00
|
|
|
groups << @user.authorized_groups.visible_to_user(current_user) if current_user
|
|
|
|
groups << @user.authorized_groups.public_to_user(current_user)
|
2016-03-09 00:01:33 +00:00
|
|
|
|
2016-03-20 20:03:53 +00:00
|
|
|
groups
|
2016-03-09 00:01:33 +00:00
|
|
|
end
|
|
|
|
end
|