mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
FIX: email replies should not be accepted for deleted topics
This commit is contained in:
parent
9445000b58
commit
b37d845dd3
5 changed files with 67 additions and 0 deletions
|
@ -45,6 +45,8 @@ module Jobs
|
|||
message_template = :email_reject_reply_key
|
||||
when Email::Receiver::BadDestinationAddress
|
||||
message_template = :email_reject_destination
|
||||
when Email::Receiver::TopicNotFoundError
|
||||
message_template = :email_reject_topic_not_found
|
||||
when Email::Receiver::TopicClosedError
|
||||
message_template = :email_reject_topic_closed
|
||||
when ActiveRecord::Rollback
|
||||
|
|
|
@ -1523,6 +1523,13 @@ en:
|
|||
|
||||
None of the destination addresses are recognized. Please make sure that the site address is in the To: line (not Cc: or Bcc:), and that you are sending to the correct email address provided by staff.
|
||||
|
||||
email_reject_topic_not_found:
|
||||
subject_template: "Email issue -- Topic Not Found"
|
||||
text_body_template: |
|
||||
We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.
|
||||
|
||||
The topic is not found, it may have been deleted. If you believe this is in error, contact a staff member.
|
||||
|
||||
email_reject_topic_closed:
|
||||
subject_template: "Email issue -- Topic Closed"
|
||||
text_body_template: |
|
||||
|
|
|
@ -15,6 +15,7 @@ module Email
|
|||
class UserNotFoundError < ProcessingError; end
|
||||
class UserNotSufficientTrustLevelError < ProcessingError; end
|
||||
class BadDestinationAddress < ProcessingError; end
|
||||
class TopicNotFoundError < ProcessingError; end
|
||||
class TopicClosedError < ProcessingError; end
|
||||
class EmailLogNotFound < ProcessingError; end
|
||||
class InvalidPost < ProcessingError; end
|
||||
|
@ -69,6 +70,7 @@ module Email
|
|||
@email_log = dest_info[:obj]
|
||||
|
||||
raise EmailLogNotFound if @email_log.blank?
|
||||
raise TopicNotFoundError if Topic.find_by_id(@email_log.topic_id).nil?
|
||||
raise TopicClosedError if Topic.find_by_id(@email_log.topic_id).closed?
|
||||
|
||||
create_reply
|
||||
|
|
|
@ -253,6 +253,37 @@ Pleasure to have you here!
|
|||
end
|
||||
end
|
||||
|
||||
describe "posting reply to a deleted topic" do
|
||||
let(:reply_key) { raise "Override this in a lower describe block" }
|
||||
let(:email_raw) { raise "Override this in a lower describe block" }
|
||||
let(:receiver) { Email::Receiver.new(email_raw) }
|
||||
let(:deleted_topic) { Fabricate(:deleted_topic) }
|
||||
let(:post) { Fabricate(:post, topic: deleted_topic, post_number: 1) }
|
||||
let(:replying_user_email) { 'jake@adventuretime.ooo' }
|
||||
let(:replying_user) { Fabricate(:user, email: replying_user_email, trust_level: 2) }
|
||||
let(:email_log) { EmailLog.new(reply_key: reply_key,
|
||||
post: post,
|
||||
post_id: post.id,
|
||||
topic_id: deleted_topic.id,
|
||||
email_type: 'user_posted',
|
||||
user: replying_user,
|
||||
user_id: replying_user.id,
|
||||
to_address: replying_user_email
|
||||
) }
|
||||
|
||||
before do
|
||||
email_log.save
|
||||
end
|
||||
|
||||
describe "should not create post" do
|
||||
let!(:reply_key) { '59d8df8370b7e95c5a49fbf86aeb2c93' }
|
||||
let!(:email_raw) { fixture_file("emails/valid_reply.eml") }
|
||||
it "raises a TopicNotFoundError" do
|
||||
expect { receiver.process }.to raise_error(Email::Receiver::TopicNotFoundError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "posting a new topic" do
|
||||
let(:category_destination) { raise "Override this in a lower describe block" }
|
||||
let(:email_raw) { raise "Override this in a lower describe block" }
|
||||
|
|
|
@ -232,6 +232,31 @@ describe Jobs::PollMailbox do
|
|||
end
|
||||
end
|
||||
|
||||
describe "when topic is deleted" do
|
||||
let(:email) { MockPop3EmailObject.new fixture_file('emails/valid_reply.eml')}
|
||||
let(:deleted_topic) { Fabricate(:deleted_topic) }
|
||||
let(:first_post) { Fabricate(:post, topic: deleted_topic, post_number: 1)}
|
||||
|
||||
before do
|
||||
first_post.save
|
||||
EmailLog.create(to_address: 'jake@email.example.com',
|
||||
email_type: 'user_posted',
|
||||
reply_key: '59d8df8370b7e95c5a49fbf86aeb2c93',
|
||||
user: user,
|
||||
post: first_post,
|
||||
topic: deleted_topic)
|
||||
end
|
||||
|
||||
describe "should not create post" do
|
||||
it "raises a TopicNotFoundError" do
|
||||
expect_exception Email::Receiver::TopicNotFoundError
|
||||
|
||||
poller.handle_mail(email)
|
||||
email.should be_deleted
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "in failure conditions" do
|
||||
|
||||
it "a valid reply without an email log raises an EmailLogNotFound error" do
|
||||
|
|
Loading…
Reference in a new issue