2016-03-20 20:03:53 +00:00
|
|
|
class ProjectsFinder < UnionFinder
|
2016-08-12 13:52:58 +00:00
|
|
|
def execute(current_user = nil, project_ids_relation = nil)
|
2016-03-20 20:03:53 +00:00
|
|
|
segments = all_projects(current_user)
|
2016-08-12 13:52:58 +00:00
|
|
|
segments.map! { |s| s.where(id: project_ids_relation) } if project_ids_relation
|
2014-02-25 17:15:08 +00:00
|
|
|
|
2017-02-04 18:26:11 +00:00
|
|
|
find_union(segments, Project).with_route
|
2014-02-25 17:15:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2014-06-05 17:37:35 +00:00
|
|
|
def all_projects(current_user)
|
2016-03-20 20:03:53 +00:00
|
|
|
projects = []
|
2016-03-10 21:08:11 +00:00
|
|
|
|
2016-03-20 20:03:53 +00:00
|
|
|
projects << current_user.authorized_projects if current_user
|
|
|
|
projects << Project.unscoped.public_to_user(current_user)
|
2015-11-18 11:21:06 +00:00
|
|
|
|
2016-03-20 20:03:53 +00:00
|
|
|
projects
|
2015-11-18 11:21:06 +00:00
|
|
|
end
|
2014-02-25 17:15:08 +00:00
|
|
|
end
|