Commit 8a8dccc8 authored by Stan Hu's avatar Stan Hu

Deprecate legacy /uploads route

The route `/uploads/:namespace/:project/:secret/:filename` has been
around for a long time, but it duplicates the
`/:namespace/:project/uploads/:secret/:filename` route. We'll redirect
the former to the second, canonical version in preparation for removing
this route entirely later.
parent 6775f193
......@@ -31,7 +31,8 @@ class Projects::UploadsController < Projects::ApplicationController
end
# Overrides ApplicationController#build_canonical_path since there are
# multiple routes that match project uploads
# multiple routes that match project uploads:
# https://gitlab.com/gitlab-org/gitlab/issues/196396
def build_canonical_path(project)
return super unless action_name == 'show'
return super unless params[:secret] && params[:filename]
......
......@@ -21,9 +21,10 @@ scope path: :uploads do
as: 'appearance_upload'
# Project markdown uploads
# Consider deprecating this in GitLab 13.x because this is redundant to show_namespace_project_uploads
# DEPRECATED: Remove this in GitLab 13.0 because this is redundant to show_namespace_project_uploads
# https://gitlab.com/gitlab-org/gitlab/issues/196396
get ":namespace_id/:project_id/:secret/:filename",
to: "projects/uploads#show",
to: redirect("%{namespace_id}/%{project_id}/uploads/%{secret}/%{filename}"),
constraints: { namespace_id: /[a-zA-Z.0-9_\-]+/, project_id: /[a-zA-Z.0-9_\-]+/, filename: %r{[^/]+} }, format: false, defaults: { format: nil }
# create uploads for models, snippets (notes) available for now
......
......@@ -28,4 +28,12 @@ describe 'Uploads', 'routing' do
expect(post("/uploads/#{model}?id=1")).not_to be_routable
end
end
describe 'legacy paths' do
include RSpec::Rails::RequestExampleGroup
it 'redirects project uploads to canonical path under project namespace' do
expect(get('/uploads/namespace/project/12345/test.png')).to redirect_to('/namespace/project/uploads/12345/test.png')
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