Sha256: 0bbe15d2a33d47ffb078f5ec022634f012df504c125116157090364fc558c970

Contents?: true

Size: 1.64 KB

Versions: 59

Compression:

Stored size: 1.64 KB

Contents

module Katello
  module Validators
    class ContentViewPuppetModuleValidator < ActiveModel::Validator
      def validate(record)
        if record.uuid.blank? && (record.name.blank? || record.author.blank?)
          record.errors[:base] << _("Invalid puppet module parameters specified. \
                                    Either 'uuid' or 'name' and 'author' must be specified.")
        elsif record.name && record.author &&
          !PuppetModule.exists?(name: record.name, author: record.author)
          record.errors[:base] << _("Puppet Module with name='%{name}' and author='%{author}' does\
                                    not exist") % { name: record.name, author: record.author }
        elsif record.uuid && !PuppetModule.exists?(uuid: record.uuid)
          record.errors[:base] << _("Puppet Module with uuid='%{uuid}' does not\
                                    exist") % { uuid: record.uuid }
        else
          puppet_modules = if record.uuid.blank?
                             PuppetModule.where(name: record.name, author: record.author)
                           else
                             PuppetModule.where(uuid: record.uuid)
                           end
          repositories = puppet_modules.flat_map(&:repositories)

          if repositories.present? && record.content_view.present? &&
              !repositories.map(&:organization).include?(record.content_view.organization)
            record.errors[:base] << _("Puppet Module does not belong to content view organization\
                                      '%{name}'" % { name: record.content_view.organization.name })
          end
        end
      end
    end
  end
end

Version data entries

59 entries across 59 versions & 1 rubygems

Version Path
katello-3.10.2 app/lib/katello/validators/content_view_puppet_module_validator.rb
katello-3.10.1.1 app/lib/katello/validators/content_view_puppet_module_validator.rb
katello-3.10.1 app/lib/katello/validators/content_view_puppet_module_validator.rb
katello-3.10.0 app/lib/katello/validators/content_view_puppet_module_validator.rb
katello-3.10.0.rc1.1 app/lib/katello/validators/content_view_puppet_module_validator.rb
katello-3.9.1 app/lib/katello/validators/content_view_puppet_module_validator.rb
katello-3.10.0.rc1 app/lib/katello/validators/content_view_puppet_module_validator.rb
katello-3.9.0 app/lib/katello/validators/content_view_puppet_module_validator.rb
katello-3.8.1 app/lib/katello/validators/content_view_puppet_module_validator.rb
katello-3.9.0.rc2 app/lib/katello/validators/content_view_puppet_module_validator.rb
katello-3.9.0.rc1 app/lib/katello/validators/content_view_puppet_module_validator.rb
katello-3.7.1.1 app/lib/katello/validators/content_view_puppet_module_validator.rb
katello-3.7.1 app/lib/katello/validators/content_view_puppet_module_validator.rb
katello-3.8.0 app/lib/katello/validators/content_view_puppet_module_validator.rb
katello-3.8.0.rc3 app/lib/katello/validators/content_view_puppet_module_validator.rb
katello-3.8.0.rc2 app/lib/katello/validators/content_view_puppet_module_validator.rb
katello-3.7.0 app/lib/katello/validators/content_view_puppet_module_validator.rb
katello-3.8.0.rc1 app/lib/katello/validators/content_view_puppet_module_validator.rb
katello-3.7.0.rc2 app/lib/katello/validators/content_view_puppet_module_validator.rb
katello-3.7.0.rc1 app/lib/katello/validators/content_view_puppet_module_validator.rb