Class: Katello::ContentViewEnvironment

Inherits:
Model
  • Object
show all
Includes:
ForemanTasks::Concerns::ActionSubject, Authorization::ContentViewEnvironment, Glue, Glue::Candlepin::Environment
Defined in:
app/models/katello/content_view_environment.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Authorization::ContentViewEnvironment

#readable?

Methods included from Glue

logger

Methods included from Glue::Candlepin::Environment

included

Methods inherited from Model

#destroy!

Class Method Details

.fetch_content_view_environments(organization:, labels: [], ids: []) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/models/katello/content_view_environment.rb', line 84

def self.fetch_content_view_environments(organization:, labels: [], ids: [])
  # Must ensure CVEs remain in the same order.
  # Using ActiveRecord .where will return them in a different order.
  id_errors = []
  label_errors = []
  cves = []
  if ids.present?
    ids.each do |id|
      cve = ::Katello::ContentViewEnvironment.find_by(id: id)
      if cve.blank?
        id_errors << id
      else
        cves << cve
      end
    end
  elsif labels.present?
    environment_names = labels.map(&:strip)
    environment_names.each do |name|
      cve = with_label_and_org(name, organization: organization)
      if cve.blank?
        label_errors << name
      else
        cves << cve
      end
    end
  end
  if labels.present? && labels.length != cves.length
    fail HttpErrors::UnprocessableEntity, _("No content view environments found with names: %{names}") % {names: label_errors.join(', ')} if label_errors.present?
  elsif ids.present? && ids.length != cves.length
    fail HttpErrors::UnprocessableEntity, _("No content view environments found with ids: %{ids}") % {ids: id_errors.join(', ')} if id_errors.present?
  end
  cves
end

.for_content_facets(content_facets) ⇒ Object



49
50
51
52
# File 'app/models/katello/content_view_environment.rb', line 49

def self.for_content_facets(content_facets)
  joins(:content_facets).
    where("#{Katello::ContentViewEnvironmentContentFacet.table_name}.content_facet_id" => content_facets).distinct
end

.in_organization(org) ⇒ Object



45
46
47
# File 'app/models/katello/content_view_environment.rb', line 45

def self.in_organization(org)
  where(environment_id: org.kt_environments)
end

.with_label_and_org(label, organization: Organization.current) ⇒ Object



54
55
56
# File 'app/models/katello/content_view_environment.rb', line 54

def self.with_label_and_org(label, organization: Organization.current)
  joins(:environment, :content_view).where("#{Katello::KTEnvironment.table_name}.organization_id" => organization, label: label).first
end

Instance Method Details

#activation_keysObject



67
68
69
# File 'app/models/katello/content_view_environment.rb', line 67

def activation_keys
  ::Katello::ActivationKey.with_content_views(self.content_view).with_environments(self.environment)
end

#default_environment?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'app/models/katello/content_view_environment.rb', line 71

def default_environment?
  content_view.default? && environment.library?
end

#hostsObject



63
64
65
# File 'app/models/katello/content_view_environment.rb', line 63

def hosts
  ::Host.in_content_view_environment(:content_view => self.content_view, :lifecycle_environment => self.environment)
end

#ownerObject

retrieve the owning environment for this content view environment.



59
60
61
# File 'app/models/katello/content_view_environment.rb', line 59

def owner
  self.environment
end

#priority(content_object) ⇒ Object



75
76
77
78
79
80
81
82
# File 'app/models/katello/content_view_environment.rb', line 75

def priority(content_object)
  case content_object
  when Katello::ActivationKey
    content_view_environment_activation_keys.find_by(:activation_key_id => content_object.id).try(:priority)
  when Katello::Host::ContentFacet
    content_view_environment_content_facets.find_by(:content_facet_id => content_object.id).try(:priority)
  end
end