Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
672704f6
Commit
672704f6
authored
Oct 24, 2016
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add relative url support to routing contrainers
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
1a7ba2a5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
1 deletion
+22
-1
lib/constraints/namespace_url_constrainer.rb
lib/constraints/namespace_url_constrainer.rb
+12
-1
spec/lib/constraints/namespace_url_constrainer_spec.rb
spec/lib/constraints/namespace_url_constrainer_spec.rb
+10
-0
No files found.
lib/constraints/namespace_url_constrainer.rb
View file @
672704f6
class
NamespaceUrlConstrainer
def
matches?
(
request
)
id
=
request
.
path
.
sub
(
/\A\/+/
,
''
).
split
(
'/'
).
first
.
sub
(
/.atom\z/
,
''
)
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
)
...
...
@@ -10,4 +13,12 @@ class NamespaceUrlConstrainer
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
spec/lib/constraints/namespace_url_constrainer_spec.rb
View file @
672704f6
...
...
@@ -17,6 +17,16 @@ describe NamespaceUrlConstrainer, lib: true do
it
{
expect
(
subject
.
matches?
(
request
'/g/gitlab'
)).
to
be_falsey
}
it
{
expect
(
subject
.
matches?
(
request
'/.gitlab'
)).
to
be_falsey
}
end
context
'relative url'
do
before
do
allow
(
Gitlab
::
Application
.
config
).
to
receive
(
:relative_url_root
)
{
'/gitlab'
}
end
it
{
expect
(
subject
.
matches?
(
request
'/gitlab/gitlab'
)).
to
be_truthy
}
it
{
expect
(
subject
.
matches?
(
request
'/gitlab/gitlab-ce'
)).
to
be_falsey
}
it
{
expect
(
subject
.
matches?
(
request
'/gitlab/'
)).
to
be_falsey
}
end
end
def
request
(
path
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment