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

Refactor: resources validators #138

Merged
merged 13 commits into from
Aug 28, 2023

Conversation

syphax-bouazzouni
Copy link

@syphax-bouazzouni syphax-bouazzouni commented Feb 28, 2023

Context

See agroportal/project-management#339

Changes

  • Add unit tests for all our validators (8cfd2f7)

  • Add an abstraction to define validators (85ca3a5)

  • Implement it for Data types (String, URI, Integer, Float, DateTime, Float, and list)(56adaf6)

    • In addition, now we enforce the validity of URIs according to RFC3987 (for example test or 'test/test' will no more be valid)
  • Implement it for uniqueness validator (cd67a52)

    • In addition, Fixed a small bug to force the id regeneration when we update a related attribute (named_with) used in the existent? test (6091f1a and a998a4e)
  • implement if for existence validator (27fffc1)

    • In addition, now existence will not allow empty strings, arrays ([]) and URIs
  • Implement if for Object types (887653c)

  • Implement it for range validator (9227510)

    • In addition, now it works also for Integers and Float (e.g enforce: [:min_2, :max_5] will enforce the value to be in that range)
  • Refactor the enforce module, to be more succinct (by extracting reusable sections)(2d1457d)

@mdorf mdorf merged commit aef5ea0 into ncbo:master Aug 28, 2023
@mdorf
Copy link
Member

mdorf commented Aug 28, 2023

merging this and #139

@syphax-bouazzouni
Copy link
Author

Hi @mdorf,

Thanks, for merging all the PRs.

Just for your information, this PR changes the behavior of the URI validator making it more strict.

Before a URI is valid if the value is of type RDF::URI, accepting empty strings and no valid URLs.
In code https://github.com/ncbo/goo/pull/139/files#diff-21b88d41e9a52d2abff6aa87b7a62ae9b99899519335b9c99bf80aecb28225e7L79

Now a URI is valid if it is a valid URL, not empty and valid
https://github.com/ncbo/goo/pull/139/files#diff-3c03f02f895eed549d9f0dde4c5b5e23bc258b36dc975ef53b201dacf045c4caR70

So you need to take a particular look if you don't have this sort of erroneous data (empty strings and no valid URLs) in Bioportal and fix them manually using NCBO cron.
But like for now you don't really use metadata properties, the easiest is to disable that for you code.
By updating this line https://github.com/ncbo/goo/pull/138/files#diff-3c03f02f895eed549d9f0dde4c5b5e23bc258b36dc975ef53b201dacf045c4caR50,
from

 value.is_a?(RDF::URI) && value.valid?

to

 value.is_a?(RDF::URI)

@alexskr
Copy link
Member

alexskr commented Aug 29, 2023

lets see if this this will address ncbo/bioportal_web_ui#57

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants