Poll Plugin: Don't allow voting on closed topics.

This commit is contained in:
Vikhyat Korrapati 2014-03-16 19:18:40 +05:30
parent ae3f135c33
commit 9ef104bbce
4 changed files with 17 additions and 1 deletions

View file

@ -1,7 +1,7 @@
<table>
{{#each poll.options}}
<tr {{bind-attr class=checked:active}} {{action selectOption option}}>
<td class="radio"><input type="radio" name="poll" {{bind-attr checked=checked disabled=controller.loading}}></td>
<td class="radio"><input type="radio" name="poll" {{bind-attr checked=checked disabled=controller.disableRadio}}></td>
<td class="option">
<div class="option">
{{{ option }}}

View file

@ -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;

View file

@ -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

View file

@ -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")