BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
82e551bd
Unverified
Commit
82e551bd
authored
Nov 07, 2016
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor routing constraints
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
76ff9fff
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
81 additions
and
74 deletions
+81
-74
constrainer_helper.rb
lib/constraints/constrainer_helper.rb
+15
-0
group_url_constrainer.rb
lib/constraints/group_url_constrainer.rb
+12
-4
namespace_url_constrainer.rb
lib/constraints/namespace_url_constrainer.rb
+0
-24
user_url_constrainer.rb
lib/constraints/user_url_constrainer.rb
+12
-4
constrainer_helper_spec.rb
spec/lib/constraints/constrainer_helper_spec.rb
+20
-0
group_url_constrainer_spec.rb
spec/lib/constraints/group_url_constrainer_spec.rb
+13
-4
namespace_url_constrainer_spec.rb
spec/lib/constraints/namespace_url_constrainer_spec.rb
+0
-35
user_url_constrainer_spec.rb
spec/lib/constraints/user_url_constrainer_spec.rb
+9
-3
No files found.
lib/constraints/constrainer_helper.rb
0 → 100644
View file @
82e551bd
module
ConstrainerHelper
def
extract_resource_path
(
path
)
id
=
path
.
dup
id
.
sub!
(
/\A
#{
relative_url_root
}
/
,
''
)
if
relative_url_root
id
.
sub
(
/\A\/+/
,
''
).
sub
(
/\/+\z/
,
''
).
sub
(
/.atom\z/
,
''
)
end
private
def
relative_url_root
if
defined?
(
Gitlab
::
Application
.
config
.
relative_url_root
)
Gitlab
::
Application
.
config
.
relative_url_root
end
end
end
lib/constraints/group_url_constrainer.rb
View file @
82e551bd
require
'constraints/namespace_url_constrain
er'
require
_relative
'constrainer_help
er'
class
GroupUrlConstrainer
<
NamespaceUrlConstrainer
def
find_resource
(
id
)
Group
.
find_by_path
(
id
)
class
GroupUrlConstrainer
include
ConstrainerHelper
def
matches?
(
request
)
id
=
extract_resource_path
(
request
.
path
)
if
id
=~
Gitlab
::
Regex
.
namespace_regex
!!
Group
.
find_by_path
(
id
)
else
false
end
end
end
lib/constraints/namespace_url_constrainer.rb
deleted
100644 → 0
View file @
76ff9fff
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
lib/constraints/user_url_constrainer.rb
View file @
82e551bd
require
'constraints/namespace_url_constrain
er'
require
_relative
'constrainer_help
er'
class
UserUrlConstrainer
<
NamespaceUrlConstrainer
def
find_resource
(
id
)
User
.
find_by
(
'lower(username) = ?'
,
id
.
downcase
)
class
UserUrlConstrainer
include
ConstrainerHelper
def
matches?
(
request
)
id
=
extract_resource_path
(
request
.
path
)
if
id
=~
Gitlab
::
Regex
.
namespace_regex
!!
User
.
find_by
(
'lower(username) = ?'
,
id
.
downcase
)
else
false
end
end
end
spec/lib/constraints/constrainer_helper_spec.rb
0 → 100644
View file @
82e551bd
require
'spec_helper'
describe
ConstrainerHelper
,
lib:
true
do
include
ConstrainerHelper
describe
'#extract_resource_path'
do
it
{
expect
(
extract_resource_path
(
'/gitlab/'
)).
to
eq
(
'gitlab'
)
}
it
{
expect
(
extract_resource_path
(
'///gitlab//'
)).
to
eq
(
'gitlab'
)
}
it
{
expect
(
extract_resource_path
(
'/gitlab.atom'
)).
to
eq
(
'gitlab'
)
}
context
'relative url'
do
before
do
allow
(
Gitlab
::
Application
.
config
).
to
receive
(
:relative_url_root
)
{
'/gitlab'
}
end
it
{
expect
(
extract_resource_path
(
'/gitlab/foo'
)).
to
eq
(
'foo'
)
}
it
{
expect
(
extract_resource_path
(
'/foo/bar'
)).
to
eq
(
'foo/bar'
)
}
end
end
end
spec/lib/constraints/group_url_constrainer_spec.rb
View file @
82e551bd
require
'spec_helper'
describe
GroupUrlConstrainer
,
lib:
true
do
let!
(
:
username
)
{
create
(
:group
,
path:
'gitlab-org
'
)
}
let!
(
:
group
)
{
create
(
:group
,
path:
'gitlab
'
)
}
describe
'#find_resource'
do
it
{
expect
(
!!
subject
.
find_resource
(
'gitlab-org'
)).
to
be_truthy
}
it
{
expect
(
!!
subject
.
find_resource
(
'gitlab-com'
)).
to
be_falsey
}
describe
'#matches?'
do
context
'root group'
do
it
{
expect
(
subject
.
matches?
(
request
'/gitlab'
)).
to
be_truthy
}
it
{
expect
(
subject
.
matches?
(
request
'/gitlab.atom'
)).
to
be_truthy
}
it
{
expect
(
subject
.
matches?
(
request
'/gitlab/edit'
)).
to
be_falsey
}
it
{
expect
(
subject
.
matches?
(
request
'/gitlab-ce'
)).
to
be_falsey
}
it
{
expect
(
subject
.
matches?
(
request
'/.gitlab'
)).
to
be_falsey
}
end
end
def
request
(
path
)
OpenStruct
.
new
(
path:
path
)
end
end
spec/lib/constraints/namespace_url_constrainer_spec.rb
deleted
100644 → 0
View file @
76ff9fff
require
'spec_helper'
describe
NamespaceUrlConstrainer
,
lib:
true
do
let!
(
:group
)
{
create
(
:group
,
path:
'gitlab'
)
}
describe
'#matches?'
do
context
'existing namespace'
do
it
{
expect
(
subject
.
matches?
(
request
'/gitlab'
)).
to
be_truthy
}
it
{
expect
(
subject
.
matches?
(
request
'/gitlab.atom'
)).
to
be_truthy
}
it
{
expect
(
subject
.
matches?
(
request
'/gitlab/'
)).
to
be_truthy
}
it
{
expect
(
subject
.
matches?
(
request
'//gitlab/'
)).
to
be_truthy
}
end
context
'non-existing namespace'
do
it
{
expect
(
subject
.
matches?
(
request
'/gitlab-ce'
)).
to
be_falsey
}
it
{
expect
(
subject
.
matches?
(
request
'/gitlab.ce'
)).
to
be_falsey
}
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
)
OpenStruct
.
new
(
path:
path
)
end
end
spec/lib/constraints/user_url_constrainer_spec.rb
View file @
82e551bd
...
...
@@ -3,8 +3,14 @@ require 'spec_helper'
describe
UserUrlConstrainer
,
lib:
true
do
let!
(
:username
)
{
create
(
:user
,
username:
'dz'
)
}
describe
'#find_resource'
do
it
{
expect
(
!!
subject
.
find_resource
(
'dz'
)).
to
be_truthy
}
it
{
expect
(
!!
subject
.
find_resource
(
'john'
)).
to
be_falsey
}
describe
'#matches?'
do
it
{
expect
(
subject
.
matches?
(
request
'/dz'
)).
to
be_truthy
}
it
{
expect
(
subject
.
matches?
(
request
'/dz.atom'
)).
to
be_truthy
}
it
{
expect
(
subject
.
matches?
(
request
'/dz/projects'
)).
to
be_falsey
}
it
{
expect
(
subject
.
matches?
(
request
'/gitlab'
)).
to
be_falsey
}
end
def
request
(
path
)
OpenStruct
.
new
(
path:
path
)
end
end
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