mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 10:57:04 +08:00
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:
parent
a9c703c230
commit
f43c0a5d85
|
@ -16,7 +16,6 @@ class UploadSerializer < ApplicationSerializer
|
|||
:human_filesize
|
||||
|
||||
def url
|
||||
return Discourse.store.cdn_url(object.url) if !object.secure || !SiteSetting.secure_media?
|
||||
UrlHelper.cook_url(object.url, secure: object.secure)
|
||||
object.for_site_setting ? object.url : UrlHelper.cook_url(object.url, secure: SiteSetting.secure_media? && object.secure)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -42,6 +42,13 @@ describe UploadsController do
|
|||
expect(Jobs::CreateAvatarThumbnails.jobs.size).to eq(1)
|
||||
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
|
||||
set_cdn_url "https://awesome.com"
|
||||
post "/uploads.json", params: { file: logo, type: "composer" }
|
||||
|
|
|
@ -22,8 +22,8 @@ RSpec.describe UploadSerializer do
|
|||
|
||||
context "when secure media is disabled" do
|
||||
it "just returns the normal URL, otherwise S3 errors are encountered" do
|
||||
json_data = JSON.load(subject.to_json)
|
||||
expect(json_data['url']).to eq(upload.url)
|
||||
UrlHelper.expects(:cook_url).with(upload.url, secure: false)
|
||||
subject.to_json
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user