2016-03-20 16:03:53 -04:00
|
|
|
class JoinedGroupsFinder < UnionFinder
|
2016-03-16 18:44:33 -04:00
|
|
|
def initialize(user)
|
2016-03-08 19:01:33 -05: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 16:03:53 -04:00
|
|
|
segments = all_groups(current_user)
|
2016-03-08 19:01:33 -05:00
|
|
|
|
2016-03-20 16:03:53 -04:00
|
|
|
find_union(segments, Group).order_id_desc
|
2016-03-08 19:01:33 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-03-20 16:03:53 -04:00
|
|
|
def all_groups(current_user)
|
|
|
|
groups = []
|
2016-03-08 19:01:33 -05:00
|
|
|
|
2016-03-20 16:03:53 -04:00
|
|
|
groups << @user.authorized_groups.visible_to_user(current_user) if current_user
|
|
|
|
groups << @user.authorized_groups.public_to_user(current_user)
|
2016-03-08 19:01:33 -05:00
|
|
|
|
2016-03-20 16:03:53 -04:00
|
|
|
groups
|
2016-03-08 19:01:33 -05:00
|
|
|
end
|
|
|
|
end
|