-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle old-style /goverment/uploads routes
This is currently handled by Whitehall but we're trying to move away from Whitehall being a frontend application. The next best place for this bit of code seems to be Government Frontend. https://github.com/alphagov/whitehall/blob/master/test/functional/asset_manager_redirect_controller_test.rb The code itself is used to handle assets which are still being requested on their own URL before we migrated all assets over to Asset Manager.
- Loading branch information
1 parent
8c30acd
commit 2c56aca
Showing
3 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class AssetManagerRedirectController < ApplicationController | ||
def show | ||
asset_url = Plek.new.public_asset_host | ||
if request.host.start_with?("draft-") | ||
asset_url = Plek.new.external_url_for("draft-assets") | ||
end | ||
|
||
redirect_to host: URI.parse(asset_url).host, status: :moved_permanently | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
test/controllers/asset_manager_redirect_controller_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require "test_helper" | ||
|
||
class AssetManagerRedirectControllerTest < ActionController::TestCase | ||
setup do | ||
Plek.any_instance.stubs(:public_asset_host).returns("http://asset-host.com") | ||
Plek.any_instance.stubs(:external_url_for).returns("http://draft-asset-host.com") | ||
end | ||
|
||
test "redirects asset requests made via public host to the public asset host" do | ||
request.host = "some-host.com" | ||
get :show, params: { path: "asset", format: "txt" } | ||
|
||
assert_redirected_to "http://asset-host.com/government/uploads/asset.txt" | ||
end | ||
|
||
test "redirects asset requests made via draft host to the draft asset host" do | ||
request.host = "draft-some-host.com" | ||
get :show, params: { path: "asset", format: "txt" } | ||
|
||
assert_redirected_to "http://draft-asset-host.com/government/uploads/asset.txt" | ||
end | ||
end |