mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 00:08:53 +08:00
FIX: Ensure oneboxed secure images which are optimized and also lightboxed optimized images are embedded in email (#11061)
We had an issue where onebox thumbnail was too large and thus was optimized, and we are using the image URLs in post to redact and re-embed, based on the sha1 in the URL. Optimized image URLs have extra stuff on the end like _99x99 so we were not parsing out the sha1 correctly. Another issue I found was for posts that have giant images, the original was being used to embed in the email and thus would basically never get included because it is huge.
For example the URL 787b17ea61
_2_690x335.jpeg was not parsed correctly; we would end up with 787b17ea6140f4f022eb7f1509a692f2873cfe35_2_690x335.jpeg as the sha1 which would not find the image to re-embed that was already attached to the email.
This fix will use the first optimized image of the detected upload when we are redacting and then re-embedding to make sure we are not sending giant things in email. Also, I detect if it is a onebox thumbnail or the site icon and force appropriate sizes and styles.
This commit is contained in:
@ -424,7 +424,7 @@ describe Email::Sender do
|
||||
context "when secure media enabled" do
|
||||
before do
|
||||
setup_s3
|
||||
stub_s3_store
|
||||
store = stub_s3_store
|
||||
|
||||
SiteSetting.secure_media = true
|
||||
SiteSetting.login_required = true
|
||||
@ -436,7 +436,8 @@ describe Email::Sender do
|
||||
FileStore::S3Store.any_instance.expects(:has_been_uploaded?).returns(true).at_least_once
|
||||
CookedPostProcessor.any_instance.stubs(:get_size).returns([244, 66])
|
||||
|
||||
@secure_image = UploadCreator.new(file_from_fixtures("logo.png", "images"), "logo.png")
|
||||
@secure_image_file = file_from_fixtures("logo.png", "images")
|
||||
@secure_image = UploadCreator.new(@secure_image_file, "logo.png")
|
||||
.create_for(Discourse.system_user.id)
|
||||
@secure_image.update_secure_status(secure_override_value: true)
|
||||
@secure_image.update(access_control_post_id: reply.id)
|
||||
@ -470,6 +471,7 @@ describe Email::Sender do
|
||||
expect(message.attachments.length).to eq(4)
|
||||
expect(message.attachments.map(&:filename))
|
||||
.to contain_exactly(*[small_pdf, large_pdf, csv_file, @secure_image].map(&:original_filename))
|
||||
expect(message.attachments["logo.png"].body.raw_source.force_encoding("UTF-8")).to eq(File.read(@secure_image_file))
|
||||
expect(message.html_part.body).to include("cid:")
|
||||
expect(message.html_part.body).to include("embedded-secure-image")
|
||||
expect(message.attachments.length).to eq(4)
|
||||
@ -481,6 +483,25 @@ describe Email::Sender do
|
||||
expect(message.html_part.body).to include("It’s")
|
||||
expect(message.html_part.charset.downcase).to eq("utf-8")
|
||||
end
|
||||
|
||||
context "when the uploaded secure image has an optimized image" do
|
||||
let!(:optimized) { Fabricate(:optimized_image, upload: @secure_image) }
|
||||
let!(:optimized_image_file) { file_from_fixtures("logo-dev.png", "images") }
|
||||
|
||||
it "uses the email styles and the optimized image to inline secure images and attaches the secure image upload to the email" do
|
||||
Discourse.store.store_optimized_image(optimized_image_file, optimized)
|
||||
optimized.update(url: Discourse.store.absolute_base_url + '/' + optimized.url)
|
||||
Discourse.store.cache_file(optimized_image_file, File.basename("#{optimized.sha1}.png"))
|
||||
Email::Sender.new(message, :valid_type).send
|
||||
expect(message.attachments.length).to eq(4)
|
||||
expect(message.attachments.map(&:filename))
|
||||
.to contain_exactly(*[small_pdf, large_pdf, csv_file, @secure_image].map(&:original_filename))
|
||||
expect(message.attachments["logo.png"].body.raw_source.force_encoding("UTF-8")).to eq(File.read(optimized_image_file))
|
||||
expect(message.html_part.body).to include("cid:")
|
||||
expect(message.html_part.body).to include("embedded-secure-image")
|
||||
expect(message.attachments.length).to eq(4)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user