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 #37852 - Support Rails 7.0 #11155

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
plugin: katello
postgresql_container: ghcr.io/theforeman/postgresql-evr
test_existing_database: false
foreman_version: develop # set to the Foreman release branch after branching :)
foreman_version: refs/pull/10299/head # set to the Foreman release branch after branching :)

angular:
name: Angular ${{ matrix.engine }} - NodeJS ${{ matrix.node }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def create
host.reload
::Katello::Host::SubscriptionFacet.update_facts(host, rhsm_params[:facts]) unless rhsm_params[:facts].blank?

respond_for_show(:resource => host, :template => '../../../api/v2/hosts/show')
respond_for_show(:resource => host, :full_template => 'katello/api/v2/hosts/show')
end

def params_to_rhsm_params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def release_version
param_group :bulk_params
def traces
collection = scoped_search(Katello::HostTracer.where(host_id: @hosts.pluck(:id)), 'application', 'desc', resource_class: Katello::HostTracer)
respond_for_index(:collection => collection, :template => '../../../api/v2/host_tracer/index')
respond_for_index(:collection => collection, :full_template => 'katello/api/v2/host_tracer/index')
end

api :PUT, "/hosts/bulk/resolve_traces", N_("Resolve traces for one or more hosts")
Expand Down Expand Up @@ -255,7 +255,7 @@ def module_streams
options[:resource_class] = Katello::ModuleStream
host_module_streams = Katello::ModuleStream.available_for_hosts(@hosts)
respond_for_index(collection: scoped_search(host_module_streams, :name, :asc, options),
template: '../../../api/v2/module_streams/name_streams')
full_template: 'katello/api/v2/module_streams/name_streams')
end

api :PUT, "/hosts/bulk/change_content_source", N_("Update the content source for specified hosts and generate the reconfiguration script")
Expand Down
3 changes: 2 additions & 1 deletion app/lib/katello/api/v2/rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ def respond_for_bulk_async(options = {})
def respond_with_template(action, resource_name, options = {}, &_block)
yield if block_given?
status = options[:status] || 200
template = options[:full_template] || "katello/api/v2/#{resource_name}/#{action}"

render :template => "katello/api/v2/#{resource_name}/#{action}",
render :template => template,
:status => status,
:locals => options.slice(:object_name, :root_name, :locals),
:layout => "katello/api/v2/layouts/#{options[:layout]}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ def validate_each(record, attribute, value)
case attribute
when :base_url
unless AlternateContentSourcePathValidator.validate_base_url(value)
record.errors[attribute] << N_("%s is not a valid path") % value
record.errors.add(attribute, N_("%s is not a valid path") % value)
end
when :subpaths
unless AlternateContentSourcePathValidator.validate_subpaths(value)
record.errors[attribute] << N_('All subpaths must have a slash at the end and none at the front')
record.errors.add(attribute, N_('All subpaths must have a slash at the end and none at the front'))
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Validators
class ContainerImageNameValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
if value && !ContainerImageNameValidator.validate_name(value)
record.errors[attribute] << N_("invalid container image name")
record.errors.add(attribute, N_("invalid container image name"))
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/lib/katello/validators/content_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class ContentValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
value.encode("UTF-8", 'binary') unless value.blank?
rescue Encoding::UndefinedConversionError
record.errors[attribute] << (options[:message] || _("cannot be a binary file."))
record.errors.add(attribute, (options[:message] || _("cannot be a binary file.")))
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def validate(record)
env = KTEnvironment.where(:id => environment_id).first
return if view.blank? || env.blank?
if view.default? && !env.library?
record.errors[:base] << _("Lifecycle environment '%{env}' cannot be used with content view '%{view}'") %
{:view => view.name, :env => env.name}
record.errors.add(:base, _("Lifecycle environment '%{env}' cannot be used with content view '%{view}'") %
{:view => view.name, :env => env.name})
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ def validate(record)
view = ContentView.where(:id => record.content_view_id).first
environment = KTEnvironment.where(:id => environment_id).first
if view.blank? || environment.blank?
record.errors[:base] << _("Content view environments must have both a content view and an environment")
record.errors.add(:base, _("Content view environments must have both a content view and an environment"))
end

