Skip to content

Commit

Permalink
Fix Style/SoleNestedConditional cop
Browse files Browse the repository at this point in the history
  • Loading branch information
archanaserver committed Jul 11, 2024
1 parent a04ca79 commit 3a98c7a
Show file tree
Hide file tree
Showing 30 changed files with 97 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,8 @@ def authorize_client_or_user
end

def authorize_client_or_admin
unless client_authorized?
deny_access unless authorize
if !client_authorized? && !authorize
deny_access
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,12 @@ def validate_content(content)
end
end

if content[:package_ids]
fail _("package_ids is not an array") unless content[:package_ids].is_a?(Array)
if content[:package_ids] && !content[:package_ids].is_a?(Array)
fail _("package_ids is not an array")
end

if content[:deb_ids]
fail _("deb_ids is not an array") unless content[:deb_ids].is_a?(Array)
if content[:deb_ids] && !content[:deb_ids].is_a?(Array)
fail _("deb_ids is not an array")
end
end

Expand Down
8 changes: 4 additions & 4 deletions app/controllers/katello/api/v2/host_errata_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ def validate_index_params!
if (params[:content_view_id] && params[:environment_id].nil?) || (params[:environment_id] && params[:content_view_id].nil?)
fail _("Either both parameters 'content_view_id' and 'environment_id' should be specified or neither should be specified")
end
if params[:type].present?
fail _("Type must be one of: %s" % TYPES_FROM_PARAMS.keys.join(', ')) unless TYPES_FROM_PARAMS.key?(params[:type].to_sym)
if params[:type].present? && !TYPES_FROM_PARAMS.key?(params[:type].to_sym)
fail _("Type must be one of: %s" % TYPES_FROM_PARAMS.keys.join(', '))
end
if params[:severity].present?
fail _("Severity must be one of: %s") % Katello::Erratum::SEVERITIES.join(', ') unless Katello::Erratum::SEVERITIES.include?(params[:severity])
if params[:severity].present? && !Katello::Erratum::SEVERITIES.include?(params[:severity])
fail _("Severity must be one of: %s") % Katello::Erratum::SEVERITIES.join(', ')
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/katello/api/v2/host_packages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def extract_group_names(groups)
end

def validate_index_params!
if params[:status].present?
fail _("Status must be one of: %s" % VERSION_STATUSES.join(', ')) unless VERSION_STATUSES.include?(params[:status])
if params[:status].present? && !VERSION_STATUSES.include?(params[:status])
fail _("Status must be one of: %s" % VERSION_STATUSES.join(', '))
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/katello/api/v2/repository_sets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ def index_relation

relation = relation.where(Katello::Content.table_name => {:name => params[:name]}) if params[:name].present?
# ignore with_custom if repository_type is specified
if params[:repository_type].blank?
relation = relation.redhat unless ::Foreman::Cast.to_bool(params[:with_custom])
if params[:repository_type].blank? && !::Foreman::Cast.to_bool(params[:with_custom])
relation = relation.redhat
end
index_relation_with_consumable_overrides(relation)
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/katello/api/v2/sync_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def find_repository
end

def ensure_library
unless @repository.nil?
fail HttpErrors::NotFound, _("You can check sync status for repositories only in the library lifecycle environment.'") unless @repository.environment.library?
if !@repository.nil? && !@repository.environment.library?
fail HttpErrors::NotFound, _("You can check sync status for repositories only in the library lifecycle environment.'")
end
end
end
Expand Down
10 changes: 4 additions & 6 deletions app/lib/actions/katello/foreman/content_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ def finalize
content_view = ::Katello::ContentView.find(input[:content_view_id])
repository = ::Katello::Repository.find(input[:repository_id]) if input[:repository_id]

if content_view.default? && repository
if repository.distribution_bootable?
os = Redhat.find_or_create_operating_system(repository)
arch = Architecture.where(:name => repository.distribution_arch).first_or_create!
os.architectures << arch unless os.architectures.include?(arch)
end
if content_view.default? && repository && repository.distribution_bootable?
os = Redhat.find_or_create_operating_system(repository)
arch = Architecture.where(:name => repository.distribution_arch).first_or_create!
os.architectures << arch unless os.architectures.include?(arch)
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions app/lib/actions/katello/host/hypervisors_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ def generate_duplicates_list
end

