cht-core icon indicating copy to clipboard operation
cht-core copied to clipboard

Run couch validations client side

Open garethbowen opened this issue 9 years ago • 19 comments

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.

garethbowen avatar Apr 20 '16 22:04 garethbowen

@abbyad please close or schedule before the end of this sprint. See triaging old issues.

medic-bot avatar Feb 15 '17 10:02 medic-bot

@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 avatar Feb 22 '17 04:02 abbyad

@abbyad It should be fairly straightforward - chuck it in!

garethbowen avatar Feb 22 '17 06:02 garethbowen

Added to current iteration, although I am not 100% sure you are not being sarcastic.

abbyad avatar Feb 23 '17 17:02 abbyad

I am never sarcastic.

garethbowen avatar Feb 23 '17 18:02 garethbowen

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.

SCdF avatar Mar 01 '17 11:03 SCdF

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.

SCdF avatar Mar 01 '17 12:03 SCdF

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":{}}

SCdF avatar Mar 07 '17 14:03 SCdF

I guess that does make sense, you are admin locally. It probably changes a bunch of our rules though.

SCdF avatar Mar 07 '17 14:03 SCdF

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

SCdF avatar Mar 08 '17 12:03 SCdF

Nice. One change requested. Back to you!

garethbowen avatar Mar 08 '17 22:03 garethbowen

Merged.

SCdF avatar Mar 09 '17 10:03 SCdF

AT: we should be validating documents on the client-side as much as we can (ie document structure stuff, not authority stuff).

SCdF avatar Mar 09 '17 10:03 SCdF

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.

SCdF avatar Mar 27 '17 13:03 SCdF

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.

SCdF avatar Mar 27 '17 13:03 SCdF

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)

medic-bot avatar May 23 '18 16:05 medic-bot

@SCdF is it a good time to revisit this?

abbyad avatar May 25 '18 21:05 abbyad

@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.

SCdF avatar May 29 '18 10:05 SCdF

Not blocking for 4.0.0

garethbowen avatar Mar 15 '22 17:03 garethbowen