From 9ef104bbce1ca86253f4dfcbf96af1b4970fffdc Mon Sep 17 00:00:00 2001 From: Vikhyat Korrapati Date: Sun, 16 Mar 2014 19:18:40 +0530 Subject: [PATCH] Poll Plugin: Don't allow voting on closed topics. --- .../javascripts/discourse/templates/poll.js.handlebars | 2 +- plugins/poll/assets/javascripts/poll_ui.js | 6 ++++++ plugins/poll/poll.rb | 2 ++ plugins/poll/spec/poll_plugin/poll_spec.rb | 8 ++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/plugins/poll/assets/javascripts/discourse/templates/poll.js.handlebars b/plugins/poll/assets/javascripts/discourse/templates/poll.js.handlebars index fdaff32268f..3168dc130c0 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 fdafc7ec268..aa9ea01dc7d 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 1261e1ca7ba..c7ebfd2f70d 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 ca121e379ad..36c4506ec71 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")