unless view&.organization == environment&.organization
record.errors[:base] << _("%{view_label} could not be promoted to %{environment_label} because the content view and the environment are not in the same organization!") % {:view_label => view&.label, :environment_label => environment&.label}
record.errors.add(:base, _("%{view_label} could not be promoted to %{environment_label} because the content view and the environment are not in the same organization!") % {:view_label => view&.label, :environment_label => environment&.label})
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ def validate(record)
if environment_id
env = KTEnvironment.where(:id => environment_id).first
unless view.blank? || env.blank? || view.in_environment?(env)
record.errors[:base] << _("Content view '%{view}' is not in environment '%{env}'") %
{:view => view.name, :env => env.name}
record.errors.add(:base, _("Content view '%{view}' is not in environment '%{env}'") %
{:view => view.name, :env => env.name})
end
end
if view&.generated_for_repository?
record.errors[:base] << _("Generated content views cannot be assigned to hosts or activation keys")
record.errors.add(:base, _("Generated content views cannot be assigned to hosts or activation keys"))
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def validate(record)
if record.errata_id.blank? && record.start_date.blank? && record.end_date.blank? && record.types.blank?
invalid_parameters = _("Invalid erratum filter rule specified, Must specify at least one of the following:" \
" 'errata_id', 'start_date', 'end_date' or 'types'")
record.errors[:base] << invalid_parameters
record.errors.add(:base, invalid_parameters)
return
end

Expand All @@ -14,7 +14,7 @@ def validate(record)
!record.types.blank?)
invalid_parameters = _("Invalid erratum filter rule specified, 'errata_id' cannot be specified in the" \
" same tuple as 'start_date', 'end_date' or 'types'")
record.errors[:base] << invalid_parameters
record.errors.add(:base, invalid_parameters)
return
end

Expand All @@ -28,13 +28,13 @@ def _check_single_date_range(record)
if !record.filter.erratum_rules.empty? &&
!record.filter.erratum_rules.any? { |rule| rule.id == record.id }
invalid_parameters = _("May not add a type or date range rule to a filter that has existing rules.")
record.errors[:base] << invalid_parameters
record.errors.add(:base, invalid_parameters)
end

else
if record.filter_has_date_or_type_rule?
invalid_parameters = _("May not add an id rule to a filter that has an existing type or date range rule.")
record.errors[:base] << invalid_parameters
record.errors.add(:base, invalid_parameters)
end

end
Expand All @@ -45,28 +45,28 @@ def _check_date_range(record)
end_date_int = record.end_date.to_time.to_i unless record.end_date.blank?

if start_date_int && (!start_date_int.is_a?(Integer) || !record.start_date.is_a?(String))
record.errors[:base] << _("The erratum filter rule start date is in an invalid format or type.")
record.errors.add(:base, _("The erratum filter rule start date is in an invalid format or type."))
end
if end_date_int && (!end_date_int.is_a?(Integer) || !record.end_date.is_a?(String))
record.errors[:base] << _("The erratum filter rule end date is in an invalid format or type.")
record.errors.add(:base, _("The erratum filter rule end date is in an invalid format or type."))
end

if start_date_int && end_date_int && !(start_date_int <= end_date_int)
record.errors[:base] << _("Invalid date range. The erratum filter rule start date must come before the end date")
record.errors.add(:base, _("Invalid date range. The erratum filter rule start date must come before the end date"))
end
end

def _check_types(record)
if record.types.is_a?(Array)
invalid_types = record.types.collect(&:to_s) - ContentViewErratumFilter::ERRATA_TYPES.keys
unless invalid_types.empty?
record.errors[:base] <<
record.errors.add(:base,
_("Invalid erratum types %{invalid_types} provided. Erratum type can be any of %{valid_types}") %
{ :invalid_types => invalid_types.join(","),
:valid_types => ContentViewErratumFilter::ERRATA_TYPES.keys.join(",")}
:valid_types => ContentViewErratumFilter::ERRATA_TYPES.keys.join(",")})
end
else
record.errors[:base] << _("The erratum type must be an array. Invalid value provided")
record.errors.add(:base, _("The erratum type must be an array. Invalid value provided"))
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def validate(record)
if !record.version.blank? && (!record.min_version.blank? || !record.max_version.blank?)
invalid_parameters = _("Invalid filter rule specified, 'version' cannot be specified in the" \
" same tuple as 'min_version' or 'max_version'")
record.errors[:base] << invalid_parameters
record.errors.add(:base, invalid_parameters)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def validate(record)
if cve.content_view_id
view = ContentView.where(:id => cve.content_view_id).first
if view&.generated_for_repository?
record.errors[:base] << _("Content view '%{cv_name}' is a generated content view, which cannot be assigned to hosts or activation keys.") % { :cv_name => view.name }
record.errors.add(:base, _("Content view '%{cv_name}' is a generated content view, which cannot be assigned to hosts or activation keys.") % { :cv_name => view.name })
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/lib/katello/validators/gpg_key_content_type_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ def validate(record)
# ssl_ca_cert, ssl_client_cert, ssl_client_key of GpgKey.content type "cert"

if !record.gpg_key.blank? && record.gpg_key.content_type != "gpg_key"
record.errors[:gpg_key] << _("Wrong content type submitted.")
record.errors.add(:gpg_key, _("Wrong content type submitted."))
end

if record.instance_of?(Katello::Product)
[:ssl_ca_cert, :ssl_client_cert, :ssl_client_key].each do |cert|
if !record.send(cert).blank? && record.send(cert).content_type != "cert"
record.errors[cert] << _("Wrong content type submitted.")
record.errors.add(cert, _("Wrong content type submitted."))
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions app/lib/katello/validators/gpg_key_content_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ def validate_each(record, attribute, value)
gpg_key_line_array.pop

if gpg_key_line_array.empty?
record.errors[attribute] << _("must contain valid Public GPG Key")
record.errors.add(attribute, _("must contain valid Public GPG Key"))
else
unless gpg_key_line_array.drop(1).join.match(/[a-zA-Z0-9+\/=]*/)
record.errors[attribute] << _("must contain valid Public GPG Key")
record.errors.add(attribute, _("must contain valid Public GPG Key"))
end
end

else
record.errors[attribute] << _("must contain valid Public GPG Key")
record.errors.add(attribute, _("must contain valid Public GPG Key"))
end

else
record.errors[attribute] << _("must contain GPG Key")
record.errors.add(attribute, _("must contain GPG Key"))
end
end

def self.validate_line_length(record, attribute, value)
value.each_line do |line|
record.errors[attribute] << _("must contain valid Public GPG Key") if line.length > ContentCredential::MAX_CONTENT_LINE_LENGTH
record.errors.add(attribute, _("must contain valid Public GPG Key")) if line.length > ContentCredential::MAX_CONTENT_LINE_LENGTH
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions app/lib/katello/validators/katello_label_format_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ module Validators
class KatelloLabelFormatValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
if value
record.errors[attribute] << N_("cannot contain characters other than ascii alpha numerals, '_', '-'. ") unless value =~ /\A[a-zA-Z0-9_\-]+\z/
record.errors.add(attribute, N_("cannot contain characters other than ascii alpha numerals, '_', '-'. ")) unless value =~ /\A[a-zA-Z0-9_\-]+\z/
NoTrailingSpaceValidator.validate_trailing_space(record, attribute, value)
KatelloLabelFormatValidator.validate_length(record, attribute, value)
else
record.errors[attribute] << N_("can't be blank")
record.errors.add(attribute, N_("can't be blank"))
end
end

