FIX: Store custom attributes that are needed by plugins in queuedpost payload (#8009)
This commit is contained in:
parent
a5542768ea
commit
79957706b1
|
@ -21,6 +21,14 @@ class NewPostManager
|
|||
sorted_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?
|
||||
|
||||
|
|
|
@ -402,6 +402,8 @@ after_initialize do
|
|||
true
|
||||
end
|
||||
|
||||
NewPostManager.add_plugin_payload_attribute("is_poll")
|
||||
|
||||
NewPostManager.add_handler(1) do |manager|
|
||||
post = Post.new(raw: manager.args[:raw])
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@ describe NewPostManager do
|
|||
SiteSetting.poll_minimum_trust_level_to_create = 0
|
||||
end
|
||||
|
||||
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 do
|
|||
referrer: "http://localhost:3000/",
|
||||
first_post_checks: true
|
||||
}
|
||||
end
|
||||
|
||||
it "should render the poll upon approval" do
|
||||
result = NewPostManager.new(user, params).perform
|
||||
expect(result.action).to eq(:enqueued)
|
||||
expect(result.reviewable).to be_present
|
||||
|
@ -35,5 +37,23 @@ describe NewPostManager do
|
|||
review_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)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue