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
Fix async validation in catalog form #5440
Conversation
* unresolved promises prevented ending of validation, so all promises all resolved
.then((json) => { | ||
if (json.resources.length > 0) { | ||
if (json.resources.length > 0 && json.resources[0].id !== id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the result is not first in the array? I think we should use Array.prototype.find
for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should not be more than one result, even if a user injects *
to the name of the catalog.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you 100% sure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With find
that code is almost unbreakable with [0]
a lot of things can go wrong in future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested the *
option on API and when you not put the query inside '
s it would not use *
as a regular expression.
However, if there is more than one result, it means there are two catalogs with the same name and the DB is already broken. 🗡️
But when I am thinking about it, a user could put the whole name into '
s but that seems as a hacky way to name a catalog. Should I take care about these cases? 😸
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would definitely use find
. Rest does not bother me much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok! I will also investigate how to properly escape special characters... e.g. %
in the name breaks it! 😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there should be some JS escaping tools. Using symbols like % is used for filtering etc in the MIQ API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it to
- it tries to find a catalog with the same name and different ID (no looking on the length of results)
- escaping only
%
to%25
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just small nitpick. Otherwise looks good. Its unfortunate we cannot throw away useless promises but thats worse than not being submit the form 😄 .
* name async validation checks if the name already exists but it did not check if the name exists on the same catalog -> now it checks id of the catalog with the same name and compares to its id
Checked commits rvsia/manageiq-ui-classic@c113510~...18cf9a7 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restarted travis(ruby timed out). LGTM
Services > Catalogs > Catalogs > Configuration > New/Edit
Description
@miq-bot add_label hammer/no, services, react
@miq-bot add_reviewer @Hyperkid123