2018-08-10 07:41:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-06-30 05:17:03 -04:00
|
|
|
module Banzai
|
|
|
|
module ReferenceParser
|
|
|
|
class ProjectParser < BaseParser
|
2018-07-15 07:55:04 -04:00
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
2018-06-30 05:17:03 -04:00
|
|
|
self.reference_type = :project
|
|
|
|
|
|
|
|
def references_relation
|
|
|
|
Project
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-07-04 15:56:09 -04:00
|
|
|
# Returns an Array of Project ids that can be read by the given user.
|
|
|
|
#
|
|
|
|
# user - The User for which to check the projects
|
2018-07-30 15:18:59 -04:00
|
|
|
def readable_project_ids_for(user)
|
|
|
|
@project_ids_by_user ||= {}
|
|
|
|
@project_ids_by_user[user] ||=
|
2021-04-26 08:09:44 -04:00
|
|
|
Project.public_or_visible_to_user(user).where(projects: { id: @projects_for_nodes.values.map(&:id) }).pluck(:id)
|
2018-07-15 07:55:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_read_reference?(user, ref_project, node)
|
2018-07-30 15:18:59 -04:00
|
|
|
readable_project_ids_for(user).include?(ref_project.try(:id))
|
2018-06-30 05:17:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|