Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

[Voting Addon] Bug: Can vote more then once on post (Is this being maintained?)*

edited February 2011 in Vanilla 2.0 - 2.8
Any "answer/thread" we call it post/topic etc

Anyways it allows duplicate, but on discussions view like on here, you can only vote it once.

Sorry if this is duplicate

Comments

  • I agree with you.
    Also when I clicked voting button even in this forum it resets voting counts...
  • I have the same problem. Voting seems to work alright in this discussion but not in the downloadable addon.
  • Looking at the next post down you need to make sure your not using an admin account.
  • yes, i have got same problem with voting. admin can vote up limitless, and normal accounts can reset the vote count.
  • sahotataransahotataran Developer, Bay Area - CA ✭✭✭
    seems like this problem still continues with me. anyone found any solutions to this?

    There was an error rendering this rich post.

  • I have several similar issues as well - I understand admins versus users but still think it should only be once. Some people can vote once, some several times, some endless. I would really love to get a fix for this. Does someones have one? Are there any other voting plugins? Thx in advance.

  • BboyHavocBboyHavoc New
    edited April 2012

    I had to change some things in the voting plugin but this worked for me. It makes it so that it only allows users to vote on comments once (+1 or -1) without having that crazy bug where it resets the voting count when logged in as a regular user(admins can still vote unlimited). Just replace the content in class.voting.plugin.php around 249-268 with this:

    $CommentID = GetValue(0, $Sender->RequestArgs, 0);
          $VoteType = GetValue(1, $Sender->RequestArgs);
          $TransientKey = GetValue(2, $Sender->RequestArgs);
          $Session = Gdn::Session();
          $OriginalScore = $Object->Score;
          $FinalVote = 0;
          $Total = 0;
          if ($Session->IsValid() && $Session->ValidateTransientKey($TransientKey) && $CommentID > 0) {
             $CommentModel = new CommentModel();
             $OldUserVote = $CommentModel->GetUserScore($CommentID, $Session->UserID);
             $NewUserVote = $VoteType == 'voteup' ? 1 : -1; //if voteup then $NewUserVote = 1 else -1
             $FinalVote = intval($OldUserVote) + intval($NewUserVote);
             // Allow admins to vote unlimited.
             $AllowVote = $Session->CheckPermission('Garden.Moderation.Manage');
             // Only allow users to vote up or down by 1.
             if (!$AllowVote && ($FinalVote > -2 && $FinalVote < 2)){
                $AllowVote = true;
             }else {
                $AllowVote = false;
             }
    
             if ($AllowVote){
                $Total = $CommentModel->SetUserScore($CommentID, $Session->UserID, $FinalVote);
             }else {
                $FinalFinalVote = $OriginalScore + $OldUserVote;
                $Total = $CommentModel->SetUserScore($CommentID, $Session->UserID, $FinalFinalVote);
             }
    
  • I tried doing this, but it prevents my admin account from making and votes at all on posts...

    I'm gonna disable this plugin until this is sorted out, otherwise I really like it! :/

  • mattmatt ✭✭

    Thanks @BboyHavoc

  • @A_Hashmi said:
    I tried doing this, but it prevents my admin account from making and votes at all on posts...

    I'm gonna disable this plugin until this is sorted out, otherwise I really like it! :/

    @A_Hashmi Did you make sure that you have the checkbox checked under Garden>Moderation>Manage in the Roles & Permissions section of the Dashboard?

    That's what line 14 in the above code is for to allow admins or whatever role with that checkbox checked to be able to vote infinite amount of times.

  • peregrineperegrine MVP
    edited November 2013

    I believe the answer is in this thread.

    2 questions -

    1) did you read all the discussions related to plugin. always a good idea to do that before enabling a plugin.

    2) I think this answers your question

    http://vanillaforums.org/discussion/comment/159049/#Comment_159049

    always a good idea to post questions about a plugin by going to the plugin and asking the question.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Mmm... I did replace the values in class.voting.plugin.php, but it doesn't work for me. After I applied the changes, Admin cannot vote, Moderator cannot vote too, and even Registered Users cannot vote.

  • peregrineperegrine MVP
    edited December 2013

    @Shinji3rd said:
    Mmm... I did replace the values in class.voting.plugin.php, but it doesn't work for me. After I applied the changes, Admin cannot vote, Moderator cannot vote too, and even Registered Users cannot vote.

    do they have permission?

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • @peregrine yes, they have permissions. But nevermind, I restored the original file with no modifications, and now the plugin works. Admin and moderators can vote multiple times, but regular users just one time, so that's ok with me.

  • Hi there, in fact there was very small bug in the code submited by BboyHavoc.
    If you remove the line 18 and 19 from his code everything works smothly like it should.
    Cheers

  • spadaspada New
    edited September 2014

    I had a weird bug with users being able to vote up/down by 2. I also didn't like that admins had special voting powers. Finally, people shouldn't be able to vote for their own comments.

    So I slightly changed the code and here is my version around lines 270-293 :

      $CommentID = GetValue(0, $Sender->RequestArgs, 0);
      $VoteType = GetValue(1, $Sender->RequestArgs);
      $TransientKey = GetValue(2, $Sender->RequestArgs);
      $Session = Gdn::Session();
      $FinalVote = 0;
      $Total = 0;
      if ($Session->IsValid() && $Session->ValidateTransientKey($TransientKey) && $CommentID > 0) {
         $CommentModel = new CommentModel();
    
         $OldUserVote = $CommentModel->GetUserScore($CommentID, $Session->UserID);
         $NewUserVote = $VoteType == 'voteup' ? 1 : -1;
         $FinalVote = intval($OldUserVote) + intval($NewUserVote);
    
        if (($FinalVote >= -1 && $FinalVote <= 1) &&                                    //Only allows +1 or -1 votes
             $CommentModel->GetID($CommentID)->InsertUserID != $Session->UserID) {      //Not allowed to vote for your own comments
                $AllowVote = true;
        }else $AllowVote = false;
    
        if ($AllowVote) {
            $Total = $CommentModel->SetUserScore($CommentID, $Session->UserID, $FinalVote);
        } else {
                $FinalFinalVote = $OldUserVote;
                $Total = $CommentModel->SetUserScore($CommentID, $Session->UserID, $FinalFinalVote);
        }
    
Sign In or Register to comment.