mirror of
https://github.com/discourse/discourse.git
synced 2025-06-17 17:32:33 +08:00
FIX: Defer topic/post created events until emails have been added (#15252)
This commit is contained in:

committed by
GitHub

parent
f24027b453
commit
ec36cddd2f
@ -1275,6 +1275,7 @@ module Email
|
|||||||
# emails, we skip the jobs here and enqueue them only _after_
|
# emails, we skip the jobs here and enqueue them only _after_
|
||||||
# the incoming email has been updated with the post and topic.
|
# the incoming email has been updated with the post and topic.
|
||||||
options[:skip_jobs] = true
|
options[:skip_jobs] = true
|
||||||
|
options[:skip_events] = true
|
||||||
result = NewPostManager.new(user, options).perform
|
result = NewPostManager.new(user, options).perform
|
||||||
|
|
||||||
errors = result.errors.full_messages
|
errors = result.errors.full_messages
|
||||||
@ -1305,6 +1306,8 @@ module Email
|
|||||||
import_mode: options[:import_mode],
|
import_mode: options[:import_mode],
|
||||||
post_alert_options: options[:post_alert_options]
|
post_alert_options: options[:post_alert_options]
|
||||||
).enqueue_jobs
|
).enqueue_jobs
|
||||||
|
DiscourseEvent.trigger(:topic_created, result.post.topic, options, user)
|
||||||
|
DiscourseEvent.trigger(:post_created, result.post, options, user)
|
||||||
end
|
end
|
||||||
|
|
||||||
result.post
|
result.post
|
||||||
|
@ -1364,6 +1364,14 @@ describe Email::Receiver do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "works" do
|
it "works" do
|
||||||
|
handler_calls = 0
|
||||||
|
handler = proc { |topic|
|
||||||
|
expect(topic.incoming_email_addresses).to contain_exactly("discourse@bar.com", "category@foo.com")
|
||||||
|
handler_calls += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
DiscourseEvent.on(:topic_created, &handler)
|
||||||
|
|
||||||
user = Fabricate(:user, email: "existing@bar.com", trust_level: SiteSetting.email_in_min_trust)
|
user = Fabricate(:user, email: "existing@bar.com", trust_level: SiteSetting.email_in_min_trust)
|
||||||
group = Fabricate(:group)
|
group = Fabricate(:group)
|
||||||
|
|
||||||
@ -1380,6 +1388,9 @@ describe Email::Receiver do
|
|||||||
|
|
||||||
# allows new user to create a topic
|
# allows new user to create a topic
|
||||||
expect { process(:new_user) }.to change(Topic, :count)
|
expect { process(:new_user) }.to change(Topic, :count)
|
||||||
|
|
||||||
|
DiscourseEvent.off(:topic_created, &handler)
|
||||||
|
expect(handler_calls).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "creates visible topic for ham" do
|
it "creates visible topic for ham" do
|
||||||
|
Reference in New Issue
Block a user