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-02-17 22:51:56 -05:00
|
|
|
def matches?(request, existence_check: true)
|
2018-03-08 07:56:54 -05: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 09:55:31 -05:00
|
|
|
|
2018-03-08 07:56:54 -05:00
|
|
|
return false unless ProjectPathValidator.valid_path?(full_path)
|
2019-02-17 22:51:56 -05:00
|
|
|
return true unless existence_check
|
2016-11-14 09:55:31 -05:00
|
|
|
|
2018-03-08 07:56:54 -05:00
|
|
|
# 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?
|
|
|
|
end
|
2016-11-14 09:55:31 -05:00
|
|
|
end
|
|
|
|
end
|