Class: Katello::ContentViewEnvironment
- Includes:
- ForemanTasks::Concerns::ActionSubject, Authorization::ContentViewEnvironment, Glue, Glue::Candlepin::Environment
- Defined in:
- app/models/katello/content_view_environment.rb
Class Method Summary collapse
- .fetch_content_view_environments(organization:, labels: [], ids: []) ⇒ Object
- .for_content_facets(content_facets) ⇒ Object
- .in_organization(org) ⇒ Object
- .with_label_and_org(label, organization: Organization.current) ⇒ Object
Instance Method Summary collapse
- #activation_keys ⇒ Object
- #default_environment? ⇒ Boolean
- #hosts ⇒ Object
-
#owner ⇒ Object
retrieve the owning environment for this content view environment.
- #priority(content_object) ⇒ Object
Methods included from Authorization::ContentViewEnvironment
Methods included from Glue
Methods included from Glue::Candlepin::Environment
Methods inherited from Model
Class Method Details
.fetch_content_view_environments(organization:, labels: [], ids: []) ⇒ Object
81 82 83 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 |
# File 'app/models/katello/content_view_environment.rb', line 81 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
46 47 48 49 |
# File 'app/models/katello/content_view_environment.rb', line 46 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
42 43 44 |
# File 'app/models/katello/content_view_environment.rb', line 42 def self.in_organization(org) where(environment_id: org.kt_environments) end |
.with_label_and_org(label, organization: Organization.current) ⇒ Object
51 52 53 |
# File 'app/models/katello/content_view_environment.rb', line 51 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_keys ⇒ Object
64 65 66 |
# File 'app/models/katello/content_view_environment.rb', line 64 def activation_keys ::Katello::ActivationKey.with_content_views(self.content_view).with_environments(self.environment) end |
#default_environment? ⇒ Boolean
68 69 70 |
# File 'app/models/katello/content_view_environment.rb', line 68 def default_environment? content_view.default? && environment.library? end |
#hosts ⇒ Object
60 61 62 |
# File 'app/models/katello/content_view_environment.rb', line 60 def hosts ::Host.in_content_view_environment(:content_view => self.content_view, :lifecycle_environment => self.environment) end |
#owner ⇒ Object
retrieve the owning environment for this content view environment.
56 57 58 |
# File 'app/models/katello/content_view_environment.rb', line 56 def owner self.environment end |
#priority(content_object) ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'app/models/katello/content_view_environment.rb', line 72 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 |