Class: Katello::ContentViewFilter

Inherits:
Model
  • Object
show all
Includes:
Authorization::ContentViewFilter
Defined in:
app/models/katello/content_view_filter.rb

Constant Summary collapse

DOCKER =
'docker'.freeze
RPM =
Rpm::CONTENT_TYPE
PACKAGE_GROUP =
PackageGroup::CONTENT_TYPE
ERRATA =
Erratum::CONTENT_TYPE
MODULE_STREAM =
ModuleStream::CONTENT_TYPE
DEB =
Deb::CONTENT_TYPE
CONTENT_TYPES =
[RPM, PACKAGE_GROUP, ERRATA, DOCKER, DEB, MODULE_STREAM].freeze
CONTENT_OPTIONS =
{ _('Packages') => RPM, _('Module Streams') => ModuleStream, _('Package Groups') => PACKAGE_GROUP, _('Errata') => ERRATA, _('Container Images') => DOCKER, _('Deb Packages') => DEB }.freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#destroy!

Class Method Details

.applicable(repo) ⇒ Object



150
151
152
153
154
155
# File 'app/models/katello/content_view_filter.rb', line 150

def self.applicable(repo)
  query = %{ (katello_content_view_filters.id in (select content_view_filter_id from katello_repository_content_view_filters where repository_id = #{repo.id})) or
             (katello_content_view_filters.id not in (select content_view_filter_id from katello_repository_content_view_filters))
           }
  where(query).select("DISTINCT katello_content_view_filters.id")
end

.class_for(content_type) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/models/katello/content_view_filter.rb', line 81

def self.class_for(content_type)
  case content_type
  when DEB
    ContentViewDebFilter
  when RPM
    ContentViewPackageFilter
  when PACKAGE_GROUP
    ContentViewPackageGroupFilter
  when ERRATA
    ContentViewErratumFilter
  when DOCKER
    ContentViewDockerFilter
  when MODULE_STREAM
    ContentViewModuleStreamFilter
  else
    fail _("Invalid content type '%{content_type}' provided. Content types can be one of %{content_types}") %
             { :content_type => content_type, :content_types => CONTENT_TYPES.join(", ") }
  end
end

.create_for(content_type, options) ⇒ Object



145
146
147
148
# File 'app/models/katello/content_view_filter.rb', line 145

def self.create_for(content_type, options)
  clazz = class_for(content_type)
  clazz.create!(options)
end

.debObject



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

def self.deb
  where(:type => ::Katello::ContentViewDebFilter.name)
end

.dockerObject



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

def self.docker
  where(:type => [::Katello::ContentViewDockerFilter.name])
end

.errataObject



62
63
64
# File 'app/models/katello/content_view_filter.rb', line 62

def self.errata
  where(:type => ::Katello::ContentViewErratumFilter.name)
end

.module_streamObject



58
59
60
# File 'app/models/katello/content_view_filter.rb', line 58

def self.module_stream
  where(:type => ::Katello::ContentViewModuleStreamFilter.name)
end

.rule_class_for(filter) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'app/models/katello/content_view_filter.rb', line 101

def self.rule_class_for(filter)
  case filter.type
  when ContentViewDebFilter.name
    ContentViewDebFilterRule
  when ContentViewPackageFilter.name
    ContentViewPackageFilterRule
  when ContentViewPackageGroupFilter.name
    ContentViewPackageGroupFilterRule
  when ContentViewErratumFilter.name
    ContentViewErratumFilterRule
  when ContentViewModuleStreamFilter.name
    ContentViewModuleStreamFilterRule
  when ContentViewDockerFilter.name
    ContentViewDockerFilterRule
  else
    fail _("Invalid content type '%{content_type}' provided. Content types can be one of %{content_types}") %
             { :content_type => filter.type, :content_types => CONTENT_TYPES.join(", ") }
  end
end

.rule_ids_for(filter) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'app/models/katello/content_view_filter.rb', line 121

def self.rule_ids_for(filter)
  case filter.type
  when ContentViewDebFilter.name
    filter.deb_rule_ids
  when ContentViewPackageFilter.name
    filter.package_rule_ids
  when ContentViewPackageGroupFilter.name
    filter.package_group_rule_ids
  when ContentViewErratumFilter.name
    filter.erratum_rule_ids
  when ContentViewModuleStreamFilter.name
    filter.module_stream_ids
  when ContentViewDockerFilter.name
    filter.docker_rule_ids
  else
    fail _("Invalid content type '%{content_type}' provided. Content types can be one of %{content_types}") %
             { :content_type => filter.type, :content_types => CONTENT_TYPES.join(", ") }
  end
end

.yum(include_module_streams = true) ⇒ Object



41
42
43
44
45
46
47
48
# File 'app/models/katello/content_view_filter.rb', line 41

def self.yum(include_module_streams = true)
  types = [::Katello::ContentViewPackageGroupFilter.name,
           ::Katello::ContentViewErratumFilter.name,
           ::Katello::ContentViewPackageFilter.name
          ]
  types << ::Katello::ContentViewModuleStreamFilter.name if include_module_streams
  where(:type => types)
end

Instance Method Details

#applicable_reposObject



189
190
191
192
193
194
195
# File 'app/models/katello/content_view_filter.rb', line 189

def applicable_repos
  if self.repositories.blank?
    self.content_view.repositories
  else
    self.repositories
  end
end

#as_json(options = {}) ⇒ Object



157
158
159
160
161
162
# File 'app/models/katello/content_view_filter.rb', line 157

def as_json(options = {})
  super(options).update("content_view_label" => content_view.label,
                        "organization" => content_view.organization.label,
                        "repos" => repositories.collect(&:name),
                        "content" => content_type)
end

#content_typeObject



70
71
72
73
74
75
76
77
78
79
# File 'app/models/katello/content_view_filter.rb', line 70

def content_type
  {
    ContentViewDebFilter => DEB,
    ContentViewPackageFilter => RPM,
    ContentViewErratumFilter => ERRATA,
    ContentViewPackageGroupFilter => PACKAGE_GROUP,
    ContentViewDockerFilter => DOCKER,
    ContentViewModuleStreamFilter => MODULE_STREAM
  }[self.class]
end

#filter_typeObject



141
142
143
# File 'app/models/katello/content_view_filter.rb', line 141

def filter_type
  CONTENT_OPTIONS.key(content_type)
end

#original_module_streams=(_include_original) ⇒ Object



201
202
203
# File 'app/models/katello/content_view_filter.rb', line 201

def original_module_streams=(_include_original)
  fail "setting original_module_streams not supported for #{self.class.name}"
end

#original_packages=(_include_original) ⇒ Object



197
198
199
# File 'app/models/katello/content_view_filter.rb', line 197

def original_packages=(_include_original)
  fail "setting original_packages not supported for #{self.class.name}"
end

#params_formatObject



66
67
68
# File 'app/models/katello/content_view_filter.rb', line 66

def params_format
  {}
end

#resulting_productsObject



185
186
187
# File 'app/models/katello/content_view_filter.rb', line 185

def resulting_products
  repositories.collect { |r| r.product }.uniq
end

#validate_content_viewObject



164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'app/models/katello/content_view_filter.rb', line 164

def validate_content_view
  if self.content_view.composite?
    errors.add(:base, _("cannot contain filters if composite view"))
  end

  if self.content_view.import_only?
    errors.add(:base, _("cannot add filter to import-only view"))
  end

  if self.content_view.generated?
    errors.add(:base, _("cannot add filter to generated content views"))
  end
end

#validate_filter_repos(errors, content_view) ⇒ Object



178
179
180
181
182
183
# File 'app/models/katello/content_view_filter.rb', line 178

def validate_filter_repos(errors, content_view)
  repo_diff = repositories - content_view.repositories
  unless repo_diff.empty?
    errors.add(:base, _("cannot contain filters whose repositories do not belong to this content view"))
  end
end