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

Fixes #37986, #37982 - Fix UI Error when importing templates #192

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions app/services/foreman_templates/parse_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def to_h(verbose = false)
:additional_errors => @additional_errors,
:additional_info => @additional_info,
:exception => @exception&.message,
:validation_errors => errors,
:validation_errors => transformed_errors,
:file => @template_file,
:type => @template.present? ? @template.class.name.underscore : nil
}
Expand All @@ -27,9 +27,7 @@ def to_h(verbose = false)
end

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

def corrupted_metadata
Expand Down Expand Up @@ -99,5 +97,13 @@ def calculate_diff(old, new)
nil
end
end

private

def transformed_errors
return {} unless errors

errors.to_hash.transform_values(&:last)
end
end
end
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.full_messages.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.full_messages.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.full_messages.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.full_messages.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.full_messages.first, "This template is locked. Please clone it to a new template to customize."
results
end
end
Expand Down