Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-21577

Ratings improperly remove ratings with 0 even if zero stored is allowed

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • 15.10.1
    • 15.9
    • Ratings
    • None
    • Unit
    • Unknown
    • N/A
    • N/A

    Description

      Have a look at this code here ..

      The case "or if we store zero" is not catched with the if-condition if(vote Unable to render embedded object: File (= 0). Thus for a 0-vote the else branch will be called. That however will remove the rating, if isZeroStored is configured. I thought it should rather remove, if not isZeroStored !?

      I think, the following code would be correct:

                  // If the vote is not 0 or if we store zero, we just modify the existing vote
                  if (vote != 0 || this.ratingsConfiguration.isZeroStored()) {
                      result = new DefaultRating(oldRating)
                          .setUpdatedAt(new Date())
                          .setVote(vote);
      
                      // It's an update of a vote
                      event = new UpdatedRatingEvent(result, oldRating.getVote());
                  // Else we remove it.
                  } else {
                      this.removeRating(oldRating.getId());
                  }
      

      Then, the if-Block catches three cases (either of vote != 0 or isZeroStored or both are true) and the else-Block catches the left over case (vote == 0 and !isZeroStored)

      Attachments

        Activity

          People

            surli Simon Urli
            hengels Holger Engels
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: