Run couch validations client side
We have document update validation in couchdb which works well, except now that documents are created on the client side this only runs on replication which doesn't give good feedback to the user. There is however a pouch plugin for executing the couch validations on the client.
Use the plugin to run our existing document validations on the client so errors are shown on document creation/update.
@abbyad please close or schedule before the end of this sprint. See triaging old issues.
@garethbowen is this something that you think we need to implement now, or add to our feature request or tech debt lists for prioritization?
@abbyad It should be fairly straightforward - chuck it in!
Added to current iteration, although I am not 100% sure you are not being sarcastic.
I am never sarcastic.
This is a bit more complicated than previously thought: we also need to include the validation in medic-client as it's currently only in the medic ddoc. I'll spend a little bit of time looking into this, but it turns into me pulling a thread I'll drop it for now.
This is a bit more complicated than I think is worth it right now. I might look at it later in the week if I'm feeling like it, but I'm worried it's a rabbit hole.
I've commited my WIP here: https://github.com/medic/medic-webapp/pull/3181
As noted in the PR:
Doesn't work, because userCtx doesn't look to be the same locally.
To test, check out this branch, grunt dev, log in as a local user, and then in the console:
let DB = angular.element(document.body).injector().get('DB'); DB().post({type: 'a-bad-doc'}).then(console.log).catch(console.error);This should fail locally with a console.error because the doc type is wrong.
What actually happens is that it incorrectly fails because it thinks the user is not logged in.
Well this is interesting / horrifying.
Arguments to validate_doc_update remotely:
{"0":{"_id":"f5587f5a-3f3a-4f54-a0a5-df801765807b","type":"a-bad-doc","_revisions":{"start":0,"ids":[]}},"1":null,"2":{"db":"medic","name":"demo","roles":["district-manager","kujua_user","data_entry","district_admin"]},"3":{}}
Arguments to validate_doc_update locally:
{"0":{"type":"a-bad-doc","_id":"c7e13e0b-6f1a-4704-ff53-f75bfe9fd7b8"},"1":null,"2":{"db":"medic-user-demo","name":null,"roles":["_admin"]},"3":{}}
I guess that does make sense, you are admin locally. It probably changes a bunch of our rules though.
Well that's done. "Fairly straightforward" is a phrase that is definitely open to interpretation, though I'm not sure how much interpretation.
@garethbowen, if you'd me the honour of a review: https://github.com/medic/medic-webapp/pull/3181
Nice. One change requested. Back to you!
Merged.
AT: we should be validating documents on the client-side as much as we can (ie document structure stuff, not authority stuff).
This broke replication, see #3236 .
I've disabled it for now, we should take a look at why this is happening so we can complete this.
I made a branch of where master was where validation worked, but replication didn't: https://github.com/medic/medic-webapp/blob/2222_validation_and_replication/static/js/services/db.js
I imagine there is a bug in pouchdb-validation that we'd need to look into.
Hi @abbyad,
This ticket has not been touched in 90 days. Is it still relevant?
Please also ensure this ticket has a Priority, Status and Type label.(See triaging old issues for more detail)
@SCdF is it a good time to revisit this?
@abbyad I don't think pouchdb-validation has been touched since we last tried to use it.
We could definitely take a look at making it work if we want to spend the time, though I do not think it's a high priority.
Not blocking for 4.0.0