2016-03-20 16:03:53 -04:00
|
|
|
class PersonalProjectsFinder < UnionFinder
|
2015-11-18 06:21:06 -05:00
|
|
|
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-03-20 16:03:53 -04:00
|
|
|
segments = all_projects(current_user)
|
2015-11-18 06:21:06 -05:00
|
|
|
|
2018-04-05 10:56:32 -04:00
|
|
|
find_union(segments, Project).includes(:namespace).order_updated_desc
|
2015-11-18 06:21:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-03-20 16:03:53 -04:00
|
|
|
def all_projects(current_user)
|
|
|
|
projects = []
|
2015-11-18 06:21:06 -05:00
|
|
|
|
2016-03-20 16:03:53 -04:00
|
|
|
projects << @user.personal_projects.visible_to_user(current_user) if current_user
|
|
|
|
projects << @user.personal_projects.public_to_user(current_user)
|
2016-03-17 18:42:46 -04:00
|
|
|
|
2016-03-20 16:03:53 -04:00
|
|
|
projects
|
2016-03-17 18:42:46 -04:00
|
|
|
end
|
2015-11-18 06:21:06 -05:00
|
|
|
end
|