Editing an existing poll clears all existing votes, but for some reason the "Cancel your vote" button is still available. And if "Cancel your vote" button is selected, the vote count will go to -1!
Steps to reproduce:
1. Create a poll with two choices
2. Vote for the first choice -> now it has 1 vote
3. Click "Edit" tab, add a third choice and click "Save" button
4. You'll return to the poll results -> now all choices have 0 votes
5. Click "Cancel your vote" button
6. Click "Results" tab -> now the first choice has -100% (-1 votes) and Total votes is -1!
This seems to be somehow related to permissions, because I could not reproduce this with the admin (user 1) account. With admin user the editing does not automatically clear existing votes in step 3.
Anyway this is reproducible with an authenticated user that has permissions to "delete own poll content", "edit own poll content" and "vote on polls", but no other permissions related to the Poll module.
| Comment | File | Size | Author |
|---|---|---|---|
| #32 | 362256-poll-vote-32-D6.patch | 1.86 KB | pwolanin |
| #29 | poll-cancel_bug.patch | 615 bytes | mstef |
| #24 | poll_362256-4.patch | 808 bytes | derjochenmeyer |
| #21 | poll_362256-3.patch | 813 bytes | derjochenmeyer |
| #19 | poll_362256-2.patch | 842 bytes | derjochenmeyer |
Comments
Comment #1
ahaapaka commentedFirst of all, editing a poll is not intended to clear all votes. This is revealed in the following comment inside the poll_update() function:
Then the reason why votes disappear (when editing a poll):
1. Form data contains votes only if the user has permission to 'administer nodes'
2. poll_update() function assumes that the $node contains all data (not just updated data)
Comment #2
ahaapaka commentedComment #3
danielhonrade commented/* 6/8/09 danielhonrade bug report
*
* Hi, I was hacking the poll core module (which is really bad, I know but
* I only have few days to finish the project (http://pinometro.com) , this is temporary anyway, I am
* planning to create a module that would integrate to poll module with the following
* features:
* - use of google chart
* - add default values for choices
* - allow/disallow users to add choices and change other settings
* - require users to vote before commenting and not otherwise
*
* then I encountered this SAME PROBLEM, which I thought at first was the result of
* my hacking but when I installed a fresh Drupal6 and tested the poll again,
* it's still there, you can check the bug by:
* 1) Install fresh Drupal 6
* 2) Allow authenticated users to vote, create/edit/delete own poll
* 3) Login as a new authenticated user and not as admin, so you don't have node administer perm
* 4) Create a poll, then vote and edit then save
* 5) You'll notice that the vote values become 0
* 5) Cancel your vote, the result becomes -1
*
* PROBLEM: if an authenticated user without node administer permission but
* has a permission to edit his/any poll, everytime he edits his poll or
* any poll the vote values become 0 and when he goes to view tab,
* if has voted, the cancel button still exists even though vote values are 0
* so if he decided to cancel, the result is negative value which
* the validator function doesn't even notice
*
* I created a patch, which I am sure, it's not the best, but it works
*
* SOLUTION 1: I added an else statement where I copied the the content in the
* if($admin) {...} and added '#disabled' => 'disabled', and changed
* '#default_value' => $votes, to '#value' => $votes, because if the
* attribute is disabled #default_value doesn't pass its value
*
* SOLUTION 2: I added an else statement where I copied the the content in the
* if($admin) {...} and just change the '#type' => 'textfield', to '#type' => 'hidden',
* but you'll have nothing under the heading VOTE COUNT which is the original
* state when you create a poll in the original poll module
*/
Comment #4
danielhonrade commentedI am having problems with getting the right diff program. But here is the patch file, anyway
/* Based on the latest Drupal 6.12-dev
* PROBLEM: if an authenticated user without node administer permission but
* has a permission to edit his/any poll, everytime he edits his poll or
* any poll the vote values become 0 and when he goes to view tab,
* if has voted, the cancel button still exists even though vote values are 0
* so if he decided to cancel, the result is negative value which
* the validator function doesn't even notice
*
* I created a patch, which I am sure, it's not the best, but it works
*
* SOLUTION 1: I added an else statement where I copied the the content in the
* if($admin) {...} and added '#disabled' => 'disabled', and changed
* '#default_value' => $votes, to '#value' => $votes, because if the
* attribute is disabled #default_value doesn't pass its value
*
* SOLUTION 2: I added an else statement where I copied the the content in the
* if($admin) {...} and just change the '#type' => 'textfield', to '#type' => 'hidden',
* but you'll have nothing under the heading VOTE COUNT which is the original
* state when you create a poll in the original poll module
*/
Comment #5
dicreat commentedSolution at #3 works for me.
Comment #6
danielhonrade commentedThis should also work for 6.12 and 6.12-dev, I just tested it, now when a user edits his poll, it gives him a disabled number of votes which makes sense since he has no administrative privileges to change the number of votes, if he wants to delete his poll, he can also, thanks for testing. Unlike before, when the user edits his poll, they all become zeros and the vote cancel still appears and when he cancels the vote becomes negative 1.
Comment #7
mstef commentedThis is still an issue in 6.13. First off, the votes are set back to zero even if you don't change or add any of the vote options. Also, when viewing the poll, if you click the 'Votes' tab, you still get a list of who voted, despite the vote count being zero. Doesn't make any sense to me..
The patch in #3 works ... i think it should be committed.
Comment #8
avpadernoI have marked #484878: Poll module bug patch as duplicate of this report.
Comment #9
Pasi commentedAnd this is still an issue in 6.14. Solution at #3 works also for me.
Comment #10
avpadernoComment #11
Kane commentedStill exists in 6.16.
Comment #12
nancydruWhen you submit a patch, you need to change the status to "needs review" so the test bot will see it.
You also need to see if this happens in D7 as it is unlikely to get fixed otherwise.
Comment #14
nancydruI got around this problem with a submit handler:
Comment #15
nancydruLet's try this one.
Comment #17
nancydruArrrggghhh, how do you fix the line endings?
Comment #18
derjochenmeyer commented@NancyDru #14
Be carefull, the code of #14 updates all polls with the vote-counts of the current poll!!! We need to only update the current node. Change the WHERE statement to
c.nid=%dlike this:This code needs to be placed in a custom module in order to work.
I dont feel good in recalculating the number of votes from the chorder. The chid would be much better, but i guess we dont have another choice here, since the chid is not stored in poll_votes.
Comment #19
derjochenmeyer commentedreroll of poll_362256.patch
Comment #21
derjochenmeyer commentedwhat about this?
Comment #23
nancydruNice try on the patches.
I had caught that code error and fixed it, I just didn't come back here and update. But thanks for finding it and telling me any way. Yes, it is in a custom module. No, I don't like the recalculation either; a fix for this problem would be much nicer.
Comment #24
derjochenmeyer commentedlast try...
Comment #25
derjochenmeyer commentedThanks for sharing the code, it saved me a couple of hours. I just wanted to help anyone who just copies and pastes the code. I did that and it worked (seemed to) until i realized that all polls had the same number of votes :)
I think its bad design, that the chid gets not saved in the poll_votes table.
Comment #26
derjochenmeyer commentedComment #28
pwolanin commentedComment #29
mstef commented...try this
Comment #30
pwolanin commentedComment #31
pwolanin commentedIt looks like this is fixed in Drupal 7 - how about just backporting that fix?
http://api.drupal.org/api/function/_poll_choice_form/7
Comment #32
pwolanin commentedHere's a backport of the D7 approach.
Comment #33
mstef commentedThe patch applies fine and fixes the issue - sort of...
Adding another choice after voting works fine - as it doesn't reset all votes to value 0 while giving you the option to cancel. There still is the possibility of a foolish admin messing things up. If you manually change all of the vote values to 0 after editing the poll, you still have the cancel your vote button.
Is that worth fixing, or simply the admin's fault?
Comment #34
pwolanin commented@mikestefff - sounds like that situation is a bug not yet addressed in Drupal 7, and I'm not sure what the right behavior is. If the admin changes any vote values (up or down), what does it mean for a user to "cancel" their vote?
Comment #35
mstef commented@pwolanin - I don't think it's even an issue worth addressing, I just thought I should point it out so everyone is at least aware of the conditions. Otherwise, the patch works and I suggest it's committed. I'm very surprised this has been lingering for the several releases now. I'm not going to change the status of the issue - I'll leave that to you.
Thanks
Comment #36
pwolanin commentedgiven this is a straight backport from 7, I hope we are in good shape.
Comment #37
mstef commentedI can't comment on the code itself, as I didn't analyze it. Functionality wise, it works fine.
Comment #38
endiku commentedBackport patch #32 works well. Same problem of clearing votes from non-admin editors.
Comment #39
gábor hojtsyCommitted @pwolanin's backport to Drupal 6. Thanks for all the testing feedback!
Comment #40
mstef commentedNice. Thanks for clearing this up.
Comment #41
nancydruFabulous, Gábor and Peter. Any ideas when the next 6.x release will arrive?