olin-build / ABE

Amorphous Blob of Events
https://abe.olin.build/
GNU Affero General Public License v3.0
7 stars 1 forks source link

Require arrays for label field #50

Open newsch opened 7 years ago

newsch commented 7 years ago

Single strings can be passed in for the labels field, which are parsed incorrectly somewhere between the database and the json response, splitting up the string into an array of characters. link to issue on frontend.

Here's an example event in mongodb:

{
    "_id" : ObjectId("5967ddc6e23b8c000487d147"),
    "_cls" : "Event",
    "title" : "Midnight Memes",
    "description" : "![now including surreal memes](https://i.imgur.com/I1Nvebi.jpg)",
    "location" : "EH3nw",
    "start" : ISODate("2017-07-15T03:59:53Z"),
    "end" : ISODate("2017-07-15T05:00:53Z"),
    "visibility" : "students",
    "labels" : "Library",
    "sub_events" : [ ]
}

and the JSON output:

{
    "_cls": "Event", 
    "description": "![now including surreal memes](https://i.imgur.com/I1Nvebi.jpg)", 
    "end": "2017-07-15 05:00:53", 
    "id": "5967ddc6e23b8c000487d147", 
    "labels": [
      "L", 
      "i", 
      "b", 
      "r", 
      "a", 
      "r", 
      "y"
    ], 
    "location": "EH3nw", 
    "start": "2017-07-15 03:59:53", 
    "title": "Midnight Memes", 
    "visibility": "students"
}
newsch commented 7 years ago

This is fixed on the frontend but should still be updated on the backend

mpbrucker commented 6 years ago

It's unclear whether this is still an issue - none of the events currently in the database have this issue as far as I can tell (querying http://abe.olin.build/events?start=2017&end=2018 returned 685 events all with lists for labels), and when trying to create a new event with:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ \ 
   "allDay": true, \ 
   "description": "Time for tea", \ 
   "end": "2018-04-27T18:49:41.508Z", \ 
   "labels": "string", \ 
   "location": "EH4L", \ 
   "start": "2018-04-27T18:49:41.508Z", \ 
   "title": "Tea time", \ 
   "visibility": "public" \ 
 }' 'http://localhost:3000/events/'

I got a 400 with the response:

{
  "error_message": "ValidationError (Event:None) (Only lists and tuples may be used in a list field: ['labels'])",
  "error_type": "validation",
  "validation_errors": [
    "labels"
  ]
}