Skip to content

Commit

Permalink
[webui] Add understandable flash message in Kiwi
Browse files Browse the repository at this point in the history
We added a more understandable error message in the Kiwi Editor and also
in the file view when the importation has a failure due to an invalid
kiwi file.
  • Loading branch information
David Kang committed Oct 11, 2017
1 parent 9fe3eb3 commit e1c8d38
Show file tree
Hide file tree
Showing 20 changed files with 420 additions and 3,563 deletions.
6 changes: 3 additions & 3 deletions src/api/app/controllers/webui/kiwi/images_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def import_from_package
if package.kiwi_image.blank? || package.kiwi_image.destroyed?
package.kiwi_image = ::Kiwi::Image.build_from_xml(package.source_file(kiwi_file), package.kiwi_file_md5)
unless package.save
errors = ["Kiwi File '#{kiwi_file}' has errors:", package.kiwi_image.errors.full_messages].join('<br />')
errors = ["Kiwi File '#{kiwi_file}' has errors:", package.kiwi_image.errors.messages.map { |_key, value| value }].join('<br/>')
redirect_to package_view_file_path(project: package.project, package: package, filename: kiwi_file), error: errors
return
end
Expand All @@ -45,8 +45,8 @@ def update
@image.write_to_backend
end
redirect_to action: :show
rescue ActiveRecord::RecordInvalid, Timeout::Error => e
flash.now[:error] = "Cannot update kiwi image: #{@image.errors.full_messages.to_sentence} #{e.message}"
rescue ActiveRecord::RecordInvalid, Timeout::Error
flash.now[:error] = ['Cannot update kiwi image:', @image.errors.messages.map { |_key, value| value }].join('<br/>')
@package_groups = @image.package_groups.select(&:kiwi_type_image?).first
render action: :show
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/kiwi/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Kiwi::Package < ApplicationRecord
belongs_to :package_group
has_one :kiwi_image, through: :package_groups

validates :name, presence: true
validates :name, presence: { message: 'Package name can\'t be blank'}

def to_h
hash = { name: name }
Expand Down
17 changes: 9 additions & 8 deletions src/api/app/models/kiwi/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ class Kiwi::Repository < ApplicationRecord
#### Scopes (first the default_scope macro if is used)

#### Validations macros
validates :alias, :source_path, uniqueness: { scope: :image }
validates :source_path, presence: true
validates :alias, :source_path, uniqueness: { scope: :image, message: "%{attribute} '%{value}' has already been taken."}
validates :source_path, presence: { message: '%{attribute} can\'t be nil.'}
validate :source_path_format
validates :priority, numericality: { only_integer: true, allow_nil: true, greater_than_or_equal_to: 0, less_than: 100 }
validates :priority, numericality: { only_integer: true, allow_nil: true, greater_than_or_equal_to: 0,
less_than: 100, message: '%{attribute} must be between 0 and 99.' }
validates :order, numericality: { only_integer: true, greater_than_or_equal_to: 1 }
# TODO: repo_type value depends on packagemanager element
# https://doc.opensuse.org/projects/kiwi/doc/#sec.description.repository
validates :repo_type, inclusion: { in: REPO_TYPES }
validates :replaceable, inclusion: { in: [true, false] }
validates :imageinclude, :prefer_license, inclusion: { in: [true, false] }, allow_nil: true
validates :repo_type, inclusion: { in: REPO_TYPES, message: "%{attribute} '%{value}' is not included in the list." }
validates :replaceable, inclusion: { in: [true, false], message: "%{attribute} has to be 'true' or 'false'" }
validates :imageinclude, :prefer_license, inclusion: { in: [true, false], message: "%{attribute} has to be 'true' or 'false'" }, allow_nil: true
validates_associated :image, on: :update

#### Class methods using self. (public and then private)
Expand All @@ -47,10 +48,10 @@ def source_path_format
return if source_path =~ /\A#{URI.regexp(['ftp', 'http', 'https', 'plain'])}\z/
if source_path_for_obs_repository?
return if repo_type == 'rpm-md'
errors.add(:repo_type, "should be 'rpm-md' for obs:// repositories")
errors.add(:repo_type, "Repo type for '#{source_path}' should be 'rpm-md' for obs:// repositories.")
end
return if source_path_for_opensuse_repository?
errors.add(:source_path, "has an invalid format")
errors.add(:source_path, "Source path '#{source_path}' has an invalid format.")
end

def to_xml
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e1c8d38

Please sign in to comment.