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