Skip to content

Commit

Permalink
Fixes #37986, #37982 - Fix UI Error when importing templates
Browse files Browse the repository at this point in the history
Importing templates through UI causes an error and the page with import
results does not load.

Steps to Reproduce:

1. Have foreman instance with the templates plugin on nightly (error
originates in one of the newest commits so it is not on stream yet).

2. Navigate to Hosts > Templates > Sync Templates

3. Import templates from
https://github.com/theforeman/community-templates.git

Actual behavior:

The page with results does not load and two popups are displayed. One
saying that templates have been imported succesfully and another saying
that there has been an error.

Expected behavior:

Page with results loads normally and displays templates correctly.
  • Loading branch information
adamlazik1 committed Nov 6, 2024
1 parent aff0e8e commit afa684e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 1 addition & 3 deletions app/services/foreman_templates/parse_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ def to_h(verbose = false)
end

def errors
@template&.errors&.messages&.transform_values do |v|
v.join(', ')
end
@template&.errors&.messages || {}
end

def corrupted_metadata
Expand Down
10 changes: 5 additions & 5 deletions test/unit/template_importer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,15 @@ def audit_comment

template_res = find_result(results[:results], template.name)
refute template_res.imported
assert_equal template_res.errors[:base], "This template is locked. Please clone it to a new template to customize."
assert_equal template_res.errors[:base].first, "This template is locked. Please clone it to a new template to customize."

ptable_res = find_result(results[:results], ptable.name)
refute ptable_res.imported
assert_equal ptable_res.errors[:base], "This template is locked. Please clone it to a new template to customize."
assert_equal ptable_res.errors[:base].first, "This template is locked. Please clone it to a new template to customize."

snippet_res = find_result(results[:results], snippet.name)
refute snippet_res.imported
assert_equal snippet_res.errors[:base], "This template is locked. Please clone it to a new template to customize."
assert_equal snippet_res.errors[:base].first, "This template is locked. Please clone it to a new template to customize."

assert_equal @template_template, template.template
assert_equal @ptable_layout, ptable.layout
Expand Down Expand Up @@ -317,11 +317,11 @@ def keep_options_test_common(lock_setting)

template_res = find_result(results[:results], template.name)
refute template_res.imported
assert_equal template_res.errors[:base], "This template is locked. Please clone it to a new template to customize."
assert_equal template_res.errors[:base].first, "This template is locked. Please clone it to a new template to customize."

ptable_res = find_result(results[:results], ptable.name)
refute ptable_res.imported
assert_equal ptable_res.errors[:base], "This template is locked. Please clone it to a new template to customize."
assert_equal ptable_res.errors[:base].first, "This template is locked. Please clone it to a new template to customize."
results
end
end
Expand Down

0 comments on commit afa684e

Please sign in to comment.