BigW Consortium Gitlab

personal_projects_finder.rb 783 Bytes
Newer Older
1
class PersonalProjectsFinder < UnionFinder
2 3 4 5 6 7 8 9 10 11 12 13
  def initialize(user)
    @user = user
  end

  # Finds the projects belonging to the user in "@user", limited to either
  # public projects or projects visible to the given user.
  #
  # current_user - When given the list of projects is limited to those only
  #                visible by this user.
  #
  # Returns an ActiveRecord::Relation.
  def execute(current_user = nil)
14
    segments = all_projects(current_user)
15

16
    find_union(segments, Project).includes(:namespace).order_id_desc
17 18 19 20
  end

  private

21 22
  def all_projects(current_user)
    projects = []
23

24 25
    projects << @user.personal_projects.visible_to_user(current_user) if current_user
    projects << @user.personal_projects.public_to_user(current_user)
Felipe Artur committed
26

27
    projects
Felipe Artur committed
28
  end
29
end