mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 20:11:11 +08:00
FIX: Don't publish polls on message bus when there are no polls (#15041)
`poll` plugin was publishing on `/polls/[topic_id]` every time a non-first post was created. I can't imagine this being needed. It regressed 3 years ago in https://github.com/discourse/discourse/pull/6359
This commit is contained in:
@ -160,10 +160,11 @@ after_initialize do
|
|||||||
guardian = Guardian.new(user)
|
guardian = Guardian.new(user)
|
||||||
DiscoursePoll::Poll.schedule_jobs(post)
|
DiscoursePoll::Poll.schedule_jobs(post)
|
||||||
|
|
||||||
unless post.is_first_post?
|
next if post.is_first_post?
|
||||||
polls = ActiveModel::ArraySerializer.new(post.polls, each_serializer: PollSerializer, root: false, scope: guardian).as_json
|
next if post.custom_fields[DiscoursePoll::HAS_POLLS].blank?
|
||||||
post.publish_message!("/polls/#{post.topic_id}", post_id: post.id, polls: polls)
|
|
||||||
end
|
polls = ActiveModel::ArraySerializer.new(post.polls, each_serializer: PollSerializer, root: false, scope: guardian).as_json
|
||||||
|
post.publish_message!("/polls/#{post.topic_id}", post_id: post.id, polls: polls)
|
||||||
end
|
end
|
||||||
|
|
||||||
on(:merging_users) do |source_user, target_user|
|
on(:merging_users) do |source_user, target_user|
|
||||||
|
@ -128,4 +128,41 @@ describe DiscoursePoll::Poll do
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "post_created" do
|
||||||
|
it "publishes on message bus if a there are polls" do
|
||||||
|
first_post = Fabricate(:post)
|
||||||
|
topic = first_post.topic
|
||||||
|
creator = PostCreator.new(user,
|
||||||
|
topic_id: topic.id,
|
||||||
|
raw: <<~RAW
|
||||||
|
[poll]
|
||||||
|
* 1
|
||||||
|
* 2
|
||||||
|
[/poll]
|
||||||
|
RAW
|
||||||
|
)
|
||||||
|
|
||||||
|
messages = MessageBus.track_publish("/polls/#{topic.id}") do
|
||||||
|
creator.create!
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(messages.count).to eq(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not publish on message bus when a post with no polls is created" do
|
||||||
|
first_post = Fabricate(:post)
|
||||||
|
topic = first_post.topic
|
||||||
|
creator = PostCreator.new(user,
|
||||||
|
topic_id: topic.id,
|
||||||
|
raw: "Just a post with definitely no polls"
|
||||||
|
)
|
||||||
|
|
||||||
|
messages = MessageBus.track_publish("/polls/#{topic.id}") do
|
||||||
|
creator.create!
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(messages.count).to eq(0)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user