SoftInstigate / restheart

Rapid API Development with MongoDB
https://restheart.org
GNU Affero General Public License v3.0
807 stars 171 forks source link

Cant update transformer if name originally typo'ed #345

Closed ml27299 closed 5 years ago

ml27299 commented 5 years ago

If you were to put a wrong/typo name for a transformer (phase = REQUEST), you cant use the PATCH request on a collection to unset it.

Imagine this was called first

$ curl -v -u a:a -X PUT http://localhost:8080/db/mycollection --header "content-type: application/json" --data '{ "rts": [  
                { "name": "addRequestProperty", "phase":"REQUEST","scope":"CHILDREN", "args": { "somedate": "dateTime" } } 
            ] }'

the name should be "addRequestProperties", so I should be able to unset the "rts" property, then set it again with the proper name

Expected Behavior

$ curl -v -u a:a -X PATCH http://localhost:8080/db/mycollection --header "content-type: application/json" --data '{"$unset": {"rts":true}}'
$ curl -v -u a:a -X PUT http://localhost:8080/db/mycollection --header "content-type: application/json" --data '{ "rts": [  
                { "name": "addRequestProperties", "phase":"REQUEST","scope":"CHILDREN", "args": { "somedate": "dateTime" } } 
            ] }'

Current Behavior

$ curl -v -u a:a -X PATCH http://localhost:8080/db/mycollection --header "content-type: application/json" --data '{"$unset": {"rts":true}}'

{"_exceptions":[{"exception":"java.lang.IllegalArgumentException","exception message":"no singleton configured with name: addRequestProperty"}],"http status code":500,"http status description":"Internal Server Error","message":"Error handling the request, see log for more information"}

Context

If I were to mess up the name, I cant make any requests except DELETE requests. I was able to fix it by dropping my database and reseeding it, but luckily it was a local database, that's not an acceptable solution for production use cases.

Removing the whole database was necessary because even tho "show collections" showed a "_properties" collection, doing "db._properties.drop()" did not work, it just said "db._properties" is undefined

Environment

mongo 3.6 restheart 3.9.0-SNAPSHOT(docker container)

Steps to Reproduce

  1. Add a request transformer to a collection and misspell the name
  2. Try making any request
  3. Try updating the collection metadata to replace/remove "rts"

Possible Implementation

If you can make it work like how the documentation says to update collection properties, then I'd say thats the best solution, but since the problem is kinda fundamental to how a request transformer is implemented, then maybe this would work?

I've implemented schemas in my restheart, I've noticed a "_schemas" collection was made (same deal as the _properties behavior when trying to execute any mongodb commands to it). In the documentation it doesnt quite say that you can delete schemas, but its kinda implied. I would think the same way that schemas are deleted, a metadata property on a collection can be deleted?

currently in restheart, you can do this to delete a schema

$ curl -v -u a:a -X DELETE http://localhost:8080/db/_schemas/myschema --header "content-type: application/json"

So, something like this to remove properties?

$ curl -v -u a:a -X DELETE http://localhost:8080/db/_properties/mycollection --header "content-type: application/json" -data '{"$unset": {"rts":true}}'
currently, this 403's due to it being a restricted resource
ujibang commented 5 years ago

If a transformer or checker fails (for instance, if its name contains a typo and cannot be found in configuration) the request is executed, a warn is added to the response and the error is logged.

This way this issue can be fixed PATCHing the rts metadata.

mkjsix commented 5 years ago

@ujibang we'll have to port this fix also on the 4.0 release

ujibang commented 5 years ago

This was cherry picked from 4.0

ml27299 commented 5 years ago

Sweet, thx! you guys have great response times!

mkjsix commented 5 years ago

Thank you @ml27299

We are gathering feedback from users to improve the community, the product and also create the next major version of RESTHeart. If it's ok, you can follow up on issue #321 or you can write an email to info@softinstigate.com (if you want to share details that you prefer not to disclose publicly) with you thought and we'll follow up, so that we can keep you in the loop about our roadmap and give the product a direction that is based on actual user's input.

The items we'd like to discuss are:

We'll soon put a "call to action" link on our website, so that all users can participate.

mkjsix commented 5 years ago

Hi @ml27299 We have released 3.10.0 which includes this fix https://github.com/SoftInstigate/restheart/releases/tag/3.10.0

ml27299 commented 5 years ago

sweet, thx!