2018-10-06 23:10:08 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-08 12:56:54 +00:00
|
|
|
module Constraints
|
|
|
|
class ProjectUrlConstrainer
|
2019-11-08 15:06:21 +00:00
|
|
|
def matches?(request, existence_check: true)
|
2018-03-08 12:56:54 +00:00
|
|
|
namespace_path = request.params[:namespace_id]
|
|
|
|
project_path = request.params[:project_id] || request.params[:id]
|
|
|
|
full_path = [namespace_path, project_path].join('/')
|
2016-11-14 14:55:31 +00:00
|
|
|
|
2019-11-08 15:06:21 +00:00
|
|
|
return false unless ProjectPathValidator.valid_path?(full_path)
|
|
|
|
return true unless existence_check
|
|
|
|
|
|
|
|
# We intentionally allow SELECT(*) here so result of this query can be used
|
|
|
|
# as cache for further Project.find_by_full_path calls within request
|
|
|
|
Project.find_by_full_path(full_path, follow_redirects: request.get?).present?
|
2018-03-08 12:56:54 +00:00
|
|
|
end
|
2016-11-14 14:55:31 +00:00
|
|
|
end
|
|
|
|
end
|