Class: Katello::ContentViewEnvironment
- Inherits:
-
Model
- Object
- Model
- 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
- .find_by_cv_and_lce!(content_view_id, lifecycle_environment_id) ⇒ 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
Class Method Details
.fetch_content_view_environments(organization:, labels: [], ids: []) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/models/katello/content_view_environment.rb', line 102 def self.fetch_content_view_environments(organization:, labels: [], ids: []) # Must ensure content view environments remain in the same order. # Using ActiveRecord .where will return them in a different order. id_errors = [] label_errors = [] cvenvs = [] if ids.present? ids.each do |id| cvenv = ::Katello::ContentViewEnvironment.find_by(id: id) if cvenv.blank? id_errors << id else cvenvs << cvenv end end elsif labels.present? environment_names = labels.map(&:strip) environment_names.each do |name| cvenv = with_label_and_org(name, organization: organization) if cvenv.blank? label_errors << name else cvenvs << cvenv end end end if labels.present? && labels.length != cvenvs.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 != cvenvs.length fail HttpErrors::UnprocessableEntity, _("No content view environments found with ids: %{ids}") % {ids: id_errors.join(', ')} if id_errors.present? end cvenvs end |
.find_by_cv_and_lce!(content_view_id, lifecycle_environment_id) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/models/katello/content_view_environment.rb', line 84 def self.find_by_cv_and_lce!(content_view_id, lifecycle_environment_id) cvenv = find_by(content_view_id: content_view_id, environment_id: lifecycle_environment_id) return cvenv if cvenv env_label = Katello::KTEnvironment.find_by(id: lifecycle_environment_id)&.label if env_label.nil? fail Katello::Errors::ContentViewEnvironmentError, _("Unable to find a lifecycle environment with ID %s") % lifecycle_environment_id end cv_label = Katello::ContentView.find_by(id: content_view_id)&.label if cv_label.nil? fail Katello::Errors::ContentViewEnvironmentError, _("Unable to find a content view with ID %s") % content_view_id end fail Katello::Errors::ContentViewEnvironmentError, _("Cannot assign content view environment %{env}/%{cv}: The content view has either not been published or has not been promoted to that lifecycle environment.") % {env: env_label, cv: cv_label} 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_keys ⇒ Object
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
71 72 73 |
# File 'app/models/katello/content_view_environment.rb', line 71 def default_environment? content_view.default? && environment.library? end |
#hosts ⇒ Object
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 |
#owner ⇒ Object
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 |