mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Allow email image embed with secure media (#10563)
This PR introduces a few important changes to secure media redaction in emails. First of all, two new site settings have been introduced: * `secure_media_allow_embed_images_in_emails`: If enabled we will embed secure images in emails instead of redacting them. * `secure_media_max_email_embed_image_size_kb`: The cap to the size of the secure image we will embed, defaulting to 1mb, so the email does not become too big. Max is 10mb. Works in tandem with `email_total_attachment_size_limit_kb`. `Email::Sender` will now attach images to the email based on these settings. The sender will also call `inline_secure_images` in `Email::Styles` after secure media is redacted and attachments are added to replace redaction messages with attached images. I went with attachment and `cid` URLs because base64 image support is _still_ flaky in email clients. All redaction of secure media is now handled in `Email::Styles` and calls out to `PrettyText.strip_secure_media` to do the actual stripping and replacing with placeholders. `app/mailers/group_smtp_mailer.rb` and `app/mailers/user_notifications.rb` no longer do any stripping because they are earlier in the pipeline than `Email::Styles`. Finally the redaction notice has been restyled and includes a link to the media that the user can click, which will show it to them if they have the necessary permissions. 
This commit is contained in:
@@ -699,50 +699,6 @@ describe UserNotifications do
|
||||
expect(mail.body.to_s).to match(I18n.t("user_notifications.reached_limit", count: 2))
|
||||
end
|
||||
|
||||
describe "secure media" do
|
||||
let(:video_upload) { Fabricate(:upload, extension: "mov") }
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:post) { Fabricate(:post) }
|
||||
|
||||
before do
|
||||
SiteSetting.s3_upload_bucket = "some-bucket-on-s3"
|
||||
SiteSetting.s3_access_key_id = "s3-access-key-id"
|
||||
SiteSetting.s3_secret_access_key = "s3-secret-access-key"
|
||||
SiteSetting.s3_cdn_url = "https://s3.cdn.com"
|
||||
SiteSetting.enable_s3_uploads = true
|
||||
SiteSetting.secure_media = true
|
||||
SiteSetting.login_required = true
|
||||
|
||||
video_upload.update!(url: "#{SiteSetting.s3_cdn_url}/#{Discourse.store.get_path_for_upload(video_upload)}")
|
||||
user.email_logs.create!(
|
||||
email_type: 'blah',
|
||||
to_address: user.email,
|
||||
user_id: user.id
|
||||
)
|
||||
end
|
||||
|
||||
it "replaces secure audio/video with placeholder" do
|
||||
reply = Fabricate(:post, topic_id: post.topic_id, raw: "Video: #{video_upload.url}")
|
||||
|
||||
notification = Fabricate(
|
||||
:notification,
|
||||
topic_id: post.topic_id,
|
||||
post_number: reply.post_number,
|
||||
user: post.user,
|
||||
data: { original_username: 'bob' }.to_json
|
||||
)
|
||||
|
||||
mail = UserNotifications.user_replied(
|
||||
user,
|
||||
post: reply,
|
||||
notification_type: notification.notification_type,
|
||||
notification_data_hash: notification.data_hash
|
||||
)
|
||||
|
||||
expect(mail.body.to_s).to match(I18n.t("emails.secure_media_placeholder"))
|
||||
end
|
||||
end
|
||||
|
||||
def expects_build_with(condition)
|
||||
UserNotifications.any_instance.expects(:build_email).with(user.email, condition)
|
||||
mailer = UserNotifications.public_send(
|
||||
|
||||
Reference in New Issue
Block a user