FEATURE: Add rake task to disable secure media (#8669)

* Add a rake task to disable secure media. This sets all uploads to `secure: false`, changes the upload ACL to public, and rebakes all the posts using the uploads to make sure they point to the correct URLs. This is in a transaction for each upload with the upload being updated the last step, so if the task fails it can be resumed.
* Also allow viewing media via the secure url if secure media is disabled, redirecting to the normal CDN url, because otherwise media links will be broken while we go and rebake all the posts + update ACLs
This commit is contained in:
Martin Brennan
2020-01-07 12:27:24 +10:00
committed by GitHub
parent fc94b6cb9e
commit abca91cc4d
3 changed files with 70 additions and 3 deletions

View File

@@ -431,6 +431,23 @@ describe UploadsController do
result = JSON.parse(response.body)
expect(result[0]["url"]).to match("secure-media-uploads")
end
context "when secure media is disabled" do
before do
SiteSetting.secure_media = false
end
it "should redirect to the regular show route" do
secure_url = upload.url.sub(SiteSetting.Upload.absolute_base_url, "/secure-media-uploads")
sign_in(user)
stub_request(:head, "https://#{SiteSetting.s3_upload_bucket}.s3.amazonaws.com/")
get secure_url
expect(response.status).to eq(302)
expect(response.redirect_url).to eq(Discourse.store.cdn_url(upload.url))
end
end
end
end