FIX: hides votes from regular users when poll is staff only (#11342)

This commit is contained in:
Joffrey JAFFEUX
2020-11-24 22:19:06 +01:00
committed by GitHub
parent a6613d15f4
commit ad1a10e6e9
3 changed files with 70 additions and 2 deletions
@@ -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