FIX: deleting staged user of rejected email shouldn't delete incoming email

This commit is contained in:
Gerhard Schlager 2017-10-31 15:13:23 +01:00
parent 8c27f28dcb
commit 880d154381
2 changed files with 12 additions and 1 deletions

View File

@ -756,7 +756,13 @@ module Email
def delete_staged_users def delete_staged_users
@staged_users.each do |user| @staged_users.each do |user|
UserDestroyer.new(Discourse.system_user).destroy(user, quiet: true) if user.posts.count == 0 if @incoming_email.user.id == user.id
@incoming_email.update_columns(user_id: nil)
end
if user.posts.count == 0
UserDestroyer.new(Discourse.system_user).destroy(user, quiet: true)
end
end end
end end
end end

View File

@ -760,6 +760,11 @@ describe Email::Receiver do
end end
end end
it "does not remove the incoming email record when staged users are deleted" do
expect { process(:bad_destinations) }.to change { IncomingEmail.count }
.and raise_error(Email::Receiver::BadDestinationAddress)
expect(IncomingEmail.last.message_id).to eq("9@foo.bar.mail")
end
end end
end end