mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
Poll Plugin: Don't allow voting on closed topics.
This commit is contained in:
parent
ae3f135c33
commit
9ef104bbce
4 changed files with 17 additions and 1 deletions
|
@ -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 }}}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue