Skip to content
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

Open
garethbowen opened this issue Apr 20, 2016 · 19 comments
Open

Run couch validations client side #2222

garethbowen opened this issue Apr 20, 2016 · 19 comments
Labels
Priority: 3 - Low Can be bumped from the release Type: Improvement Make something better

Comments

@garethbowen
Copy link
Member

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 garethbowen added the Type: Feature Add something new label Apr 20, 2016
@medic-bot
Copy link

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

@SCdF SCdF added the Status: Blocked waiting for triage Blocked waiting for prioritisation label Feb 15, 2017
@abbyad
Copy link
Contributor

abbyad commented Feb 22, 2017

@garethbowen is this something that you think we need to implement now, or add to our feature request or tech debt lists for prioritization?

@garethbowen
Copy link
Member Author

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

@abbyad abbyad added this to the February 14th - February 28th milestone Feb 23, 2017
@abbyad abbyad removed the Status: Blocked waiting for triage Blocked waiting for prioritisation label Feb 23, 2017
@abbyad abbyad removed their assignment Feb 23, 2017
@abbyad
Copy link
Contributor

abbyad commented Feb 23, 2017

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

@garethbowen
Copy link
Member Author

I am never sarcastic.

@SCdF
Copy link
Contributor

SCdF commented Mar 1, 2017

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 added a commit that referenced this issue Mar 1, 2017
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
Copy link
Contributor

SCdF commented Mar 1, 2017

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.

@SCdF SCdF assigned SCdF and unassigned SCdF Mar 1, 2017
SCdF added a commit that referenced this issue Mar 7, 2017
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
Copy link
Contributor

SCdF commented Mar 7, 2017

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
Copy link
Contributor

SCdF commented Mar 7, 2017

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

SCdF added a commit that referenced this issue Mar 7, 2017
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.
@SCdF
Copy link
Contributor

SCdF commented Mar 9, 2017

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

@SCdF
Copy link
Contributor

SCdF commented Mar 27, 2017

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 SCdF reopened this Mar 27, 2017
@SCdF
Copy link
Contributor

SCdF commented Mar 27, 2017

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.

@garethbowen garethbowen removed this from the February 28th - March 14th milestone Mar 28, 2017
@garethbowen garethbowen added Type: Improvement Make something better and removed Type: Feature Add something new labels Oct 24, 2017
@medic-bot medic-bot added the Status: Blocked waiting for triage Blocked waiting for prioritisation label May 23, 2018
@medic-bot
Copy link

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)

@abbyad
Copy link
Contributor

abbyad commented May 25, 2018

@SCdF is it a good time to revisit this?

@abbyad abbyad assigned SCdF and unassigned abbyad May 25, 2018
@SCdF
Copy link
Contributor

SCdF commented May 29, 2018

@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 SCdF removed their assignment May 29, 2018
@SCdF SCdF added Priority: 3 - Low Can be bumped from the release and removed Status: Blocked waiting for triage Blocked waiting for prioritisation labels May 29, 2018
@abbyad abbyad added this to the 4.0.0 milestone May 18, 2021
@garethbowen
Copy link
Member Author

Not blocking for 4.0.0

@garethbowen garethbowen removed this from the 4.0.0 milestone Mar 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: 3 - Low Can be bumped from the release Type: Improvement Make something better
Projects
None yet
Development

No branches or pull requests

4 participants