def validate_host_organization(host, organization)
if host.organization_id.nil? || host.organization_id != organization
fail _("Host '%{name}' does not belong to an organization") % {:name => host.name} unless host.organization
if (host.organization_id.nil? || host.organization_id != organization) && !host.organization
fail _("Host '%{name}' does not belong to an organization") % {:name => host.name}
end
end

Expand Down Expand Up @@ -175,8 +175,8 @@ def update_subscription_facet(uuid, host)
end

def update_facts(uuid, host)
if @candlepin_attributes.key?(uuid)
::Katello::Host::SubscriptionFacet.update_facts(host, @candlepin_attributes[uuid][:facts]) unless @candlepin_attributes[uuid][:facts].blank?
if @candlepin_attributes.key?(uuid) && !@candlepin_attributes[uuid][:facts].blank?
::Katello::Host::SubscriptionFacet.update_facts(host, @candlepin_attributes[uuid][:facts])
end
end

Expand Down
10 changes: 4 additions & 6 deletions app/lib/actions/katello/repository/import_upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def plan(repository, uploads, options = {})

def run
repository = ::Katello::Repository.find(input[:repository_id])
if input[:sync_capsule]
ForemanTasks.async_task(Katello::Repository::CapsuleSync, repository) if Setting[:foreman_proxy_content_auto_sync]
if input[:sync_capsule] && (Setting[:foreman_proxy_content_auto_sync])
ForemanTasks.async_task(Katello::Repository::CapsuleSync, repository)
end
output[:upload_results] = results_to_json(input[:upload_results])
rescue ::Katello::Errors::CapsuleCannotBeReached # skip any capsules that cannot be connected to
Expand Down Expand Up @@ -92,10 +92,8 @@ def results_to_json(results)
json_results << {:type => 'file'}
end
end
unless json_results.size
if result[:content_unit_href]
json_results << {:type => 'file'}
end
if !json_results.size && (result[:content_unit_href])
json_results << {:type => 'file'}
end
end
json_results
Expand Down
8 changes: 3 additions & 5 deletions app/lib/actions/pulp3/repository/save_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ def run
end

output[:publication_provided] = false
if input[:tasks].present?
if (publication_href = ::Katello::Pulp3::Task.publication_href(input[:tasks]))
repo.update(:publication_href => publication_href)
output[:publication_provided] = true
end
if input[:tasks].present? && (publication_href = ::Katello::Pulp3::Task.publication_href(input[:tasks]))
repo.update(:publication_href => publication_href)
output[:publication_provided] = true
end

