Fork me on GitHub
Current release is 2.1.5 (31 Oct 2014).

Users who have not yet upgraded to 2.1 should get security release 2.0.18.14 (1 Nov 2014). We will stop providing these security releases to 2.0 at the end of this year.

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

edited February 2011 in Vanilla 2.0 Help
This discussion is related to the Voting addon.
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.
    Silvestr92
  • sahotataransahotataran Developer, Bay Area - CA ✭✭✭
    seems like this problem still continues with me. anyone found any solutions to this?

    Theme Charcha for great desktop and mobile experience! - drop me a message :)

  • 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);
             }
    
    matt
  • 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 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 ☯ hasta luego :) In-Flight MVP
    edited November 2013

    @kramer65 said in this discussion in outer space.

    http://vanillaforums.org/discussion/25407/how-to-restrict-users-from-voting-more-than-once-in-the-voting-plugin

    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.

    Monetary Donations will be appreciated if you use my plugins. Thanks in Advance.
    As a waiter gets a tip for a good meal, tips for successful solutions appreciated as well. Peregrine

  • 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 ☯ hasta luego :) In-Flight 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?

    Monetary Donations will be appreciated if you use my plugins. Thanks in Advance.
    As a waiter gets a tip for a good meal, tips for successful solutions appreciated as well. Peregrine

  • @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 25

    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);
        }
    
    hgtonight
Sign In or Register to comment.