From: Tomas Sedovic<tomas(a)sedovic.cz>
https://bugzilla.redhat.com/show_bug.cgi?id=761218
When a template name wasn't specified in the UI but was in the uploaded
template, we still weren't showing it on the Overview screen.
---
src/app/controllers/images_controller.rb | 24 +++++++-----------------
src/app/models/template_xml.rb | 5 +++--
2 files changed, 10 insertions(+), 19 deletions(-)
diff --git a/src/app/controllers/images_controller.rb
b/src/app/controllers/images_controller.rb
index a178596..66acd6d 100644
--- a/src/app/controllers/images_controller.rb
+++ b/src/app/controllers/images_controller.rb
@@ -102,7 +102,7 @@ class ImagesController< ApplicationController
url = params[:image_url]
begin
xml_source = RestClient.get(url, :accept => :xml)
- rescue RestClient::Exception, SocketError, URI::InvalidURIError
+ rescue RestClient::Exception, SocketError, URI::InvalidURIError,
Errno::ECONNREFUSED
flash.now[:error] = t('images.flash.error.invalid_url')
render :new and return
end
@@ -116,7 +116,8 @@ class ImagesController< ApplicationController
rescue Nokogiri::XML::SyntaxError
errors = [t('template_xml.errors.xml_parse_error')]
else
- doc.name = @name
+ doc.name = @name unless @name.blank?
+ @name = doc.name
@xml = doc.to_xml
errors = doc.validate
end
@@ -134,10 +135,13 @@ class ImagesController< ApplicationController
@name = params[:name]
@xml = params[:image_xml]
- errors = TemplateXML.validate(@xml)
+ doc = TemplateXML.new(@xml)
+ errors = doc.validate
if errors.any?
flash.now[:error] = errors
render :edit_xml and return
+ else
+ @name = doc.name
end
end
@@ -205,20 +209,6 @@ class ImagesController< ApplicationController
end
protected
- def add_template_name(doc, name)
- return unless doc
-
- if doc.root.nil? || doc.root.name != 'template'
- doc.root = doc.create_element('template')
- end
-
- if doc.xpath('/template/name').empty?
- doc.xpath('/template').first<< doc.create_element('name')
- end
-
- doc.xpath('/template/name').first.content = name unless name.blank?
- end
-
def load_target_images(build)
@target_images_by_target = {}
return unless build
diff --git a/src/app/models/template_xml.rb b/src/app/models/template_xml.rb
index 149c9c5..323b4e0 100644
--- a/src/app/models/template_xml.rb
+++ b/src/app/models/template_xml.rb
@@ -53,11 +53,12 @@ class TemplateXML
@xml.xpath('/template').first<<
@xml.create_element('name')
end
- @xml.xpath('/template/name').first.content = name unless name.blank?
+ name ||= ""
+ @xml.xpath('/template/name').first.content = name
end
def name
- doc.xpath('/template/name').text
+ @xml.xpath('/template/name').text
end
def to_xml