if version_href
Expand Down
4 changes: 2 additions & 2 deletions app/lib/katello/concerns/base_template_scope_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ def load_errata_applications(filter_errata_type: nil, include_last_reboot: 'yes'
current_erratum_errata_type = current_erratum[1]
current_erratum_issued = current_erratum.last

if filter_errata_type != 'all'
next unless filter_errata_type == current_erratum_errata_type
if filter_errata_type != 'all' && !(filter_errata_type == current_erratum_errata_type)
next
end

hash = {
Expand Down
4 changes: 2 additions & 2 deletions app/lib/katello/util/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ def self.build_vrea(package, include_zero_epoch = true)
vrea = [package[:version], package[:release]].compact.join('-')
vrea = vrea + '.' + package[:arch] unless package[:arch].nil?
vrea = vrea + '.' + package[:suffix] unless package[:suffix].nil?
unless package[:epoch].nil?
vrea = package[:epoch] + ':' + vrea if package[:epoch].to_i != 0 || include_zero_epoch
if !package[:epoch].nil? && (package[:epoch].to_i != 0 || include_zero_epoch)
vrea = package[:epoch] + ':' + vrea
end
vrea
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ module Katello
module Validators
class AlternateContentSourceProductsValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
if value
if attribute == :product_id
product = ::Katello::Product.find(value)
content_type = record.alternate_content_source.content_type
if product.repositories.with_type(content_type).has_url.empty?
record.errors.add(attribute, _("%{name} has no %{type} repositories with upstream URLs to add to the alternate content source.") % { name: product.name, type: content_type })
end
if value && (attribute == :product_id)
product = ::Katello::Product.find(value)
content_type = record.alternate_content_source.content_type
if product.repositories.with_type(content_type).has_url.empty?
record.errors.add(attribute, _("%{name} has no %{type} repositories with upstream URLs to add to the alternate content source.") % { name: product.name, type: content_type })
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 @@ -13,8 +13,8 @@ def validate_each(record, attribute, value)
end

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

def self.validate_trailing_space(record, attribute, value)
if value
record.errors[attribute] << _("must not contain leading or trailing white spaces.") unless value.strip == value
if value && !(value.strip == value)
record.errors[attribute] << _("must not contain leading or trailing white spaces.")
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/lib/katello/validators/prior_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def validate(record)
# this is because in v1.0 we want
# prior to have only one child (unless its the Library)
ancestor = record.prior
if ancestor && !ancestor.library?
record.errors[:prior] << _("prior environment can only have one child") if ancestor.successors.count == 1 && !ancestor.successors.include?(record)
if ancestor && !ancestor.library? && (ancestor.successors.count == 1 && !ancestor.successors.include?(record))
record.errors[: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 @@ -12,10 +12,8 @@ def validate_each(record, attribute, value)
def unique_attribute?(record, attribute, value)
unique = true

if record.provider && !record.provider.redhat_provider? && record.send("#{attribute}_changed?")
if Product.in_org(record.provider.organization).where(attribute => value).exists?
unique = false
end
if record.provider && !record.provider.redhat_provider? && record.send("#{attribute}_changed?") && Product.in_org(record.provider.organization).where(attribute => value).exists?
unique = false
end

unique
Expand Down
10 changes: 4 additions & 6 deletions app/models/katello/activation_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,10 @@ def self.find_by_purpose_addons(_key, operator, value)
end

def validate_destroyable!
unless organization.being_deleted?
if Parameter.where(name: 'kt_activation_keys').pluck(:value).any? { |value| value.split(",").include?(name) }
fail _("This activation key is associated to one or more Hosts/Hostgroups. "\
"Search and unassociate Hosts/Hostgroups using params.kt_activation_keys ~ \"%{name}\" "\
"before deleting." % {name: name})
end
if !organization.being_deleted? && Parameter.where(name: 'kt_activation_keys').pluck(:value).any? { |value| value.split(",").include?(name) }
fail _("This activation key is associated to one or more Hosts/Hostgroups. "\
"Search and unassociate Hosts/Hostgroups using params.kt_activation_keys ~ \"%{name}\" "\
"before deleting." % {name: name})
end
true
end
Expand Down
6 changes: 2 additions & 4 deletions app/models/katello/concerns/hostgroup_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ def correct_kickstart_repository
self.medium = nil
end

if content_facet&.kickstart_repository_id && !matching_kickstart_repository?(content_facet)
if (equivalent = equivalent_kickstart_repository)
self.content_facet.kickstart_repository_id = equivalent[:id]
end
if content_facet&.kickstart_repository_id && !matching_kickstart_repository?(content_facet) && (equivalent = equivalent_kickstart_repository)
self.content_facet.kickstart_repository_id = equivalent[:id]
end
end

Expand Down
6 changes: 2 additions & 4 deletions app/models/katello/concerns/location_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ def set_default_overrides
end

def reset_settings
if saved_change_to_attribute?(:title)
if ::Setting[:default_location_subscribed_hosts] == self.title_before_last_save
::Setting[:default_location_subscribed_hosts] = self.title
end
if saved_change_to_attribute?(:title) && (::Setting[:default_location_subscribed_hosts] == self.title_before_last_save)
::Setting[:default_location_subscribed_hosts] = self.title
end
end

Expand Down
8 changes: 4 additions & 4 deletions app/models/katello/concerns/operatingsystem_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def partition_table_name_for_os
end

def assign_templates!
if [ 'Suse', 'Debian' ].include?(self.family)
return if assign_related_os_templates
if [ 'Suse', 'Debian' ].include?(self.family) && assign_related_os_templates
return
end

# Automatically assign default templates
Expand All @@ -98,8 +98,8 @@ def assign_templates!

partition_table_name = partition_table_name_for_os
return if partition_table_name.nil?
if (ptable = Ptable.unscoped.find_by_name(partition_table_name))
ptables << ptable unless ptables.include?(ptable)
if (ptable = Ptable.unscoped.find_by_name(partition_table_name)) && !ptables.include?(ptable)
ptables << ptable
end
end

Expand Down
6 changes: 2 additions & 4 deletions app/models/katello/host/subscription_facet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,8 @@ def self.propose_custom_fact(facts)
setting_fact = Setting[:register_hostname_fact]
only_use_custom_fact = Setting[:register_hostname_fact_strict_match]

if !setting_fact.blank? && !facts[setting_fact].blank?
if only_use_custom_fact || ::Host.where(:name => setting_fact.downcase).any?
facts[setting_fact]
end
if !setting_fact.blank? && !facts[setting_fact].blank? && (only_use_custom_fact || ::Host.where(:name => setting_fact.downcase).any?)
facts[setting_fact]
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/models/katello/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ def assign_unique_label
self.label = Util::Model.labelize(self.name) if self.label.blank?

# if the object label is already being used in this org, append the id to make it unique
if Product.all_in_org(self.organization).where("#{Katello::Product.table_name}.label = ?", self.label).count > 0
self.label = self.label + "_" + self.cp_id unless self.cp_id.blank?
if Product.all_in_org(self.organization).where("#{Katello::Product.table_name}.label = ?", self.label).count > 0 && !self.cp_id.blank?
self.label = self.label + "_" + self.cp_id
end
end

Expand Down
22 changes: 10 additions & 12 deletions app/models/katello/task_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,16 @@ def message
when :package
p = self.parameters[:packages]
first_package = p.first.is_a?(Hash) ? p.first[:name] : p.first
unless p && p.length > 0
if self.task_type == "package_update"
case self.overall_status
when "running"
return "updating"
when "waiting"
return "updating"
when "error"
return _("all packages update failed")
else
return _("all packages update")
end
if !p && p.length > 0 && (self.task_type == "package_update")
case self.overall_status
when "running"
return "updating"
when "waiting"
return "updating"
when "error"
return _("all packages update failed")
else
return _("all packages update")
end
end

Expand Down
10 changes: 4 additions & 6 deletions app/services/katello/pulp3/repository/apt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,10 @@ def multi_copy_units(repo_id_map, _dependency_solving)
# Not needed during incremental update due to dest_base_version
# -> Unless incrementally updating a CV repo that is a soft copy of its library instance.
# -> I.e. no filters and not an incremental version.
unless dest_repo_id_map[:base_version]
# Don't perform extra content actions if the repo is a soft copy of its library instance.
# Taken care of by the IncrementalUpdate action.
unless dest_repo.soft_copy_of_library?
tasks << remove_all_content_from_repo(dest_repo_href)
end
# Don't perform extra content actions if the repo is a soft copy of its library instance.
# Taken care of by the IncrementalUpdate action.
if !dest_repo_id_map[:base_version] && !dest_repo.soft_copy_of_library?
tasks << remove_all_content_from_repo(dest_repo_href)
end
source_repo_ids.each do |source_repo_id|
source_repo_version = ::Katello::Repository.find(source_repo_id).version_href
Expand Down
6 changes: 2 additions & 4 deletions app/services/katello/pulp3/repository/yum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ def import_distribution_data
:distribution_family => distribution.results.first.release_name,
:distribution_bootable => self.class.distribution_bootable?(distribution)
)
unless distribution.results.first.variants.empty?
unless distribution.results.first.variants.first.name.nil?
repo.update!(:distribution_variant => distribution.results.first.variants.map(&:name).join(','))
end
if !distribution.results.first.variants.empty? && !distribution.results.first.variants.first.name.nil?
repo.update!(:distribution_variant => distribution.results.first.variants.map(&:name).join(','))
end
end
end
Expand Down
Loading

0 comments on commit 3a98c7a

Please sign in to comment.