summaryrefslogtreecommitdiff
path: root/lib/constraints/project_url_constrainer.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/constraints/project_url_constrainer.rb')
-rw-r--r--lib/constraints/project_url_constrainer.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/constraints/project_url_constrainer.rb b/lib/constraints/project_url_constrainer.rb
new file mode 100644
index 00000000000..730b05bed97
--- /dev/null
+++ b/lib/constraints/project_url_constrainer.rb
@@ -0,0 +1,13 @@
+class ProjectUrlConstrainer
+ def matches?(request)
+ namespace_path = request.params[:namespace_id]
+ project_path = request.params[:project_id] || request.params[:id]
+ full_path = namespace_path + '/' + project_path
+
+ unless ProjectPathValidator.valid?(project_path)
+ return false
+ end
+
+ Project.find_with_namespace(full_path).present?
+ end
+end