diff --git a/plugins/poll/assets/javascripts/discourse/templates/poll.js.handlebars b/plugins/poll/assets/javascripts/discourse/templates/poll.js.handlebars index fdaff3226..3168dc130 100644 --- a/plugins/poll/assets/javascripts/discourse/templates/poll.js.handlebars +++ b/plugins/poll/assets/javascripts/discourse/templates/poll.js.handlebars @@ -1,7 +1,7 @@ {{#each poll.options}} - +
{{{ option }}} diff --git a/plugins/poll/assets/javascripts/poll_ui.js b/plugins/poll/assets/javascripts/poll_ui.js index fdafc7ec2..aa9ea01dc 100644 --- a/plugins/poll/assets/javascripts/poll_ui.js +++ b/plugins/poll/assets/javascripts/poll_ui.js @@ -38,8 +38,14 @@ var PollController = Discourse.Controller.extend({ poll: null, showResults: false, + disableRadio: Em.computed.any('poll.post.topic.closed', 'loading'), + actions: { selectOption: function(option) { + if (this.get('disableRadio')) { + return; + } + if (!this.get('currentUser.id')) { this.get('postController').send('showLogin'); return; diff --git a/plugins/poll/poll.rb b/plugins/poll/poll.rb index 1261e1ca7..c7ebfd2f7 100644 --- a/plugins/poll/poll.rb +++ b/plugins/poll/poll.rb @@ -124,6 +124,8 @@ module ::PollPlugin end def set_vote!(user, option) + return if @post.topic.closed? + # Get the user's current vote. vote = get_vote(user) vote = nil unless details.keys.include? vote diff --git a/plugins/poll/spec/poll_plugin/poll_spec.rb b/plugins/poll/spec/poll_plugin/poll_spec.rb index ca121e379..36c4506ec 100644 --- a/plugins/poll/spec/poll_plugin/poll_spec.rb +++ b/plugins/poll/spec/poll_plugin/poll_spec.rb @@ -50,6 +50,14 @@ describe PollPlugin::Poll do poll.details["Onodera"].should eq(1) end + it "should not set votes on closed polls" do + poll.set_vote!(user, "Onodera") + post.topic.closed = true + post.topic.save! + poll.set_vote!(user, "Chitoge") + poll.get_vote(user).should eq("Onodera") + end + it "should serialize correctly" do poll.serialize(user).should eq({options: poll.details, selected: nil}) poll.set_vote!(user, "Onodera")