mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user