FIX: uploading an image as a site setting

When uploading an image as a site setting, we need to return the "raw" URL, otherwise
when saving the site setting, the upload won't be looked up properly.

Follow-up-to: f11363d446
This commit is contained in:
Régis Hanol 2020-07-03 13:23:10 +02:00
parent a9c703c230
commit f43c0a5d85
3 changed files with 10 additions and 4 deletions

View File

@ -16,7 +16,6 @@ class UploadSerializer < ApplicationSerializer
:human_filesize :human_filesize
def url def url
return Discourse.store.cdn_url(object.url) if !object.secure || !SiteSetting.secure_media? object.for_site_setting ? object.url : UrlHelper.cook_url(object.url, secure: SiteSetting.secure_media? && object.secure)
UrlHelper.cook_url(object.url, secure: object.secure)
end end
end end

View File

@ -42,6 +42,13 @@ describe UploadsController do
expect(Jobs::CreateAvatarThumbnails.jobs.size).to eq(1) expect(Jobs::CreateAvatarThumbnails.jobs.size).to eq(1)
end end
it 'returns "raw" url for site settings' do
set_cdn_url "https://awesome.com"
post "/uploads.json", params: { file: logo, type: "site_setting", for_site_setting: "true" }
expect(response.status).to eq 200
expect(response.parsed_body["url"]).to start_with("/uploads/default/")
end
it 'returns cdn url' do it 'returns cdn url' do
set_cdn_url "https://awesome.com" set_cdn_url "https://awesome.com"
post "/uploads.json", params: { file: logo, type: "composer" } post "/uploads.json", params: { file: logo, type: "composer" }

View File

@ -22,8 +22,8 @@ RSpec.describe UploadSerializer do
context "when secure media is disabled" do context "when secure media is disabled" do
it "just returns the normal URL, otherwise S3 errors are encountered" do it "just returns the normal URL, otherwise S3 errors are encountered" do
json_data = JSON.load(subject.to_json) UrlHelper.expects(:cook_url).with(upload.url, secure: false)
expect(json_data['url']).to eq(upload.url) subject.to_json
end end
end end