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
Fixes #4127 - Global Parameters with types #5241
Fixes #4127 - Global Parameters with types #5241
Conversation
Issues: #4127 |
end | ||
|
||
def down | ||
remove_column :parameters, :key_type |
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.
Trailing whitespace detected.
return if !self.value.is_a?(String) || value.contains_erb? | ||
Foreman::Parameters::Caster.new(self, :attribute_name => :value, :to => object_for_key_type.key_type).cast! | ||
rescue StandardError, SyntaxError => e | ||
Foreman::Logging.exception("Error while parsing #{object_for_key_type}", e) |
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.
Use 2 (not 4) spaces for indentation.
@@ -0,0 +1,12 @@ | |||
module KeyValueValidation | |||
extend ActiveSupport::Concern | |||
|
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.
Trailing whitespace detected.
app/helpers/key_types_helper.rb
Outdated
"<dt>JSON</dt> <dd>Any valid JSON input.</dd>" + | ||
"</dl>").html_safe, | ||
:label_help_options => { :title => _("How values are validated") }} | ||
|
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.
Trailing whitespace detected.
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.
Thanks for doing this, it makes the input so much better!
I know its WIP but I guess there are API changes needed?
@@ -0,0 +1,9 @@ | |||
class AddKeyTypeToParameters < ActiveRecord::Migration | |||
def up | |||
add_column :parameters, :key_type, :string, :default => N_("string"), :limit => 255 |
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'm not sure N_("string")
should be marked for translation?
@@ -0,0 +1,20 @@ | |||
module KeyType | |||
extend ActiveSupport::Concern | |||
KEY_TYPES = [N_("string"), N_("boolean"), N_("integer"), N_("real"), N_("array"), N_("hash"), N_("yaml"), N_("json")] |
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.
It would be nice to avoid storing them here and in the lookup_key model.
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.
It looks like they are in a comment in the lookup_key model already, it should probably be removed altogether to avoid confusion.
@@ -0,0 +1,20 @@ | |||
module KeyType | |||
extend ActiveSupport::Concern | |||
KEY_TYPES = [N_("string"), N_("boolean"), N_("integer"), N_("real"), N_("array"), N_("hash"), N_("yaml"), N_("json")] |
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.
It looks like they are in a comment in the lookup_key model already, it should probably be removed altogether to avoid confusion.
@@ -56,6 +61,10 @@ def self.type_priority(type) | |||
PRIORITY.fetch(type.to_s.underscore.to_sym, nil) unless type.nil? | |||
end | |||
|
|||
def value_before_type_cast |
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.
Not sure you need this, in KeyValueValidation
the value_before_type_cast
can run with no parameters and then it will work on self.value which is what you are sending.
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.
the naming here is confusing, what's the difference between value_before_type_casting and value_before_type_cast? it looks like this only returns early if error is present
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.
Actually, previously we have used method value_before_type_cast
as custom method in lookup_key but if I am correct 'ActiveModelalso provides
*_before_type_cast(here * -> attribute_name) methods so modified it and declared
value_before_type_casting as our custom method used by
lookup_keyto check casting by passing the
value` .
Any other suggestion on method name for value_before_type_casting?
EDIT - modified method name from value_before_type_casting to format_value_before_type_cast
<label class="control-label col-md-2" for="common_parameter_value"><%= _("Value") %></label> | ||
|
||
<div class="col-md-9"> | ||
<div class="editor-container"> |
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.
Maybe we can consult @amirfefer or @sharvit on how to allow the editor when in full screen mode?
Or @Rohoover could suggest another editor.
Background for this: we are using the ACE editor but when adding a type and making parameters look more like smart class parameters we need to show validations next to the editor and using the ACE would not look so good.
There was an attempt at some point to only show the ACE editor when entering full screen for easy editing but that failed.
Perhaps with the use of react this is now possible?
It will probably need to be in a separate PR.
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.
@orrabin
Is there are screenshot or visual you can show me?
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.
Please check below screenshots for your reference.
-
web-ui after my change where I have removed existing editor and added key type dropdown. I found that for other parameters pages, we haven't used any editor except this page.
app/helpers/key_types_helper.rb
Outdated
def param_type_selector(f, options = {}) | ||
common_extra_options = { :size => "col-md-4", :class=> "without_select2", | ||
:label_help => _("<dl>" + | ||
"<dt>String</dt> <dd>Everything is taken as a string.</dd>" + |
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 know you didn't write it and just moved it but maybe now is a good time to change the wording in this comment a little.
@@ -0,0 +1,9 @@ | |||
class AddKeyTypeToParameters < ActiveRecord::Migration |
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 get this error when trying to run the migrations:
StandardError: Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release the migration was written for:
class AddKeyTypeToParameters < ActiveRecord::Migration[4.2]
The validations works nicely and the migration looks correct. The hidden value checkbox is not working with the change, the js there probably searches for the editor and needs to be updated. |
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 I understand. Would it be possible to put the same expand button you have on the Smart Class Parameters page on the Global Parameters page next to Value box. This would seem like a consistent handling.
I hope I understood the issue properly.
@Rohoover yes I meant adding the expand button and checking if when expanding we could get the editor.
|
I would be really happy to see this PR in foreman as it would help us to configure foreman_ansible roles which require hash values like https://github.com/bennojoy/nginx How to proceed to get it in? |
@sbernhard, |
5bbd666
to
f4ba49a
Compare
return if !self.value.is_a?(String) || value.contains_erb? | ||
Foreman::Parameters::Caster.new(self, :attribute_name => :value, :to => object_for_key_type.key_type).cast! | ||
rescue StandardError, SyntaxError => e | ||
Foreman::Logging.exception("Error while parsing #{object_for_key_type}", e) |
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.
Layout/IndentationWidth: Use 2 (not 4) spaces for indentation.
f4ba49a
to
be7e1c0
Compare
be7e1c0
to
c48adb3
Compare
@orrabin, @sean797 and @sbernhard, Apologize for delay in delivery of these changes!
@Rohoover, |
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 a bit picky here but can we get the input field to match the height of the expand button for the edit page?
@kgaikwad, what is the status here? |
@ares, thank you for review. I have addressed almost all comments except migration change. EDIT - updated PR with the suggested modifications. |
f2cc385
to
88f8143
Compare
spoke with Ori, she's fine with dismissing, the review is out of date
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.
It's ready from code perspective, there are 2 tests failing now that needs to be fixed. It seems escaping has changed.
Also I found one little issue, the value in parameter form does seems to have smaller height than it should. It's not aligned with fullscreen button. Should be tiny css fix I hope. See screenshot
After this is fixed, I'm happy to click the green button. I'm looking forward to this a lot :-)
88f8143
to
45710dd
Compare
45710dd
to
6922d3d
Compare
6922d3d
to
b89b8cb
Compare
@ares, |
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.
Thanks @kgaikwad, I retested and confirmed it still works smoothly. I'm very happy to click the merge button, great work!
@@ -65,7 +65,7 @@ module Search | |||
|
|||
scoped_search :relation => :puppetclasses, :on => :name, :complete_value => true, :rename => :class, :only_explicit => true, :operators => ['= ', '~ '], :ext_method => :search_by_puppetclass | |||
scoped_search :relation => :fact_values, :on => :value, :in_key => :fact_names, :on_key => :name, :rename => :facts, :complete_value => true, :only_explicit => true, :ext_method => :search_cast_facts | |||
scoped_search :relation => :search_parameters, :on => :value, :on_key => :name, :complete_value => true, :rename => :params, :ext_method => :search_by_params, :only_explicit => true |
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 know, I'm late to the party. But where did this go?
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.
As value field is now converted to serialized one searching is not working as expected.
I tried using to_yaml
but won't able to cover all scenarios and for smart_class_parameters, I don't find searching with value field.
One of suggestion given by @ekohl is to have searchable field separately and value with yaml.
After this discussion, I have removed searching parameters using value field and added searching based on name.
What is your thoughts on 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.
I believe we (dm) use search by parameters in some automation via API requests. We (foreman) promise that the APIv2 is stable and I believe part of the promise is keeping the search stable.
I think the least we should do is add this to the manual in the upgrade notes.
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.
can't we keep the current behavior ? this will continue to work with strings as it was prior to the change?
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 the search syntax can't be considered as part of the API. While we should try to do as little breaking changes as possible, but sometimes it does not make sense. From time to time we realize it's better to rename the search keyword for a given attribute or change the :only_explicit definition or drop some operators for some attribute and it was always accepted.
Now for the suggestion, if we allow fulltext searching, it could work in some cases. But it can also start returning weird results or simply feel buggy. People will ask for adding more operators in order to search in nested keys etc. I think it's better to just drop this and don't make people confused. I believe it's clear to all devs, how the search would behave, but it would be quite surprising for users who don't understand how we store data in SQL and how scoped search syntax translates to it.
Also given it doesn't work on smart class parameters and smart variables, I don't think it will hit majority of users. If you strongly believe we should add full text searching back, I'd prefer if we first add some inline help about how the search works and especially in this particular search field.
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 the search syntax can't be considered as part of the API.
I think the search syntax is a valid part of the API, we even use it for permissions. As I said, the least we should do is document the changes so users don't get surprises when they upgrade.
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.
So here's the documentation - theforeman/theforeman.org#1322
Given the fact ale least two people feel differently about that, we should probably bring that up to discourse or document the outcome in our manual. At the end I don't mind steering any direction, but we should set the expectations for users. I didn't find any mention at https://theforeman.org/manuals/1.20/index.html#4.1.5Searching (or in API section linked from here)
No description provided.