From 6b90ccb9fd57401912e1978cbad28cc693a2e0a1 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 6 Oct 2016 15:14:24 +0300 Subject: Change user & group landing page routing from /u/:name & /groups/:name to /:name Signed-off-by: Dmitriy Zaporozhets --- lib/constraints/group_url_constrainer.rb | 7 +++++++ lib/constraints/namespace_url_constrainer.rb | 13 +++++++++++++ lib/constraints/user_url_constrainer.rb | 7 +++++++ 3 files changed, 27 insertions(+) create mode 100644 lib/constraints/group_url_constrainer.rb create mode 100644 lib/constraints/namespace_url_constrainer.rb create mode 100644 lib/constraints/user_url_constrainer.rb (limited to 'lib/constraints') diff --git a/lib/constraints/group_url_constrainer.rb b/lib/constraints/group_url_constrainer.rb new file mode 100644 index 00000000000..ca39b1961ae --- /dev/null +++ b/lib/constraints/group_url_constrainer.rb @@ -0,0 +1,7 @@ +require 'constraints/namespace_url_constrainer' + +class GroupUrlConstrainer < NamespaceUrlConstrainer + def find_resource(id) + Group.find_by_path(id) + end +end diff --git a/lib/constraints/namespace_url_constrainer.rb b/lib/constraints/namespace_url_constrainer.rb new file mode 100644 index 00000000000..23920193743 --- /dev/null +++ b/lib/constraints/namespace_url_constrainer.rb @@ -0,0 +1,13 @@ +class NamespaceUrlConstrainer + def matches?(request) + id = request.path.sub(/\A\/+/, '').split('/').first.sub(/.atom\z/, '') + + if id =~ Gitlab::Regex.namespace_regex + find_resource(id) + end + end + + def find_resource(id) + Namespace.find_by_path(id) + end +end diff --git a/lib/constraints/user_url_constrainer.rb b/lib/constraints/user_url_constrainer.rb new file mode 100644 index 00000000000..ef38d47d5c6 --- /dev/null +++ b/lib/constraints/user_url_constrainer.rb @@ -0,0 +1,7 @@ +require 'constraints/namespace_url_constrainer' + +class UserUrlConstrainer < NamespaceUrlConstrainer + def find_resource(id) + User.find_by_username(id) + end +end -- cgit v1.2.1