mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 10:43:57 +08:00
30990006a9
This reduces chances of errors where consumers of strings mutate inputs and reduces memory usage of the app. Test suite passes now, but there may be some stuff left, so we will run a few sites on a branch prior to merging
62 lines
1.1 KiB
Ruby
62 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class PollSerializer < ApplicationSerializer
|
|
attributes :name,
|
|
:type,
|
|
:status,
|
|
:public,
|
|
:results,
|
|
:min,
|
|
:max,
|
|
:step,
|
|
:options,
|
|
:voters,
|
|
:close,
|
|
:preloaded_voters
|
|
|
|
def public
|
|
true
|
|
end
|
|
|
|
def include_public?
|
|
object.everyone?
|
|
end
|
|
|
|
def include_min?
|
|
object.min.present? && (object.number? || object.multiple?)
|
|
end
|
|
|
|
def include_max?
|
|
object.max.present? && (object.number? || object.multiple?)
|
|
end
|
|
|
|
def include_step?
|
|
object.step.present? && object.number?
|
|
end
|
|
|
|
def options
|
|
object.poll_options.map { |o| PollOptionSerializer.new(o, root: false).as_json }
|
|
end
|
|
|
|
def voters
|
|
object.poll_votes.map { |v| v.user_id }.uniq.count + object.anonymous_voters.to_i
|
|
end
|
|
|
|
def close
|
|
object.close_at
|
|
end
|
|
|
|
def include_close?
|
|
object.close_at.present?
|
|
end
|
|
|
|
def preloaded_voters
|
|
DiscoursePoll::Poll.serialized_voters(object)
|
|
end
|
|
|
|
def include_preloaded_voters?
|
|
object.can_see_voters?(scope)
|
|
end
|
|
|
|
end
|