Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: private message email without in reply to section #85

Merged
merged 1 commit into from Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/mailers/user_notifications_extensions.rb
Expand Up @@ -8,4 +8,15 @@ def notification_email(user, opts)
end
super
end

module ClassMethods
def get_context_posts(post, topic_user, user)
return [] if post.is_encrypted?
super
end
end

def self.prepended(mod)
mod.singleton_class.prepend(ClassMethods)
end
end
9 changes: 9 additions & 0 deletions lib/user_notification_renderer_extensions.rb
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module UserNotificationRendererExtensions
def render(*args)
post = args[0]&.dig(:locals, :post)
args[0][:locals][:in_reply_to_post] = nil if post&.is_encrypted?
super(*args)
end
end
2 changes: 2 additions & 0 deletions plugin.rb
Expand Up @@ -40,6 +40,7 @@ module ::DiscourseEncrypt
load File.expand_path('../lib/topics_controller_extensions.rb', __FILE__)
load File.expand_path('../lib/upload_validator_extensions.rb', __FILE__)
load File.expand_path('../lib/user_extensions.rb', __FILE__)
load File.expand_path('../lib/user_notification_renderer_extensions.rb', __FILE__)

class DiscourseEncrypt::Engine < Rails::Engine
engine_name DiscourseEncrypt::PLUGIN_NAME
Expand Down Expand Up @@ -76,6 +77,7 @@ class DiscourseEncrypt::Engine < Rails::Engine
UserNotifications.class_eval { prepend UserNotificationsExtensions }

SiteSetting.singleton_class.prepend SiteSettingExtensions
UserNotificationRenderer.singleton_class.prepend UserNotificationRendererExtensions
end

# Send plugin-specific topic data to client via serializers.
Expand Down
33 changes: 27 additions & 6 deletions spec/lib/email_sender_spec.rb
Expand Up @@ -19,6 +19,13 @@
.create_for(Discourse.system_user.id)
end

fab!(:user) { Fabricate(:user) }

before do
user.user_option.update!(email_in_reply_to: true,
email_previous_replies: UserOption.previous_replies_type[:always])
end

context "encrypted" do
fab!(:encrypted_topic) { Fabricate(:encrypt_topic) }
fab!(:encrypted_post) { Fabricate(:encrypt_post, topic: encrypted_topic) }
Expand All @@ -28,14 +35,18 @@
Hello world!
#{UploadMarkdown.new(small_pdf).attachment_markdown}
RAW
reply = Fabricate(:encrypt_post, raw: raw, topic: encrypted_post.topic, user: Fabricate(:user))
reply = Fabricate(:encrypt_post,
raw: raw,
topic: encrypted_post.topic,
user: Fabricate(:user),
reply_to_post_number: encrypted_post.post_number)
reply.link_post_uploads
reply
end
fab!(:notification) { Fabricate(:posted_notification, user: encrypted_post.user, post: encrypted_reply) }
let(:message) do
UserNotifications.user_posted(
encrypted_post.user,
UserNotifications.user_replied(
user,
post: encrypted_reply,
notification_type: notification.notification_type,
notification_data_hash: notification.data_hash
Expand All @@ -50,6 +61,9 @@
expect(message.reply_to).to eq(["noreply@test.localhost"])
expect(message.body.raw_source).not_to match("or reply to this email to respond")
expect(message.subject).to match("[Discourse] [PM] A secret message ##{encrypted_topic.id}")
renderer = Email::Renderer.new(message, {})
expect(renderer.html).not_to match("In Reply To")
expect(renderer.html).not_to match("Previous Replies")
end
end

Expand All @@ -60,14 +74,18 @@
Hello world!
#{UploadMarkdown.new(small_pdf).attachment_markdown}
RAW
reply = Fabricate(:post, raw: raw, topic: post.topic, user: Fabricate(:user))
reply = Fabricate(:post,
raw: raw,
topic: post.topic,
user: Fabricate(:user),
reply_to_post_number: post.post_number)
reply.link_post_uploads
reply
end
fab!(:notification) { Fabricate(:posted_notification, user: post.user, post: reply) }
let(:message) do
UserNotifications.user_posted(
post.user,
UserNotifications.user_replied(
user,
post: reply,
notification_type: notification.notification_type,
notification_data_hash: notification.data_hash
Expand All @@ -82,6 +100,9 @@
expect(message.reply_to).to eq(["test+%{reply_key}@example.com"])
expect(message.body.raw_source).to match("or reply to this email to respond")
expect(message.subject).to match("[Discourse] #{post.topic.title}")
renderer = Email::Renderer.new(message, {})
expect(renderer.html).to match("In Reply To")
expect(renderer.html).to match("Previous Replies")
end
end
end