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
3549e457
Commit
3549e457
authored
Mar 07, 2018
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Constraints module to comply with Naming/FileName cop
parent
cc96d697
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
34 additions
and
34 deletions
+34
-34
config/routes/git_http.rb
config/routes/git_http.rb
+1
-1
config/routes/group.rb
config/routes/group.rb
+1
-3
config/routes/project.rb
config/routes/project.rb
+1
-3
config/routes/user.rb
config/routes/user.rb
+1
-3
lib/constraints/group_url_constrainer.rb
lib/constraints/group_url_constrainer.rb
+7
-5
lib/constraints/project_url_constrainer.rb
lib/constraints/project_url_constrainer.rb
+11
-9
lib/constraints/user_url_constrainer.rb
lib/constraints/user_url_constrainer.rb
+7
-5
spec/lib/constraints/group_url_constrainer_spec.rb
spec/lib/constraints/group_url_constrainer_spec.rb
+1
-1
spec/lib/constraints/project_url_constrainer_spec.rb
spec/lib/constraints/project_url_constrainer_spec.rb
+1
-1
spec/lib/constraints/user_url_constrainer_spec.rb
spec/lib/constraints/user_url_constrainer_spec.rb
+1
-1
spec/routing/routing_spec.rb
spec/routing/routing_spec.rb
+2
-2
No files found.
config/routes/git_http.rb
View file @
3549e457
...
@@ -40,7 +40,7 @@ scope(path: '*namespace_id/:project_id',
...
@@ -40,7 +40,7 @@ scope(path: '*namespace_id/:project_id',
# /info/refs?service=git-receive-pack, but nothing else.
# /info/refs?service=git-receive-pack, but nothing else.
#
#
git_http_handshake
=
lambda
do
|
request
|
git_http_handshake
=
lambda
do
|
request
|
ProjectUrlConstrainer
.
new
.
matches?
(
request
)
&&
::
Constraints
::
ProjectUrlConstrainer
.
new
.
matches?
(
request
)
&&
(
request
.
query_string
.
blank?
||
(
request
.
query_string
.
blank?
||
request
.
query_string
.
match
(
/\Aservice=git-(upload|receive)-pack\z/
))
request
.
query_string
.
match
(
/\Aservice=git-(upload|receive)-pack\z/
))
end
end
...
...
config/routes/group.rb
View file @
3549e457
require
'constraints/group_url_constrainer'
resources
:groups
,
only:
[
:index
,
:new
,
:create
]
do
resources
:groups
,
only:
[
:index
,
:new
,
:create
]
do
post
:preview_markdown
post
:preview_markdown
end
end
constraints
(
GroupUrlConstrainer
.
new
)
do
constraints
(
::
Constraints
::
GroupUrlConstrainer
.
new
)
do
scope
(
path:
'groups/*id'
,
scope
(
path:
'groups/*id'
,
controller: :groups
,
controller: :groups
,
constraints:
{
id:
Gitlab
::
PathRegex
.
full_namespace_route_regex
,
format:
/(html|json|atom)/
})
do
constraints:
{
id:
Gitlab
::
PathRegex
.
full_namespace_route_regex
,
format:
/(html|json|atom)/
})
do
...
...
config/routes/project.rb
View file @
3549e457
require
'constraints/project_url_constrainer'
resources
:projects
,
only:
[
:index
,
:new
,
:create
]
resources
:projects
,
only:
[
:index
,
:new
,
:create
]
draw
:git_http
draw
:git_http
constraints
(
ProjectUrlConstrainer
.
new
)
do
constraints
(
::
Constraints
::
ProjectUrlConstrainer
.
new
)
do
# If the route has a wildcard segment, the segment has a regex constraint,
# If the route has a wildcard segment, the segment has a regex constraint,
# the segment is potentially followed by _another_ wildcard segment, and
# the segment is potentially followed by _another_ wildcard segment, and
# the `format` option is not set to false, we need to specify that
# the `format` option is not set to false, we need to specify that
...
...
config/routes/user.rb
View file @
3549e457
require
'constraints/user_url_constrainer'
## EE-specific
## EE-specific
get
'unsubscribes/:email'
,
to:
'unsubscribes#show'
,
as: :unsubscribe
get
'unsubscribes/:email'
,
to:
'unsubscribes#show'
,
as: :unsubscribe
post
'unsubscribes/:email'
,
to:
'unsubscribes#create'
post
'unsubscribes/:email'
,
to:
'unsubscribes#create'
...
@@ -45,7 +43,7 @@ scope(constraints: { username: Gitlab::PathRegex.root_namespace_route_regex }) d
...
@@ -45,7 +43,7 @@ scope(constraints: { username: Gitlab::PathRegex.root_namespace_route_regex }) d
get
'/u/:username/contributed'
,
to:
redirect
(
'users/%{username}/contributed'
)
get
'/u/:username/contributed'
,
to:
redirect
(
'users/%{username}/contributed'
)
end
end
constraints
(
UserUrlConstrainer
.
new
)
do
constraints
(
::
Constraints
::
UserUrlConstrainer
.
new
)
do
# Get all keys of user
# Get all keys of user
get
':username.keys'
=>
'profiles/keys#get_keys'
,
constraints:
{
username:
Gitlab
::
PathRegex
.
root_namespace_route_regex
}
get
':username.keys'
=>
'profiles/keys#get_keys'
,
constraints:
{
username:
Gitlab
::
PathRegex
.
root_namespace_route_regex
}
...
...
lib/constraints/group_url_constrainer.rb
View file @
3549e457
class
GroupUrlConstrainer
module
Constraints
def
matches?
(
request
)
class
GroupUrlConstrainer
full_path
=
request
.
params
[
:group_id
]
||
request
.
params
[
:id
]
def
matches?
(
request
)
full_path
=
request
.
params
[
:group_id
]
||
request
.
params
[
:id
]
return
false
unless
NamespacePathValidator
.
valid_path?
(
full_path
)
return
false
unless
NamespacePathValidator
.
valid_path?
(
full_path
)
Group
.
find_by_full_path
(
full_path
,
follow_redirects:
request
.
get?
).
present?
Group
.
find_by_full_path
(
full_path
,
follow_redirects:
request
.
get?
).
present?
end
end
end
end
end
lib/constraints/project_url_constrainer.rb
View file @
3549e457
class
ProjectUrlConstrainer
module
Constraints
def
matches?
(
request
)
class
ProjectUrlConstrainer
namespace_path
=
request
.
params
[
:namespace_id
]
def
matches?
(
request
)
project_path
=
request
.
params
[
:project_id
]
||
request
.
params
[
:id
]
namespace_path
=
request
.
params
[
:namespace_id
]
full_path
=
[
namespace_path
,
project_path
].
join
(
'/'
)
project_path
=
request
.
params
[
:project_id
]
||
request
.
params
[
:id
]
full_path
=
[
namespace_path
,
project_path
].
join
(
'/'
)
return
false
unless
ProjectPathValidator
.
valid_path?
(
full_path
)
return
false
unless
ProjectPathValidator
.
valid_path?
(
full_path
)
# We intentionally allow SELECT(*) here so result of this query can be used
# We intentionally allow SELECT(*) here so result of this query can be used
# as cache for further Project.find_by_full_path calls within request
# as cache for further Project.find_by_full_path calls within request
Project
.
find_by_full_path
(
full_path
,
follow_redirects:
request
.
get?
).
present?
Project
.
find_by_full_path
(
full_path
,
follow_redirects:
request
.
get?
).
present?
end
end
end
end
end
lib/constraints/user_url_constrainer.rb
View file @
3549e457
class
UserUrlConstrainer
module
Constraints
def
matches?
(
request
)
class
UserUrlConstrainer
full_path
=
request
.
params
[
:username
]
def
matches?
(
request
)
full_path
=
request
.
params
[
:username
]
return
false
unless
NamespacePathValidator
.
valid_path?
(
full_path
)
return
false
unless
NamespacePathValidator
.
valid_path?
(
full_path
)
User
.
find_by_full_path
(
full_path
,
follow_redirects:
request
.
get?
).
present?
User
.
find_by_full_path
(
full_path
,
follow_redirects:
request
.
get?
).
present?
end
end
end
end
end
spec/lib/constraints/group_url_constrainer_spec.rb
View file @
3549e457
require
'spec_helper'
require
'spec_helper'
describe
GroupUrlConstrainer
do
describe
Constraints
::
GroupUrlConstrainer
do
let!
(
:group
)
{
create
(
:group
,
path:
'gitlab'
)
}
let!
(
:group
)
{
create
(
:group
,
path:
'gitlab'
)
}
describe
'#matches?'
do
describe
'#matches?'
do
...
...
spec/lib/constraints/project_url_constrainer_spec.rb
View file @
3549e457
require
'spec_helper'
require
'spec_helper'
describe
ProjectUrlConstrainer
do
describe
Constraints
::
ProjectUrlConstrainer
do
let!
(
:project
)
{
create
(
:project
)
}
let!
(
:project
)
{
create
(
:project
)
}
let!
(
:namespace
)
{
project
.
namespace
}
let!
(
:namespace
)
{
project
.
namespace
}
...
...
spec/lib/constraints/user_url_constrainer_spec.rb
View file @
3549e457
require
'spec_helper'
require
'spec_helper'
describe
UserUrlConstrainer
do
describe
Constraints
::
UserUrlConstrainer
do
let!
(
:user
)
{
create
(
:user
,
username:
'dz'
)
}
let!
(
:user
)
{
create
(
:user
,
username:
'dz'
)
}
describe
'#matches?'
do
describe
'#matches?'
do
...
...
spec/routing/routing_spec.rb
View file @
3549e457
...
@@ -9,7 +9,7 @@ require 'spec_helper'
...
@@ -9,7 +9,7 @@ require 'spec_helper'
# user_calendar_activities GET /u/:username/calendar_activities(.:format)
# user_calendar_activities GET /u/:username/calendar_activities(.:format)
describe
UsersController
,
"routing"
do
describe
UsersController
,
"routing"
do
it
"to #show"
do
it
"to #show"
do
allow_any_instance_of
(
UserUrlConstrainer
).
to
receive
(
:matches?
).
and_return
(
true
)
allow_any_instance_of
(
::
Constraints
::
UserUrlConstrainer
).
to
receive
(
:matches?
).
and_return
(
true
)
expect
(
get
(
"/User"
)).
to
route_to
(
'users#show'
,
username:
'User'
)
expect
(
get
(
"/User"
)).
to
route_to
(
'users#show'
,
username:
'User'
)
end
end
...
@@ -210,7 +210,7 @@ describe Profiles::KeysController, "routing" do
...
@@ -210,7 +210,7 @@ describe Profiles::KeysController, "routing" do
# get all the ssh-keys of a user
# get all the ssh-keys of a user
it
"to #get_keys"
do
it
"to #get_keys"
do
allow_any_instance_of
(
UserUrlConstrainer
).
to
receive
(
:matches?
).
and_return
(
true
)
allow_any_instance_of
(
::
Constraints
::
UserUrlConstrainer
).
to
receive
(
:matches?
).
and_return
(
true
)
expect
(
get
(
"/foo.keys"
)).
to
route_to
(
'profiles/keys#get_keys'
,
username:
'foo'
)
expect
(
get
(
"/foo.keys"
)).
to
route_to
(
'profiles/keys#get_keys'
,
username:
'foo'
)
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