debian-mirror-gitlab/app/finders/personal_projects_finder.rb

30 lines
783 B
Ruby
Raw Normal View History

2016-06-02 11:05:42 +05:30
class PersonalProjectsFinder < UnionFinder
2015-11-26 14:37:03 +05:30
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)
2016-06-02 11:05:42 +05:30
segments = all_projects(current_user)
2015-11-26 14:37:03 +05:30
2016-06-02 11:05:42 +05:30
find_union(segments, Project).includes(:namespace).order_id_desc
2015-11-26 14:37:03 +05:30
end
private
2016-06-02 11:05:42 +05:30
def all_projects(current_user)
projects = []
2015-11-26 14:37:03 +05:30
2016-06-02 11:05:42 +05:30
projects << @user.personal_projects.visible_to_user(current_user) if current_user
projects << @user.personal_projects.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
end