Overriding parameters causes them to go blank in Foreman 3.0 / Katello 4.2

Problem:
When provisioning a new host, if you override more than one parameter, the previous parameter that you override clears the “Name” and “Value” fields

Expected outcome:
Previous version brought down all fields no matter how many parameters were chosen.

Foreman and Proxy versions:
Foreman 3.0.1-1
Katello 4.2.1
Foreman and Proxy plugin versions:
foreman-tasks 5.1.1
foreman_chef 0.10.0
foreman_discovery 18.0.5
foreman_docker 5.0.0
foreman_puppet 1.0.5
foreman_remote_execution 4.8.0
katello 4.2.1
Distribution and version:
CentOS Linux release 7.9.2009 (Core)
Other relevant data:

1 Like

This is still an issue in Foreman 3.1 and Katello 4.3

Hey @tbrooks, sorry we missed this.
I think that this looks related to: Foreman UI: propably bug in js in 3.2.0

Thank you for your reply. I see that the change is suppose to be made to:

app/assets/javascripts/parameter_override.js

However, I’m not able to find this file.

The only file I’m able to find that’s even similar to this is:

/var/lib/foreman/public/assets/parameter_override-dc08f9cc7cfa8b58a45c3ef5ac16cfaed80b2f07cc21afa7ac7595aa42cad173.js

which doesn’t match.

Could you please advise where to make this edit?

Hey @tbrooks !
Yes that should be it, I guess that in production environments rails adds that asset suffix.

Maybe the file is minified? Not sure if it’s gonna work, but can you try to copy paste the content of this file from the Foreman 3.0-stable?

I will also try to cherry pick the fix to older branches.

I also see this in /var/lib/foreman/public/assets/
parameter_override-dc08f9cc7cfa8b58a45c3ef5ac16cfaed80b2f07cc21afa7ac7595aa42cad173.js
parameter_override-dc08f9cc7cfa8b58a45c3ef5ac16cfaed80b2f07cc21afa7ac7595aa42cad173.js.gz

So, is the gz file what you mean by minified?

The format of the .js is not quite what I saw in the fix. It’s a single line:

function override_param(a){var e=$(a).closest("tr").addClass("override-param"),d=e.find("[id^=name_]").text(),i=e.find("[id^=parameter_type_]").text(),r=e.find("[id^=value_]"),n=r.val();$("#parameters").find(".btn-primary").click();var t=$("#parameters").find(".fields").last();if(t.find("[id$=_name]").val(d),t.find("[id$=_parameter_type]").val(i),t.find("[id$=_value]").val(n==r.data("hidden-value")?"":n),r.hasClass("masked-input")){var l=t.find("span.fa-eye-slash").closest("a"),s=t.find(".set_hidden_value");s.prop("checked",!0),s.val("1"),l.click()}}

The .gz is minified and also compressed,
Pasting the code with the fix in the .js should do the trick

Hi @Ron_Lavi,

I was hoping for the best. I added the following into the .js file and restarted foreman, but it’s still blanking when selecting to override.

function override_param(item) {
  var param = $(item)
    .closest('tr')
    .addClass('override-param');
  var n = param.find('[id^=name_]').text();
  var parameter_type_val = param.find('[id^=parameter_type_]').text();
  var param_value = param.find('[id^=value_]');
  var v = param_value.val();
  
  var addParameterButton = $('#parameters').find('.btn-primary');
  addParameterButton.click();
  var directionOfAddedItems = addParameterButton.attr('direction');
  var new_param = $('#parameters').find('.fields');
  if(directionOfAddedItems === 'append'){
    new_param = new_param.last();
  } else {
    new_param = new_param.first();
  }
  new_param.find('[id$=_name]').val(n);
  new_param.find('[id$=_parameter_type]').val(parameter_type_val);
  new_param
    .find('[id$=_value]')
    .val(v == param_value.data('hidden-value') ? '' : v);
  if (param_value.hasClass('masked-input')) {
    var alink = new_param.find('span.fa-eye-slash').closest('a'),
      hiddenValueCheckBox = new_param.find('.set_hidden_value');
    hiddenValueCheckBox.prop('checked', true);
    hiddenValueCheckBox.val('1');
    alink.click();
  }
}

Can you place some console.log() or debugger to see if the file is actually called?

Adding @evgeni @ares who might know better than me how it works in production…

WIthout recompiling the whole thing? No idea.

Has this fix been incorporated into Foreman 3.2 and Katello 4.4?

Not yet, no

Opened cherry-pick into 3.2-stable: [CP 3.2] Fixes #34747 - override_param should consider direction by Ron-Lavi · Pull Request #9196 · theforeman/foreman · GitHub

1 Like