A platform for community discussion. Free, open, simple.
FIX: Replying to deleted post via email should create new reply to topic
Gerhard Schlagereeedc3901e50
diff --git a/lib/email/receiver.rb b/lib/email/receiver.rbindex 898838faad1..3419dbda062 100644--- a/lib/email/receiver.rb+++ b/lib/email/receiver.rb@@ -596,12 +596,14 @@ module Emailraise ReplyUserNotMatchingError, "post_reply_key.user_id => #{post_reply_key.user_id.inspect}, user.id => #{user.id.inspect}"end+ post = Post.with_deleted.find(post_reply_key.post_id)+create_reply(user: user,raw: body,elided: elided,hidden_reason_id: hidden_reason_id,- post: post_reply_key.post,- topic: post_reply_key.post.topic,+ post: post,+ topic: post&.topic,skip_validations: user.staged?)endend@@ -834,13 +836,14 @@ module Emaildef create_reply(options = {})raise TopicNotFoundError if options[:topic].nil? || options[:topic].trashed?+ options[:post] = nil if options[:post]&.trashed?if post_action_type = post_action_for(options[:raw])create_post_action(options[:user], options[:post], post_action_type)elseraise TopicClosedError if options[:topic].closed?- options[:topic_id] = options[:post].try(:topic_id)- options[:reply_to_post_number] = options[:post].try(:post_number)+ options[:topic_id] = options[:topic].id+ options[:reply_to_post_number] = options[:post]&.post_numberoptions[:is_group_message] = options[:topic].private_message? && options[:topic].allowed_groups.exists?create_post_with_attachments(options)enddiff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rbindex 6d92858fd15..f7721a0e906 100644--- a/spec/components/email/receiver_spec.rb+++ b/spec/components/email/receiver_spec.rb@@ -351,6 +351,12 @@ describe Email::Receiver doexpect { process(:staged_reply_restricted) }.to change { topic.posts.count }end+ it "posts a reply to the topic when the post was deleted" do+ post.update_columns(deleted_at: 1.day.ago)+ expect { process(:reply_user_matching) }.to change { topic.posts.count }+ expect(topic.ordered_posts.last.reply_to_post_number).to be_nil+ end+describe 'Unsubscribing via email' dolet(:last_email) { ActionMailer::Base.deliveries.last }