2016-03-20 16:03:53 -04:00
|
|
|
class GroupProjectsFinder < UnionFinder
|
|
|
|
def initialize(group, options = {})
|
2016-03-21 18:11:24 -04:00
|
|
|
@group = group
|
2016-03-20 16:03:53 -04:00
|
|
|
@options = options
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute(current_user = nil)
|
|
|
|
segments = group_projects(current_user)
|
|
|
|
find_union(segments, Project)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def group_projects(current_user)
|
2016-03-21 18:11:24 -04:00
|
|
|
only_owned = @options.fetch(:only_owned, false)
|
2016-03-20 16:30:08 -04:00
|
|
|
only_shared = @options.fetch(:only_shared, false)
|
2016-03-20 16:03:53 -04:00
|
|
|
|
|
|
|
projects = []
|
|
|
|
|
|
|
|
if current_user
|
2017-02-06 21:32:34 -05:00
|
|
|
if @group.users.include?(current_user)
|
2016-03-20 16:30:08 -04:00
|
|
|
projects << @group.projects unless only_shared
|
|
|
|
projects << @group.shared_projects unless only_owned
|
2016-03-20 16:03:53 -04:00
|
|
|
else
|
2016-03-20 16:30:08 -04:00
|
|
|
unless only_shared
|
2016-03-20 16:03:53 -04:00
|
|
|
projects << @group.projects.visible_to_user(current_user)
|
|
|
|
projects << @group.projects.public_to_user(current_user)
|
|
|
|
end
|
|
|
|
|
2016-03-20 16:30:08 -04:00
|
|
|
unless only_owned
|
2016-03-20 16:03:53 -04:00
|
|
|
projects << @group.shared_projects.visible_to_user(current_user)
|
|
|
|
projects << @group.shared_projects.public_to_user(current_user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
2016-03-20 16:30:08 -04:00
|
|
|
projects << @group.projects.public_only unless only_shared
|
|
|
|
projects << @group.shared_projects.public_only unless only_owned
|
2016-03-20 16:03:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
projects
|
|
|
|
end
|
|
|
|
end
|