Class: Katello::Provider

Inherits:
Model
  • Object
show all
Includes:
ForemanTasks::Concerns::ActionSubject, Glue, Glue::Provider
Defined in:
app/models/katello/provider.rb

Constant Summary collapse

REDHAT =
'Red Hat'.encode('utf-8')
CUSTOM =
'Custom'.encode('utf-8')
ANONYMOUS =
'Anonymous'.encode('utf-8')
TYPES =
[REDHAT, CUSTOM, ANONYMOUS].freeze

Constants included from Glue::Provider

Glue::Provider::DISTRIBUTOR_VERSION

Instance Method Summary collapse

Methods included from Glue

logger

Methods included from Glue::Provider

included, orphaned_custom_product?, orphaned_product?, provider_for_cp_id

Instance Method Details

#anonymous_provider?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'app/models/katello/provider.rb', line 76

def anonymous_provider?
  provider_type == ANONYMOUS
end

#as_json(*args) ⇒ Object



89
90
91
# File 'app/models/katello/provider.rb', line 89

def as_json(*args)
  super.merge('organization_label' => self.organization.label)
end

#constraint_redhat_updateObject



47
48
49
50
51
52
53
54
# File 'app/models/katello/provider.rb', line 47

def constraint_redhat_update
  if !new_record? && redhat_provider?
    not_allowed_changes = changes.keys
    unless not_allowed_changes.empty?
      errors.add(:base, _("the following attributes can not be updated for the Red Hat provider: [ %s ]") % not_allowed_changes.join(", "))
    end
  end
end

#count_providers(type) ⇒ Object



56
57
58
# File 'app/models/katello/provider.rb', line 56

def count_providers(type)
  Provider.where(:organization_id => self.organization_id, :provider_type => type).count(:id)
end

#custom_provider?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'app/models/katello/provider.rb', line 72

def custom_provider?
  provider_type == CUSTOM
end

#only_one_rhn_providerObject



30
31
32
33
34
35
# File 'app/models/katello/provider.rb', line 30

def only_one_rhn_provider
  # validate only when new record is added (skip explicit valid? calls)
  if new_record? && provider_type == REDHAT && count_providers(REDHAT) != 0
    errors.add(:base, _("Only one Red Hat provider permitted for an Organization"))
  end
end

#prevent_redhat_deletionObject



37
38
39
40
41
42
43
44
45
# File 'app/models/katello/provider.rb', line 37

def prevent_redhat_deletion
  if !being_deleted? && redhat_provider?
    Rails.logger.error _("Red Hat provider can not be deleted")
    throw :abort
  else
    # organization that is being deleted via background destroyer can delete rh provider
    true
  end
end

#redhat_provider=(is_rh) ⇒ Object



64
65
66
# File 'app/models/katello/provider.rb', line 64

def redhat_provider=(is_rh)
  is_rh ? REDHAT : ANONYMOUS # Anonymous is the now the default
end

#redhat_provider?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'app/models/katello/provider.rb', line 68

def redhat_provider?
  provider_type == REDHAT
end


101
102
103
# File 'app/models/katello/provider.rb', line 101

def related_resources
  self.organization
end

#serializable_hash(options = {}) ⇒ Object



82
83
84
85
86
87
# File 'app/models/katello/provider.rb', line 82

def serializable_hash(options = {})
  options = {} if options.nil?
  hash = super(options)
  hash.merge(:sync_state => self.sync_state,
                    :last_sync => self.last_sync)
end

#total_productsObject



93
94
95
# File 'app/models/katello/provider.rb', line 93

def total_products
  products.length
end

#total_repositoriesObject



97
98
99
# File 'app/models/katello/provider.rb', line 97

def total_repositories
  repositories.length
end

#yum_repo?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'app/models/katello/provider.rb', line 60

def yum_repo?
  provider_type == CUSTOM || provider_type == ANONYMOUS
end