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

Flexible format validations #360

Closed
czosel opened this issue Apr 8, 2019 · 3 comments · Fixed by #426
Closed

Flexible format validations #360

czosel opened this issue Apr 8, 2019 · 3 comments · Fixed by #426
Assignees
Labels
prio: high High priority
Projects

Comments

@czosel
Copy link
Contributor

czosel commented Apr 8, 2019

Form validations typically include format validations for fields things like emails, social security numbers, credit card and phone numbers, etc.

After discussing with @kaldras, we propose adding a new feature which functions similarly to #320 for this:

  • Add new extension point, e.g. format-validations.py (maybe find better name to avoid confusion with validations.py)
  • Add some pre-defined validations to caluma core for common stuff (e.g. email)
  • Add a new query to the API allFormatValidations which will be used in the form builder UI
  • Add a new field to formatValidation to TextQuestion, IntegerQuestion, FloatQuestion
  • Integrate new validations in form/validators.py
  • A format validation is defined by
    • a slug (e.g. email)
    • a name (translated for display in the form builder, e.g. E-Mail)
    • a definition of the actual validation rule. Open question: Would this be regex? Python and JS have different engines - I'm not sure how different they are in practice. A possible escape hatch would be (if the two engines are too different) to use node.js for the backend side.
@czosel
Copy link
Contributor Author

czosel commented Apr 8, 2019

/cc @winged Can you share some insights on the regex question?
/cc @open-dynaMIX

@winged
Copy link
Contributor

winged commented Apr 12, 2019

I like the idea, however I wouldn't use plain regex, but JEXL instead.

The data structure and API/query is a good idea. We could have some built-in validators (hmm regarding filename: validators.py, whaddya think?) and let the users extend it via extension points.

Then we'd have a bunch of JEXL validators available to the users via API. Those could be executed in frontend and in backend as well. Why would I chose JEXL instead of plain regex? Maybe you have a validation of a question in the context of another question, for example your chimney height must be in relation to the overall height of the roof etc.

What's also needed is a (localized) error message to be displayed in case the validation fails, along with the possibility to add multiple validators to a field.

