gitlab-org--gitlab-foss/lib/constraints/namespace_url_constrainer.rb
Dmitriy Zaporozhets 672704f638
Add relative url support to routing contrainers
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2016-10-24 13:51:17 +03:00

24 lines
537 B
Ruby

class NamespaceUrlConstrainer
def matches?(request)
id = request.path
id = id.sub(/\A#{relative_url_root}/, '') if relative_url_root
id = id.sub(/\A\/+/, '').split('/').first
id = id.sub(/.atom\z/, '') if id
if id =~ Gitlab::Regex.namespace_regex
find_resource(id)
end
end
def find_resource(id)
Namespace.find_by_path(id)
end
private
def relative_url_root
if defined?(Gitlab::Application.config.relative_url_root)
Gitlab::Application.config.relative_url_root
end
end
end