Skip to content

Commit

Permalink
Make polls work better on multi-language forums.
Browse files Browse the repository at this point in the history
  • Loading branch information
vikhyat committed Apr 1, 2014
1 parent a3f270f commit 5f94579
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions plugins/poll/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def vote

post = Post.find(params[:post_id])
poll = PollPlugin::Poll.new(post)
unless poll.is_poll?
unless poll.has_poll_details?
render status: 400, json: false
return
end
Expand Down Expand Up @@ -102,7 +102,7 @@ def poll_details
PollPlugin::Poll.new(object).serialize(scope.user)
end
def include_poll_details?
PollPlugin::Poll.new(object).is_poll?
PollPlugin::Poll.new(object).has_poll_details?
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions plugins/poll/poll.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ def is_poll?
topic.title =~ /^#{I18n.t('poll.prefix')}/i
end

def has_poll_details?
if SiteSetting.allow_user_locale?
# If we allow users to select their locale of choice we cannot detect polls
# by the prefix, so we fall back to checking if the poll details is set in
# places to make sure polls are still accessible by users using a different
# locale than the one used by the topic creator.
not self.details.nil?
else
self.is_poll?
end
end

# Called during validation of poll posts. Discourse already restricts edits to
# the OP and staff, we want to make sure that:
#
Expand Down

0 comments on commit 5f94579

Please sign in to comment.