A platform for community discussion. Free, open, simple.
FIX: Store custom attributes that are needed by plugins in queuedpost payload (#8009)
Roman Rizzi79957706b1cd
diff --git a/lib/new_post_manager.rb b/lib/new_post_manager.rbindex a9a12786940..5db5cd5ef3a 100644--- a/lib/new_post_manager.rb+++ b/lib/new_post_manager.rb@@ -21,6 +21,14 @@ class NewPostManagersorted_handlers.map { |h| h[:proc] }end+ def self.plugin_payload_attributes+ @payload_attributes ||= []+ end++ def self.add_plugin_payload_attribute(attribute)+ plugin_payload_attributes << attribute+ end+def self.clear_handlers!@sorted_handlers = []end@@ -208,6 +216,9 @@ class NewPostManager%w(typing_duration_msecs composer_open_duration_msecs reply_to_post_number).each do |a|payload[a] = @args[a].to_i if @args[a]end++ self.class.plugin_payload_attributes.each { |a| payload[a] = @args[a] if @args[a].present? }+payload[:via_email] = true if !!@args[:via_email]payload[:raw_email] = @args[:raw_email] if @args[:raw_email].present?diff --git a/plugins/poll/plugin.rb b/plugins/poll/plugin.rbindex ca5948292dd..29c365aec42 100644--- a/plugins/poll/plugin.rb+++ b/plugins/poll/plugin.rb@@ -402,6 +402,8 @@ after_initialize dotrueend+ NewPostManager.add_plugin_payload_attribute("is_poll")+NewPostManager.add_handler(1) do |manager|post = Post.new(raw: manager.args[:raw])diff --git a/plugins/poll/spec/lib/new_post_manager_spec.rb b/plugins/poll/spec/lib/new_post_manager_spec.rbindex 9517e4fafb4..4bee4c5a4fc 100644--- a/plugins/poll/spec/lib/new_post_manager_spec.rb+++ b/plugins/poll/spec/lib/new_post_manager_spec.rb@@ -11,8 +11,8 @@ describe NewPostManager doSiteSetting.poll_minimum_trust_level_to_create = 0end- it "should render the poll upon approval" do- params = {+ let(:params) do+ {raw: "[poll]\n* 1\n* 2\n* 3\n[/poll]",archetype: "regular",category: "",@@ -27,7 +27,9 @@ describe NewPostManager doreferrer: "http://localhost:3000/",first_post_checks: true}+ end+ it "should render the poll upon approval" doresult = NewPostManager.new(user, params).performexpect(result.action).to eq(:enqueued)expect(result.reviewable).to be_present@@ -35,5 +37,23 @@ describe NewPostManager doreview_result = result.reviewable.perform(admin, :approve_post)expect(Poll.where(post: review_result.created_post).exists?).to eq(true)end++ it 're-validates the poll when the approve_post event is triggered' do+ invalid_raw_poll = <<~RAW+ [poll type=multiple min=0]+ * 1+ * 2+ [/poll]+ RAW++ result = NewPostManager.new(user, params).perform++ reviewable = result.reviewable+ reviewable.payload["raw"] = invalid_raw_poll+ reviewable.save!++ review_result = result.reviewable.perform(admin, :approve_post)+ expect(Poll.where(post: review_result.created_post).exists?).to eq(false)+ endendend