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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
f05469f9
Commit
f05469f9
authored
May 04, 2017
by
Michael Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve discussions
parent
9e48f02e
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
31 additions
and
25 deletions
+31
-25
app/controllers/concerns/routable_actions.rb
app/controllers/concerns/routable_actions.rb
+9
-7
app/controllers/groups/application_controller.rb
app/controllers/groups/application_controller.rb
+1
-5
app/controllers/projects/application_controller.rb
app/controllers/projects/application_controller.rb
+6
-13
app/models/user.rb
app/models/user.rb
+4
-0
changelogs/unreleased/17361-redirect-renamed-paths.yml
changelogs/unreleased/17361-redirect-renamed-paths.yml
+4
-0
spec/controllers/groups_controller_spec.rb
spec/controllers/groups_controller_spec.rb
+2
-0
spec/controllers/projects_controller_spec.rb
spec/controllers/projects_controller_spec.rb
+1
-0
spec/controllers/users_controller_spec.rb
spec/controllers/users_controller_spec.rb
+4
-0
No files found.
app/controllers/concerns/routable_actions.rb
View file @
f05469f9
module
RoutableActions
extend
ActiveSupport
::
Concern
def
find_routable!
(
routable_klass
,
requested_full_path
,
extra_authorization_
method
:
nil
)
def
find_routable!
(
routable_klass
,
requested_full_path
,
extra_authorization_
proc
:
nil
)
routable
=
routable_klass
.
find_by_full_path
(
requested_full_path
,
follow_redirects:
request
.
get?
)
if
authorized?
(
routable_klass
,
routable
,
extra_authorization_method
)
if
routable_authorized?
(
routable_klass
,
routable
,
extra_authorization_proc
)
ensure_canonical_path
(
routable
,
requested_full_path
)
routable
else
...
...
@@ -13,12 +13,12 @@ module RoutableActions
end
end
def
authorized?
(
routable_klass
,
routable
,
extra_authorization_method
)
def
routable_authorized?
(
routable_klass
,
routable
,
extra_authorization_proc
)
action
=
:"read_
#{
routable_klass
.
to_s
.
underscore
}
"
return
false
unless
can?
(
current_user
,
action
,
routable
)
if
extra_authorization_
method
send
(
extra_authorization_method
,
routable
)
if
extra_authorization_
proc
extra_authorization_proc
.
call
(
routable
)
else
true
end
...
...
@@ -27,9 +27,11 @@ module RoutableActions
def
ensure_canonical_path
(
routable
,
requested_path
)
return
unless
request
.
get?
canonical_path
=
routable
.
try
(
:full_path
)
||
routable
.
namespace
.
full_path
canonical_path
=
routable
.
full_path
if
canonical_path
!=
requested_path
flash
[
:notice
]
=
'This project has moved to this location. Please update your links and bookmarks.'
if
canonical_path
.
casecmp
(
requested_path
)
!=
0
flash
[
:notice
]
=
"Project '
#{
requested_path
}
' was moved to '
#{
canonical_path
}
'. Please update any links and bookmarks that may still have the old path."
end
redirect_to
request
.
original_url
.
sub
(
requested_path
,
canonical_path
)
end
end
...
...
app/controllers/groups/application_controller.rb
View file @
f05469f9
...
...
@@ -9,11 +9,7 @@ class Groups::ApplicationController < ApplicationController
private
def
group
@group
||=
find_routable!
(
Group
,
requested_full_path
)
end
def
requested_full_path
params
[
:group_id
]
||
params
[
:id
]
@group
||=
find_routable!
(
Group
,
params
[
:group_id
]
||
params
[
:id
])
end
def
group_projects
...
...
app/controllers/projects/application_controller.rb
View file @
f05469f9
...
...
@@ -17,24 +17,17 @@ class Projects::ApplicationController < ApplicationController
# to
# localhost/group/project
#
if
params
[
:format
]
==
'git'
redirect_to
request
.
original_url
.
gsub
(
/\.git\/?\Z/
,
''
)
return
end
redirect_to
url_for
(
params
.
merge
(
format:
nil
))
if
params
[
:format
]
==
'git'
end
def
project
@project
||=
find_routable!
(
Project
,
requested_full_path
,
extra_authorization_method: :project_not_being_deleted?
)
end
def
requested_full_path
namespace
=
params
[
:namespace_id
]
id
=
params
[
:project_id
]
||
params
[
:id
]
"
#{
namespace
}
/
#{
id
}
"
@project
||=
find_routable!
(
Project
,
File
.
join
(
params
[
:namespace_id
],
params
[
:project_id
]
||
params
[
:id
]),
extra_authorization_proc:
project_not_being_deleted?
)
end
def
project_not_being_deleted?
(
project
)
!
project
.
pending_delete?
def
project_not_being_deleted?
->
(
project
)
{
!
project
.
pending_delete?
}
end
def
repository
...
...
app/models/user.rb
View file @
f05469f9
...
...
@@ -360,6 +360,10 @@ class User < ActiveRecord::Base
end
end
def
full_path
username
end
def
self
.
internal_attributes
[
:ghost
]
end
...
...
changelogs/unreleased/17361-redirect-renamed-paths.yml
0 → 100644
View file @
f05469f9
---
title
:
Redirect old links after renaming a user/group/project.
merge_request
:
10370
author
:
spec/controllers/groups_controller_spec.rb
View file @
f05469f9
...
...
@@ -55,6 +55,7 @@ describe GroupsController do
get
:issues
,
id:
group
.
to_param
.
upcase
expect
(
response
).
to
redirect_to
(
issues_group_path
(
group
.
to_param
))
expect
(
controller
).
not_to
set_flash
[
:notice
]
end
end
...
...
@@ -99,6 +100,7 @@ describe GroupsController do
get
:merge_requests
,
id:
group
.
to_param
.
upcase
expect
(
response
).
to
redirect_to
(
merge_requests_group_path
(
group
.
to_param
))
expect
(
controller
).
not_to
set_flash
[
:notice
]
end
end
...
...
spec/controllers/projects_controller_spec.rb
View file @
f05469f9
...
...
@@ -185,6 +185,7 @@ describe ProjectsController do
expect
(
assigns
(
:project
)).
to
eq
(
public_project
)
expect
(
response
).
to
redirect_to
(
"/
#{
public_project
.
full_path
}
"
)
expect
(
controller
).
not_to
set_flash
[
:notice
]
end
end
end
...
...
spec/controllers/users_controller_spec.rb
View file @
f05469f9
...
...
@@ -71,6 +71,7 @@ describe UsersController do
get
:show
,
username:
user
.
username
.
downcase
expect
(
response
).
to
redirect_to
(
user
)
expect
(
controller
).
not_to
set_flash
[
:notice
]
end
end
end
...
...
@@ -149,6 +150,7 @@ describe UsersController do
get
:calendar
,
username:
user
.
username
.
downcase
expect
(
response
).
to
redirect_to
(
user_calendar_path
(
user
))
expect
(
controller
).
not_to
set_flash
[
:notice
]
end
end
end
...
...
@@ -202,6 +204,7 @@ describe UsersController do
get
:calendar_activities
,
username:
user
.
username
.
downcase
expect
(
response
).
to
redirect_to
(
user_calendar_activities_path
(
user
))
expect
(
controller
).
not_to
set_flash
[
:notice
]
end
end
end
...
...
@@ -255,6 +258,7 @@ describe UsersController do
get
:snippets
,
username:
user
.
username
.
downcase
expect
(
response
).
to
redirect_to
(
user_snippets_path
(
user
))
expect
(
controller
).
not_to
set_flash
[
:notice
]
end
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