eloquence / lib.reviews

A free/libre code and information platform for reviews of anything
Creative Commons Zero v1.0 Universal
171 stars 13 forks source link

"You have previously reviewed" lib.reviews even though I have not #193

Closed arxcode closed 6 years ago

arxcode commented 6 years ago

I have a problem while trying to review lib.reviews itself. I do the following:

  1. Log in
  2. Click on "New review"
  3. Enter "https://lib.reviews/" in the "Review by URL" field
  4. The system correctly displays a new area "Review subject" and lists "lib.reviews".
  5. About half a second after that, a pop-up appears: "You have previously reviewed this subject: lib.reviews. Do you want to abandon the contents of this form and edit your existing review?"

Note that I have not reviewed lib.reviews before, so I don't think this error should appear. This is confirmed by the fact that the "Edit review" button doesn't do anything when clicking it.

I have looked at the code, but I am not sure if I understand correctly what is going on. In particular this line here:

        if (result.data.thing && result.data.thing.reviews) {

I am wondering whether the problem might be that an empty array in JavaScript is truthy? Because that's what the API returns. My browser requests the following URL (via GET):

https://lib.reviews/api/thing?url=https://lib.reviews/&userID=xxxxxx

(I replaced my userID with xxxxxx.)

The API returns the following:

{
  "thing": {
    "id": "a6d2c163-791b-4429-b0e7-4ca217a3e085",
    "label": {
      "en": "lib.reviews",
      "eo": "lib.reviews",
      "es": "lib.reviews",
      "it": "lib.reviews",
      "pt-PT": "lib.reviews"
    },
    "description": {
      "en": "platform for reviewing anything",
      "pt-PT": "plataforma para resenhar qualquer coisa"
    },
    "originalLanguage": "en",
    "canonicalSlugName": "lib.reviews",
    "urlID": "lib.reviews",
    "createdOn": "2016-11-15T13:19:12.094Z",
    "createdBy": "d07e8385-0302-4199-b05a-87b993efc5ac",
    "numberOfReviews": 2,
    "averageStarRating": 5,
    "urls": [
      "https://lib.reviews/",
      "https://www.wikidata.org/wiki/Q27926115"
    ],
    "reviews": []
  }
}

So reviews is empty, but a valid array, and thus evaluates to a truthy value, triggering the error?

eloquence commented 6 years ago

From a quick look your diagnosis appears absolutely correct. Thank you for the very detailed report, will fix.

eloquence commented 6 years ago

Fixed and deployed, lemme know if you still encounter this one.

arxcode commented 6 years ago

Wow, that was quick! I tested it again and now it seems to work. Thanks a lot for the great site!