FIX: hides votes from regular users when poll is staff only (#11342)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class PollOptionSerializer < ApplicationSerializer
|
||||
|
||||
attributes :id, :html, :votes
|
||||
|
||||
def id
|
||||
@@ -13,4 +12,7 @@ class PollOptionSerializer < ApplicationSerializer
|
||||
object.poll_votes.size + object.anonymous_votes.to_i
|
||||
end
|
||||
|
||||
def include_votes?
|
||||
scope[:can_see_results]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -42,7 +42,15 @@ class PollSerializer < ApplicationSerializer
|
||||
end
|
||||
|
||||
def options
|
||||
object.poll_options.map { |o| PollOptionSerializer.new(o, root: false).as_json }
|
||||
can_see_results = object.can_see_results?(scope.user)
|
||||
|
||||
object.poll_options.map do |option|
|
||||
PollOptionSerializer.new(
|
||||
option,
|
||||
root: false,
|
||||
scope: { can_see_results: can_see_results }
|
||||
).as_json
|
||||
end
|
||||
end
|
||||
|
||||
def voters
|
||||
|
||||
Reference in New Issue
Block a user