So, we'd have, as a summary:

  • A global validations list, extendable via extension point
  • Questions can have multiple validators attached (combined via AND operator)
  • Validators consist of:
    • Slug / identifier
    • Name / description (localized)
    • JEXL implementation
    • Error message (localized, possibly with placeholders for the question's name)
  • The JEXL code in the validator should be able to access:
    • A regex match function
    • the answer's data
    • access to the other answers in the document (possibly even parent/neighbor documents in the tree)

@open-dynaMIX
Copy link
Member

open-dynaMIX commented May 3, 2019

Great idea 💡!

format_validations seems to me to be a good name for this feature.

When discussing this with @czosel, we decided to go with plain regex as a start and will switch to JEXL as the need arises.

EDIT: Or better call it format_validators.

open-dynaMIX added a commit to open-dynaMIX/caluma that referenced this issue May 6, 2019
This commit adds flexible format validators.

There is one new query: `all_format_validators` that enables querying
all available format validators.

A text- or textarea-question can have one or multiple format_validators
assigned.

When querying a question, there is a new `FormatValidatorsConnection`,
containing all FormatValidator-objects assigned on the question.

For this there is a new `QuestionValidator` that ensures, referenced
format_validators exist.

`translate_value()` has been moved to `core.utils`, as this is used in the
`data_source`- and `form`-app.

There is a new extension-point `format_validators.py`.

When adding the tests for this, it became obvious, that there was something
wrong with the parameters for `DataSource`. As I was touching those tests
anyway, I fixed this as well.

Added commented out extension volume to docker-compose.yml. Also added
forgotten data_sources extension volume.

Additionally this commit also cleans up the snapshots for document and
question as there were quite a lot old unused snapshots.

Closes projectcaluma#360
open-dynaMIX added a commit to open-dynaMIX/caluma that referenced this issue May 6, 2019
This commit adds flexible format validators.

There is one new query: `all_format_validators` that enables querying
all available format validators.

A text- or textarea-question can have one or multiple format_validators
assigned.

When querying a question, there is a new `FormatValidatorsConnection`,
containing all FormatValidator-objects assigned on the question.

For this there is a new `QuestionValidator` that ensures, referenced
format_validators exist.

`translate_value()` has been moved to `core.utils`, as this is used in the
`data_source`- and `form`-app.

There is a new extension-point `format_validators.py`.

When adding the tests for this, it became obvious, that there was something
wrong with the parameters for `DataSource`. As I was touching those tests
anyway, I fixed this as well.

Added commented out extension volume to docker-compose.yml. Also added
forgotten data_sources extension volume.

Additionally this commit also cleans up the snapshots for document and
question as there were quite a lot old unused snapshots.

Closes projectcaluma#360
open-dynaMIX added a commit to open-dynaMIX/caluma that referenced this issue May 6, 2019
This commit adds flexible format validators.

There is one new query: `all_format_validators` that enables querying
all available format validators.

A text- or textarea-question can have one or multiple format_validators
assigned.

When querying a question, there is a new `FormatValidatorsConnection`,
containing all FormatValidator-objects assigned on the question.

For this there is a new `QuestionValidator` that ensures, referenced
format_validators exist.

`translate_value()` has been moved to `core.utils`, as this is used in the
`data_source`- and `form`-app.

There is a new extension-point `format_validators.py`.

When adding the tests for this, it became obvious, that there was something
wrong with the parameters for `DataSource`. As I was touching those tests
anyway, I fixed this as well.

Added commented out extension volume to docker-compose.yml. Also added
forgotten data_sources extension volume.

Additionally this commit also cleans up the snapshots for document and
question as there were quite a lot old unused snapshots.

Closes projectcaluma#360
@open-dynaMIX open-dynaMIX self-assigned this May 6, 2019
open-dynaMIX added a commit to open-dynaMIX/caluma that referenced this issue May 8, 2019
This commit adds flexible format validators.

There is one new query: `all_format_validators` that enables querying
all available format validators.

A text- or textarea-question can have one or multiple format_validators
assigned.

When querying a question, there is a new `FormatValidatorsConnection`,
containing all FormatValidator-objects assigned on the question.

For this there is a new `QuestionValidator` that ensures, referenced
format_validators exist.

`translate_value()` has been moved to `core.utils`, as this is used in the
`data_source`- and `form`-app.

There is a new extension-point `format_validators.py`.

When adding the tests for this, it became obvious, that there was something
wrong with the parameters for `DataSource`. As I was touching those tests
anyway, I fixed this as well.

Added commented out extension volume to docker-compose.yml. Also added
forgotten data_sources extension volume.

Additionally this commit also cleans up the snapshots for document and
question as there were quite a lot old unused snapshots.

Closes projectcaluma#360
open-dynaMIX added a commit to open-dynaMIX/caluma that referenced this issue May 8, 2019
This commit adds flexible format validators.

There is one new query: `all_format_validators` that enables querying
all available format validators.

A text- or textarea-question can have one or multiple format_validators
assigned.

When querying a question, there is a new `FormatValidatorsConnection`,
containing all FormatValidator-objects assigned on the question.

For this there is a new `QuestionValidator` that ensures, referenced
format_validators exist.

`translate_value()` has been moved to `core.utils`, as this is used in the
`data_source`- and `form`-app.

There is a new extension-point `format_validators.py`.

When adding the tests for this, it became obvious, that there was something
wrong with the parameters for `DataSource`. As I was touching those tests
anyway, I fixed this as well.

Added commented out extension volume to docker-compose.yml. Also added
forgotten data_sources extension volume.

Additionally this commit also cleans up the snapshots for document and
question as there were quite a lot old unused snapshots.

Closes projectcaluma#360
Release May automation moved this from To do to Done May 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
prio: high High priority
Projects
No open projects
Release May
  
Done
Development

Successfully merging a pull request may close this issue.

3 participants