-
-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run couch validations client side #2222
Comments
@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. |
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.
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: #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 {"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 {"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. |
The fn on medic-client contains validations around document structure, which can be usefully run in PouchDB (ie on the client side). The fn on medic contains authority checks, which can only be run in Couchdb, since Pouchdb doesn't have that kind of information.
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 |
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.
The text was updated successfully, but these errors were encountered: