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

47 lines
1.3 KiB
Ruby
Raw Normal View History

2016-06-02 11:05:42 +05:30
class PersonalProjectsFinder < UnionFinder
2018-11-18 11:00:15 +05:30
include Gitlab::Allowable
def initialize(user, params = {})
2015-11-26 14:37:03 +05:30
@user = user
2018-11-18 11:00:15 +05:30
@params = params
2015-11-26 14:37:03 +05:30
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-11-18 11:00:15 +05:30
# params - Optional query parameters
# min_access_level: integer
2015-11-26 14:37:03 +05:30
#
# Returns an ActiveRecord::Relation.
def execute(current_user = nil)
2018-11-18 11:00:15 +05:30
return Project.none unless can?(current_user, :read_user_profile, @user)
2016-06-02 11:05:42 +05:30
segments = all_projects(current_user)
2015-11-26 14:37:03 +05:30
2018-11-08 19:23:39 +05:30
find_union(segments, Project).includes(:namespace).order_updated_desc
2015-11-26 14:37:03 +05:30
end
private
2016-06-02 11:05:42 +05:30
def all_projects(current_user)
2018-11-18 11:00:15 +05:30
return [projects_with_min_access_level(current_user)] if current_user && min_access_level?
2015-11-26 14:37:03 +05:30
2018-11-18 11:00:15 +05:30
projects = []
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)
projects
2015-11-26 14:37:03 +05:30
end
2018-11-18 11:00:15 +05:30
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-26 14:37:03 +05:30
end