Read about our upcoming Code of Conduct on this issue

projects_finder.rb 490 Bytes
Newer Older
Douwe Maan's avatar
Douwe Maan committed
1
class ProjectsFinder < UnionFinder
2
  def execute(current_user = nil, project_ids_relation = nil)
Douwe Maan's avatar
Douwe Maan committed
3
    segments = all_projects(current_user)
4
    segments.map! { |s| s.where(id: project_ids_relation) } if project_ids_relation
5

6
    find_union(segments, Project).with_route
7
8
9
10
  end

  private

11
  def all_projects(current_user)
Douwe Maan's avatar
Douwe Maan committed
12
    projects = []
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg committed
13

Douwe Maan's avatar
Douwe Maan committed
14
15
    projects << current_user.authorized_projects if current_user
    projects << Project.unscoped.public_to_user(current_user)
16

Douwe Maan's avatar
Douwe Maan committed
17
    projects
18
  end
19
end