Commit ab98f8b5 authored by Michael Kozono's avatar Michael Kozono

Fix redirect message for groups and users

parent e7e13252
...@@ -4,7 +4,7 @@ module RoutableActions ...@@ -4,7 +4,7 @@ module RoutableActions
def find_routable!(routable_klass, requested_full_path, extra_authorization_proc: 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?) routable = routable_klass.find_by_full_path(requested_full_path, follow_redirects: request.get?)
if routable_authorized?(routable_klass, routable, extra_authorization_proc) if routable_authorized?(routable, extra_authorization_proc)
ensure_canonical_path(routable, requested_full_path) ensure_canonical_path(routable, requested_full_path)
routable routable
else else
...@@ -13,8 +13,8 @@ module RoutableActions ...@@ -13,8 +13,8 @@ module RoutableActions
end end
end end
def routable_authorized?(routable_klass, routable, extra_authorization_proc) def routable_authorized?(routable, extra_authorization_proc)
action = :"read_#{routable_klass.to_s.underscore}" action = :"read_#{routable.class.to_s.underscore}"
return false unless can?(current_user, action, routable) return false unless can?(current_user, action, routable)
if extra_authorization_proc if extra_authorization_proc
...@@ -30,7 +30,7 @@ module RoutableActions ...@@ -30,7 +30,7 @@ module RoutableActions
canonical_path = routable.full_path canonical_path = routable.full_path
if canonical_path != requested_path if canonical_path != requested_path
if canonical_path.casecmp(requested_path) != 0 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." flash[:notice] = "#{routable.class.to_s.titleize} '#{requested_path}' was moved to '#{canonical_path}'. Please update any links and bookmarks that may still have the old path."
end end
redirect_to request.original_url.sub(requested_path, canonical_path) redirect_to request.original_url.sub(requested_path, canonical_path)
end end
......
...@@ -101,7 +101,7 @@ describe GroupsController do ...@@ -101,7 +101,7 @@ describe GroupsController do
get :issues, id: redirect_route.path get :issues, id: redirect_route.path
expect(response).to redirect_to(issues_group_path(group.to_param)) expect(response).to redirect_to(issues_group_path(group.to_param))
expect(controller).to set_flash[:notice].to(/moved/) expect(controller).to set_flash[:notice].to(group_moved_message(redirect_route, group))
end end
end end
end end
...@@ -146,7 +146,7 @@ describe GroupsController do ...@@ -146,7 +146,7 @@ describe GroupsController do
get :merge_requests, id: redirect_route.path get :merge_requests, id: redirect_route.path
expect(response).to redirect_to(merge_requests_group_path(group.to_param)) expect(response).to redirect_to(merge_requests_group_path(group.to_param))
expect(controller).to set_flash[:notice].to(/moved/) expect(controller).to set_flash[:notice].to(group_moved_message(redirect_route, group))
end end
end end
end end
...@@ -249,4 +249,8 @@ describe GroupsController do ...@@ -249,4 +249,8 @@ describe GroupsController do
end end
end end
end end
def group_moved_message(redirect_route, group)
"Group '#{redirect_route.path}' was moved to '#{group.full_path}'. Please update any links and bookmarks that may still have the old path."
end
end end
...@@ -227,7 +227,7 @@ describe ProjectsController do ...@@ -227,7 +227,7 @@ describe ProjectsController do
get :show, namespace_id: 'foo', id: 'bar' get :show, namespace_id: 'foo', id: 'bar'
expect(response).to redirect_to(public_project) expect(response).to redirect_to(public_project)
expect(controller).to set_flash[:notice].to(/moved/) expect(controller).to set_flash[:notice].to(project_moved_message(redirect_route, public_project))
end end
end end
end end
...@@ -473,7 +473,7 @@ describe ProjectsController do ...@@ -473,7 +473,7 @@ describe ProjectsController do
get :refs, namespace_id: 'foo', id: 'bar' get :refs, namespace_id: 'foo', id: 'bar'
expect(response).to redirect_to(refs_namespace_project_path(namespace_id: public_project.namespace, id: public_project)) expect(response).to redirect_to(refs_namespace_project_path(namespace_id: public_project.namespace, id: public_project))
expect(controller).to set_flash[:notice].to(/moved/) expect(controller).to set_flash[:notice].to(project_moved_message(redirect_route, public_project))
end end
end end
end end
...@@ -487,4 +487,8 @@ describe ProjectsController do ...@@ -487,4 +487,8 @@ describe ProjectsController do
expect(JSON.parse(response.body).keys).to match_array(%w(body references)) expect(JSON.parse(response.body).keys).to match_array(%w(body references))
end end
end end
def project_moved_message(redirect_route, project)
"Project '#{redirect_route.path}' was moved to '#{project.full_path}'. Please update any links and bookmarks that may still have the old path."
end
end end
...@@ -83,7 +83,7 @@ describe UsersController do ...@@ -83,7 +83,7 @@ describe UsersController do
get :show, username: redirect_route.path get :show, username: redirect_route.path
expect(response).to redirect_to(user) expect(response).to redirect_to(user)
expect(controller).to set_flash[:notice].to(/moved/) expect(controller).to set_flash[:notice].to(user_moved_message(redirect_route, user))
end end
end end
...@@ -162,7 +162,7 @@ describe UsersController do ...@@ -162,7 +162,7 @@ describe UsersController do
get :calendar, username: redirect_route.path get :calendar, username: redirect_route.path
expect(response).to redirect_to(user_calendar_path(user)) expect(response).to redirect_to(user_calendar_path(user))
expect(controller).to set_flash[:notice].to(/moved/) expect(controller).to set_flash[:notice].to(user_moved_message(redirect_route, user))
end end
end end
end end
...@@ -216,7 +216,7 @@ describe UsersController do ...@@ -216,7 +216,7 @@ describe UsersController do
get :calendar_activities, username: redirect_route.path get :calendar_activities, username: redirect_route.path
expect(response).to redirect_to(user_calendar_activities_path(user)) expect(response).to redirect_to(user_calendar_activities_path(user))
expect(controller).to set_flash[:notice].to(/moved/) expect(controller).to set_flash[:notice].to(user_moved_message(redirect_route, user))
end end
end end
end end
...@@ -270,7 +270,7 @@ describe UsersController do ...@@ -270,7 +270,7 @@ describe UsersController do
get :snippets, username: redirect_route.path get :snippets, username: redirect_route.path
expect(response).to redirect_to(user_snippets_path(user)) expect(response).to redirect_to(user_snippets_path(user))
expect(controller).to set_flash[:notice].to(/moved/) expect(controller).to set_flash[:notice].to(user_moved_message(redirect_route, user))
end end
end end
end end
...@@ -320,4 +320,8 @@ describe UsersController do ...@@ -320,4 +320,8 @@ describe UsersController do
end end
end end
end end
def user_moved_message(redirect_route, user)
"User '#{redirect_route.path}' was moved to '#{user.full_path}'. Please update any links and bookmarks that may still have the old path."
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment