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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

44 lines
1.3 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2016-06-02 11:05:42 +05:30
class ContributedProjectsFinder < UnionFinder
2015-11-26 14:37:03 +05:30
def initialize(user)
@user = user
end
# Finds the projects "@user" contributed to, limited to either public projects
# or projects visible to the given user.
#
# current_user - When given the list of the projects is limited to those only
# visible by this user.
#
2022-08-13 15:12:31 +05:30
# ignore_visibility - When true the list of projects will include all contributed
# projects, regardless of their visibility to the current_user
#
2015-11-26 14:37:03 +05:30
# Returns an ActiveRecord::Relation.
2022-08-13 15:12:31 +05:30
def execute(current_user = nil, ignore_visibility: false)
2019-02-02 18:00:53 +05:30
# Do not show contributed projects if the user profile is private.
return Project.none unless can_read_profile?(current_user)
2022-08-13 15:12:31 +05:30
segments = all_projects(current_user, ignore_visibility)
2015-11-26 14:37:03 +05:30
2020-03-13 15:44:24 +05:30
find_union(segments, Project).with_namespace.order_id_desc
2015-11-26 14:37:03 +05:30
end
private
2019-02-02 18:00:53 +05:30
def can_read_profile?(current_user)
Ability.allowed?(current_user, :read_user_profile, @user)
end
2022-08-13 15:12:31 +05:30
def all_projects(current_user, ignore_visibility)
return [@user.contributed_projects] if ignore_visibility
2016-06-02 11:05:42 +05:30
projects = []
2015-11-26 14:37:03 +05:30
2016-06-02 11:05:42 +05:30
projects << @user.contributed_projects.visible_to_user(current_user) if current_user
projects << @user.contributed_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