FEATURE: Show votes in an "on voted" poll to the creator

This required properly plumbing the guardian into the serializer.

Notably, the default state in the client was not changed - if you haven't voted in
the poll, you need to click the button to view the results instead of the results
being immediately visible on page load.

Implements https://meta.discourse.org/t/-/138108
This commit is contained in:
Kane York
2020-03-20 11:29:00 -07:00
committed by Kane York
parent 0d3386d255
commit 330102fd20
6 changed files with 30 additions and 11 deletions

View File

@@ -47,7 +47,11 @@ class Poll < ActiveRecord::Base
def can_see_results?(user)
return !!user&.staff? if staff_only?
!!(always? || (on_vote? && has_voted?(user)) || is_closed?)
!!(always? || (on_vote? && (is_me?(user) || has_voted?(user))) || is_closed?)
end
def is_me?(user)
user && post.user&.id == user&.id
end
def has_voted?(user)

View File

@@ -61,7 +61,7 @@ class PollSerializer < ApplicationSerializer
end
def include_preloaded_voters?
object.can_see_voters?(scope)
object.can_see_voters?(scope.user)
end
end