2016-06-02 11:05:42 +05:30
|
|
|
class ProjectsFinder < UnionFinder
|
2016-09-13 17:45:13 +05:30
|
|
|
def execute(current_user = nil, project_ids_relation = nil)
|
2016-06-02 11:05:42 +05:30
|
|
|
segments = all_projects(current_user)
|
2016-09-13 17:45:13 +05:30
|
|
|
segments.map! { |s| s.where(id: project_ids_relation) } if project_ids_relation
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
find_union(segments, Project)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def all_projects(current_user)
|
2016-06-02 11:05:42 +05:30
|
|
|
projects = []
|
2015-11-26 14:37:03 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
projects << current_user.authorized_projects if current_user
|
|
|
|
projects << Project.unscoped.public_to_user(current_user)
|
2015-11-26 14:37:03 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
projects
|
2015-11-26 14:37:03 +05:30
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|