2018-10-06 19:10:08 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-08 07:56:54 -05:00
|
|
|
module Constraints
|
|
|
|
class ProjectUrlConstrainer
|
2019-11-08 10:06:21 -05:00
|
|
|
def matches?(request, existence_check: true)
|
2018-03-08 07:56:54 -05:00
|
|
|
namespace_path = request.params[:namespace_id]
|
2020-12-01 07:09:17 -05:00
|
|
|
project_path = request.params[:project_id] || request.params[:id]
|
2018-03-08 07:56:54 -05:00
|
|
|
full_path = [namespace_path, project_path].join('/')
|
2016-11-14 09:55:31 -05:00
|
|
|
|
2019-11-08 10:06:21 -05: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 07:56:54 -05:00
|
|
|
end
|
2016-11-14 09:55:31 -05:00
|
|
|
end
|
|
|
|
end
|