def self.validate_length(record, attribute, value, max_length = 128, min_length = 1)
if value
record.errors[attribute] << N_("cannot contain more than %s characters") % max_length unless value.length <= max_length
record.errors[attribute] << N_("must contain at least %s character") % min_length unless value.length >= min_length
record.errors.add(attribute, N_("cannot contain more than %s characters") % max_length) unless value.length <= max_length
record.errors.add(attribute, N_("must contain at least %s character") % min_length) unless value.length >= min_length
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/lib/katello/validators/katello_name_format_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ def validate_each(record, attribute, value)
NoTrailingSpaceValidator.validate_trailing_space(record, attribute, value)
KatelloNameFormatValidator.validate_length(record, attribute, value)
else
record.errors[attribute] << N_("cannot be blank")
record.errors.add(attribute, N_("cannot be blank"))
end
end

def self.validate_length(record, attribute, value, min_length = 1)
if value && !(value.length >= min_length)
record.errors[attribute] << _("must contain at least %s character") % min_length
record.errors.add(attribute, _("must contain at least %s character") % min_length)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/lib/katello/validators/katello_url_format_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def validate_each(record, attribute, value)
end

attribute_name = options[:field_name] || attribute
record.errors[attribute_name] << N_("is invalid") unless kurl_valid?(value)
record.errors.add(attribute_name, N_("is invalid")) unless kurl_valid?(value)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/lib/katello/validators/library_presence_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Katello
module Validators
class LibraryPresenceValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
record.errors[attribute] << N_("must contain '%s'") % "Library" if value.select { |e| e.library }.empty?
record.errors.add(attribute, N_("must contain '%s'") % "Library") if value.select { |e| e.library }.empty?
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/lib/katello/validators/no_trailing_space_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def validate_each(record, attribute, value)

def self.validate_trailing_space(record, attribute, value)
if value && !(value.strip == value)
record.errors[attribute] << _("must not contain leading or trailing white spaces.")
record.errors.add(attribute, _("must not contain leading or trailing white spaces."))
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Validators
class NonLibraryEnvironmentValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return unless value
record.errors[attribute] << N_("Cannot register a system to the '%s' environment") % "Library" if !record.environment.nil? && record.environment.library?
record.errors.add(attribute, N_("Cannot register a system to the '%s' environment") % "Library") if !record.environment.nil? && record.environment.library?
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/lib/katello/validators/not_in_library_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Katello
module Validators
class NotInLibraryValidator < ActiveModel::Validator
def validate(record)
record.errors[:environment] << _("The '%s' environment cannot contain a changeset!") % "Library" if record.environment.library?
record.errors.add(:environment, _("The '%s' environment cannot contain a changeset!") % "Library") if record.environment.library?
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/lib/katello/validators/path_descendents_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def validate(record)
#environment is not duplicated in its path
# We do not want circular dependencies
return if record.prior.nil?
record.errors[:prior] << _(" environment cannot be set to an environment already on its path") if duplicate? record.prior
record.errors.add(:prior, _(" environment cannot be set to an environment already on its path")) if duplicate? record.prior
end

def duplicate?(record)
Expand Down
2 changes: 1 addition & 1 deletion app/lib/katello/validators/prior_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def validate(record)
# prior to have only one child (unless its the Library)
ancestor = record.prior
if ancestor && !ancestor.library? && (ancestor.successors.count == 1 && !ancestor.successors.include?(record))
record.errors[:prior] << _("prior environment can only have one child")
record.errors.add(:prior, _("prior environment can only have one child"))
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def validate_each(record, attribute, value)
unique = self.unique_attribute?(record, attribute, value)

unless unique
record.errors[attribute] << _("has already been taken for a product in this organization.")
record.errors.add(attribute, _("has already been taken for a product in this organization."))
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/lib/katello/validators/repo_disablement_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module Validators
class RepoDisablementValidator < ActiveModel::Validator
def validate(record)
if record.redhat? && record.enabled_changed? && !record.enabled? && record.promoted?
record.errors[:base] << N_("Repository cannot be disabled since it has already been promoted.")
record.errors.add(:base, N_("Repository cannot be disabled since it has already been promoted."))
elsif !record.redhat? && !record.enabled?
record.errors[:base] << N_("Custom repositories cannot be disabled.")
record.errors.add(:base, N_("Custom repositories cannot be disabled."))
end
end
end
Expand Down
Loading
Loading