bug in the checkMaxVotes () - proposal of a patch
Hello, I found a bug in the checkMaxVotes() function of the PollService.php file in the following use case:
- creation of a poll by date with a number of commitments limited to a value x.
- intervention of an administrator on a person's vote (modification of a commitment on a date) The control of the maximum commitments does not take into account the own vote of the person being modified. In fact, the software blocks as soon as it finds a slot that has reached the maximum vote even if one of these votes is that of the user being modified. The bug can be corrected as follows:
* This method checks if the votes doesn't conflicts the maximum votes constraint
* @param $ user_choice
* @param \ stdClass $ poll
* @param string $ poll_id
* @throws ConcurrentVoteException
* /
//private function checkMaxVotes ($user_choice, $poll, $poll_id) {
private function checkMaxVotes ($user_choice, $poll, $poll_id, $vote_id) {
$ votes = $ this-> allVotesByPollId ($ poll_id);
if (count ($ votes) <= 0) {
return;
}
// look for the existing polls of the user who would like to change them
$count = 0; // init counter
$user_considere = 0; // init id user to consider
foreach ($votes as $v){
if ($v-> id == $vote_id){
$user_considere = $count;
}
else $count ++;
}
$best_choices = $this-> computeBestChoices ($votes, $poll);
foreach ($best_choices ['y'] as $i => $nb_choice) {
// if for this option we have reached maximum value and user wants to add itself too
$ch = substr ($votes [$user_considere] -> choices, $i, 1);
// if ($ poll-> ValueMax! == null && $ nb_choice> = $ poll-> ValueMax && $ user_choice [$ i] === "2") {
if ($poll-> ValueMax! == null && $nb_choice> = $poll-> ValueMax && $user_choice [$i] === "2" && $ch! = "2") {// if we reached the maximum values and the user poll is 2 and the previous poll was not 2 => not possible else ok
throw new ConcurrentVoteException ();
}
}
}
}```
thank's for all