diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-05-19 22:28:38 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-05-19 22:28:38 +0300 |
commit | 5d5e695473bf65d89f12f330374f7bb36548e876 (patch) | |
tree | 94a80beb5f1b89debab74aff79d9e0bf0b93ef40 /app/controllers | |
parent | bdf62a19d2cdbdfe554eb73500fd5fe4744161b1 (diff) | |
parent | 49697bc8df613dfe8e88f5f7cd8eae57e26c786f (diff) |
Merge branch 'fix-issue-32506' into 'master'
Fix redirects modifying the host
Closes #32506
See merge request !11498
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/concerns/routable_actions.rb | 10 | ||||
-rw-r--r-- | app/controllers/groups/application_controller.rb | 6 | ||||
-rw-r--r-- | app/controllers/groups_controller.rb | 8 | ||||
-rw-r--r-- | app/controllers/projects/application_controller.rb | 7 | ||||
-rw-r--r-- | app/controllers/projects_controller.rb | 7 | ||||
-rw-r--r-- | app/controllers/users_controller.rb | 4 |
6 files changed, 37 insertions, 5 deletions
diff --git a/app/controllers/concerns/routable_actions.rb b/app/controllers/concerns/routable_actions.rb index afd110adcad..4199da9cdf5 100644 --- a/app/controllers/concerns/routable_actions.rb +++ b/app/controllers/concerns/routable_actions.rb @@ -24,15 +24,15 @@ module RoutableActions end end - def ensure_canonical_path(routable, requested_path) + def ensure_canonical_path(routable, requested_full_path) return unless request.get? canonical_path = routable.full_path - if canonical_path != requested_path - if canonical_path.casecmp(requested_path) != 0 - 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." + if canonical_path != requested_full_path + if canonical_path.casecmp(requested_full_path) != 0 + flash[:notice] = "#{routable.class.to_s.titleize} '#{requested_full_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) + redirect_to build_canonical_path(routable) end end end diff --git a/app/controllers/groups/application_controller.rb b/app/controllers/groups/application_controller.rb index afffb813b44..c0ac47e363d 100644 --- a/app/controllers/groups/application_controller.rb +++ b/app/controllers/groups/application_controller.rb @@ -31,4 +31,10 @@ class Groups::ApplicationController < ApplicationController return render_403 end end + + def build_canonical_path(group) + params[:group_id] = group.to_param + + url_for(params) + end end diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 1515173d0ac..965ced4d372 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -169,4 +169,12 @@ class GroupsController < Groups::ApplicationController @notification_setting = current_user.notification_settings_for(group) end end + + def build_canonical_path(group) + return group_path(group) if action_name == 'show' # root group path + + params[:id] = group.to_param + + url_for(params) + end end diff --git a/app/controllers/projects/application_controller.rb b/app/controllers/projects/application_controller.rb index 12e4a6999ae..cb4bd0ad5f5 100644 --- a/app/controllers/projects/application_controller.rb +++ b/app/controllers/projects/application_controller.rb @@ -29,6 +29,13 @@ class Projects::ApplicationController < ApplicationController @project = find_routable!(Project, path, extra_authorization_proc: auth_proc) end + def build_canonical_path(project) + params[:namespace_id] = project.namespace.to_param + params[:project_id] = project.to_param + + url_for(params) + end + def repository @repository ||= project.repository end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 63d018c8cbf..544715d62ea 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -365,4 +365,11 @@ class ProjectsController < Projects::ApplicationController def project_view_files_allowed? !project.empty_repo? && can?(current_user, :download_code, project) end + + def build_canonical_path(project) + params[:namespace_id] = project.namespace.to_param + params[:id] = project.to_param + + url_for(params) + end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ba22b2f9d29..19fc1e5de49 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -138,4 +138,8 @@ class UsersController < ApplicationController def projects_for_current_user ProjectsFinder.new(current_user: current_user).execute end + + def build_canonical_path(user) + url_for(params.merge(username: user.to_param)) + end end |