2018-09-11 15:08:34 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-03-20 16:03:53 -04:00
|
|
|
class PersonalProjectsFinder < UnionFinder
|
2018-07-24 08:46:19 -04:00
|
|
|
include Gitlab::Allowable
|
|
|
|
|
2018-07-08 15:43:06 -04:00
|
|
|
def initialize(user, params = {})
|
2015-11-18 06:21:06 -05:00
|
|
|
@user = user
|
2018-07-08 15:43:06 -04:00
|
|
|
@params = params
|
2015-11-18 06:21:06 -05:00
|
|
|
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.
|
2018-07-08 15:43:06 -04:00
|
|
|
# params - Optional query parameters
|
|
|
|
# min_access_level: integer
|
2015-11-18 06:21:06 -05:00
|
|
|
#
|
|
|
|
# Returns an ActiveRecord::Relation.
|
|
|
|
def execute(current_user = nil)
|
2018-07-24 08:46:19 -04:00
|
|
|
return Project.none unless can?(current_user, :read_user_profile, @user)
|
|
|
|
|
2016-03-20 16:03:53 -04:00
|
|
|
segments = all_projects(current_user)
|
2015-11-18 06:21:06 -05:00
|
|
|
|
2020-01-24 07:09:01 -05:00
|
|
|
find_union(segments, Project).with_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)
|
2021-11-22 16:10:35 -05:00
|
|
|
return [@user.personal_projects] if current_user && current_user.can_read_all_resources?
|
2018-07-08 15:43:06 -04:00
|
|
|
return [projects_with_min_access_level(current_user)] if current_user && min_access_level?
|
2015-11-18 06:21:06 -05:00
|
|
|
|
2018-07-08 15:43:06 -04:00
|
|
|
projects = []
|
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)
|
|
|
|
projects
|
2016-03-17 18:42:46 -04:00
|
|
|
end
|
2018-07-08 15:43:06 -04:00
|
|
|
|
|
|
|
def projects_with_min_access_level(current_user)
|
|
|
|
@user
|
|
|
|
.personal_projects
|
|
|
|
.visible_to_user_and_access_level(current_user, @params[:min_access_level])
|
|
|
|
end
|
|
|
|
|
|
|
|
def min_access_level?
|
|
|
|
@params[:min_access_level].present?
|
|
|
|
end
|
2015-11-18 06:21:06 -05:00
|
|
|
end
|