FIX: Replying to deleted post via email should create new reply to topic

This commit is contained in:
Gerhard Schlager 2018-09-03 23:06:25 +02:00
parent fe6c3b7d2e
commit eeedc3901e
2 changed files with 13 additions and 4 deletions

View File

@ -596,12 +596,14 @@ module Email
raise 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?)
end
end
@ -834,13 +836,14 @@ module Email
def 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)
else
raise 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_number
options[:is_group_message] = options[:topic].private_message? && options[:topic].allowed_groups.exists?
create_post_with_attachments(options)
end

View File

@ -351,6 +351,12 @@ describe Email::Receiver do
expect { 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' do
let(:last_email) { ActionMailer::Base.deliveries.last }