mirror of
https://github.com/discourse/discourse.git
synced 2024-12-21 07:56:29 +08:00
f7d7092a7a
The lastest version of rubocop-discourse enables rules regarding plugins.
27 lines
627 B
Ruby
27 lines
627 B
Ruby
# frozen_string_literal: true
|
|
|
|
module DiscoursePoll
|
|
module PostExtension
|
|
extend ActiveSupport::Concern
|
|
|
|
prepended do
|
|
attr_accessor :extracted_polls
|
|
|
|
has_many :polls, dependent: :destroy
|
|
|
|
after_save do
|
|
polls = self.extracted_polls
|
|
self.extracted_polls = nil
|
|
next if polls.blank? || !polls.is_a?(Hash)
|
|
post = self
|
|
|
|
::Poll.transaction do
|
|
polls.values.each { |poll| DiscoursePoll::Poll.create!(post.id, poll) }
|
|
post.custom_fields[DiscoursePoll::HAS_POLLS] = true
|
|
post.save_custom_fields(true)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|