Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
32b1b5420579
Commit
32b1b542
authored
Oct 20, 2015
by
Douwe Maan
Browse files
Prefer project with exact path to differently cased one when both exist.
parent
8c6a05d7701e
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/controllers/application_controller.rb
View file @
32b1b542
...
...
@@ -118,8 +118,8 @@
end
project_path
=
"
#{
namespace
}
/
#{
id
}
"
@project
=
Project
.
find_with_namespace
(
project_path
)
@project
=
Project
.
find_with_namespace
(
project_path
)
||
Project
.
find_with_namespace
(
project_path
,
case_sensitive:
false
)
if
@project
and
can?
(
current_user
,
:read_project
,
@project
)
if
@project
.
path_with_namespace
!=
project_path
...
...
app/models/project.rb
View file @
32b1b542
...
...
@@ -235,7 +235,7 @@
where
(
'projects.archived = ?'
,
false
).
where
(
'LOWER(projects.name) LIKE :query'
,
query:
"%
#{
query
.
downcase
}
%"
)
end
def
find_with_namespace
(
id
)
def
find_with_namespace
(
id
,
case_sensitive:
true
)
namespace_path
,
project_path
=
id
.
split
(
'/'
)
return
nil
if
!
namespace_path
||
!
project_path
...
...
@@ -243,5 +243,5 @@
# Use of unscoped ensures we're not secretly adding any ORDER BYs, which
# have a negative impact on performance (and aren't needed for this
# query).
unscoped
.
projects
=
unscoped
.
joins
(
:namespace
).
...
...
@@ -247,7 +247,14 @@
joins
(
:namespace
).
iwhere
(
'namespaces.path'
=>
namespace_path
).
iwhere
(
'projects.path'
=>
project_path
).
take
iwhere
(
'namespaces.path'
=>
namespace_path
)
projects
=
if
case_sensitive
projects
.
where
(
'projects.path'
=>
project_path
)
else
projects
.
iwhere
(
'projects.path'
=>
project_path
)
end
projects
.
take
end
def
visibility_levels
...
...
spec/controllers/projects_controller_spec.rb
View file @
32b1b542
...
...
@@ -51,6 +51,7 @@
end
context
"when requested with case sensitive namespace and project path"
do
it
"redirects to the normalized path for case mismatch"
do
get
:show
,
namespace_id:
public_project
.
namespace
.
path
,
id:
public_project
.
path
.
upcase
context
"when there is a match with the same casing"
do
it
"loads the project"
do
get
:show
,
namespace_id:
public_project
.
namespace
.
path
,
id:
public_project
.
path
...
...
@@ -56,4 +57,6 @@
expect
(
response
).
to
redirect_to
(
"/
#{
public_project
.
path_with_namespace
}
"
)
expect
(
assigns
(
:project
)).
to
eq
(
public_project
)
expect
(
response
.
status
).
to
eq
(
200
)
end
end
...
...
@@ -58,5 +61,12 @@
end
it
"loads the page if normalized path matches request path"
do
get
:show
,
namespace_id:
public_project
.
namespace
.
path
,
id:
public_project
.
path
context
"when there is a match with different casing"
do
it
"redirects to the normalized path"
do
get
:show
,
namespace_id:
public_project
.
namespace
.
path
,
id:
public_project
.
path
.
upcase
expect
(
assigns
(
:project
)).
to
eq
(
public_project
)
expect
(
response
).
to
redirect_to
(
"/
#{
public_project
.
path_with_namespace
}
"
)
end
context
"when there is also a match with the same casing"
do
...
...
@@ -62,5 +72,13 @@
expect
(
response
.
status
).
to
eq
(
200
)
let!
(
:other_project
)
{
create
(
:project
,
:public
,
namespace:
public_project
.
namespace
,
path:
public_project
.
path
.
upcase
)
}
it
"loads the exactly matched project"
do
get
:show
,
namespace_id:
public_project
.
namespace
.
path
,
id:
public_project
.
path
.
upcase
expect
(
assigns
(
:project
)).
to
eq
(
other_project
)
expect
(
response
.
status
).
to
eq
(
200
)
end
end
end
end
end
...
...
Write
Preview
Supports
Markdown
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