Problem/Motivation
I am working on a site using the Voting API module and the Like & Dislike module. I would like to allow anonymous users to vote.
This module saves a vote_source
(by default the IP address) for each vote, so this should be possible. The problem is that when a module (here Like & Dislike) asks how many times the current user has voted by calling VoteStorage::getUserVotes()
the vote_source
is ignored. If the current user is anonymous, and a different anonymous user has voted, it looks as though the currrent user has already voted.
Proposed resolution
Add an optional parameter to VoteStorage::getUserVotes()
specifying the vote source. If the parameter is omitted, and the user is anonymous, then use the default callback for the vote type.
Whenever the user is anonymous, count only votes for the matching vote_source
, whether passed in or from the default.
Make corresponding changes to the VoteStorage::deleteUserVotes()
method.
Remaining tasks
Write a patch.- Review the patch.
- Update the documentation.
User interface changes
None.
API changes
This changes the public API of the VoteStorage
class. It adds an optional parameter to the getUserVotes()
and deleteUserVotes()
methods, and it changes the behavior of these method when the user is anonymous (whether or not the optional parameter is supplied). IMHO, the change in behavior is a bug fix.
Modules that use the Voting API and manage the vote source themselves (using Vote::setSource()
before Vote::save()
) will have to be updated to use the new parameter. Modules that use the default behavior will not have to change, but they will get different results when calling VoteStorage::getUserVotes()
for anonymous users.
Data model changes
None. There is already a vote_source
field in the database table.
Comment | File | Size | Author |
---|---|---|---|
#5 | 2846341-anonymous-votes-5.patch | 6.14 KB | benjifisher |
#5 | 2846341-anonymous-votes-5-tests-only.patch | 1.98 KB | benjifisher |
#2 | 2846341-anonymous-votes-2.patch | 4.15 KB | benjifisher |
Comments
Comment #2
benjifisherThe attached patch does what I suggested in the issue description. It also makes the corresponding update to the
deleteUserVotes()
method. In fact, in the spirit of DRY, this patch replaces most of the body of that function with a call togetUserVotes()
.Comment #3
benjifisherComment #4
Tom.W CreditAttribution: Tom.W at PwC's Experience Center commented@benjifisher - As we were discussing this yesterday and you asked for my input - Could you write an accompanying test which proves that this change works as intended? That would definitely make the patch easier to review
Comment #5
benjifisher@Tom.W You might have changed the status to NW.
I have added two new patches. The "tests-only" patch should lead to a failing test if you apply it. (It looks as though automated testing is disabled for this module.) It also amounts to an interdiff. The other patch includes both the new test and the changes from #2.
Comment #6
jeroen.b CreditAttribution: jeroen.b at .VDMi/ commentedI can confirm that this patch fixes the issue in like_and_dislike module.
Thanks for the patch @benjifisher!
Comment #7
benjifisher@jeroen.b Can you mark the issue RTBC? Your comment suggests that you have Tested, but maybe you have not Reviewed the code changes.
Comment #8
jeroen.b CreditAttribution: jeroen.b at .VDMi/ commentedDid a code review now. Looks good.
Comment #9
BarisW CreditAttribution: BarisW at LimoenGroen commentedThanks for the patch. I'm still having issues with VotingAPI Widgets, but I'm afraid that's related to how that module checks if voting should be enabled: #2896994: Anonymous voting doesn't work
Comment #11
pifagorDone
Comment #12
pifagor