Skip to content

Commit

Permalink
Fixes #30352 - Add an original mod streams filter
Browse files Browse the repository at this point in the history
This commit allows module streams filters to include Module Streams that
do not belong to any errata. This is especially useful when used in
conjunction with rpm filters.

Refs #30352 - reverting b58687e

For more context:

`Original` in this context applies to modules that were originally
there before errata started coming.
We use `--original-packages` for rpm that are not part of any errata.

This commit adds `--original-module-streams` for module streams that
are not part of errata.

Module filters introduced a  flaw in master.

Since we did not have this --original-module-streams flag,
if you did any sort of errata filtering you'd not get modules that
do not belong to any errata

Many customers want ->
1. All the content in the base +
2. Security errata up until a specified date in their cve
so their filters are written the same way

This commit aims to fix this scenario
  • Loading branch information
parthaa committed Jul 13, 2020
1 parent 853260e commit 28dce7b
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def index_relation
param :type, String, :desc => N_("type of filter (e.g. rpm, package_group, erratum, docker, modulemd)"), :required => true
param :original_packages, :bool, :desc => N_("add all packages without errata to the included/excluded list. " \
"(package filter only)")
param :original_module_streams, :bool, :desc => N_("add all module streams without errata to the included/excluded list. " \
"(module stream filter only)")
param :inclusion, :bool, :desc => N_("specifies if content should be included or excluded, default: inclusion=false")
param :repository_ids, Array, :desc => N_("list of repository ids")
param :description, String, :desc => N_("description of the filter")
Expand All @@ -60,6 +62,8 @@ def show
param :name, String, :desc => N_("new name for the filter")
param :original_packages, :bool, :desc => N_("add all packages without errata to the included/excluded list. " \
"(package filter only)")
param :original_module_streams, :bool, :desc => N_("add all module streams without errata to the included/excluded list. " \
"(module stream filter only)")
param :inclusion, :bool, :desc => N_("specifies if content should be included or excluded, default: inclusion=false")
param :repository_ids, Array, :desc => N_("list of repository ids")
param :description, String, :desc => N_("description of the filter"), :required => false
Expand Down Expand Up @@ -95,7 +99,7 @@ def find_filter
end

def filter_params
params.require(:content_view_filter).permit(:name, :inclusion, :original_packages, :description, :repository_ids => [])
params.require(:content_view_filter).permit(:name, :inclusion, :original_packages, :original_module_streams, :description, :repository_ids => [])
end
end
end
4 changes: 4 additions & 0 deletions app/models/katello/content_view_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ def original_packages=(_include_original)
fail "setting original_packages not supported for #{self.class.name}"
end

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

protected

def validate_repos
Expand Down
14 changes: 11 additions & 3 deletions app/models/katello/content_view_module_stream_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@ class ContentViewModuleStreamFilter < ContentViewFilter

validates_lengths_from_database

def generate_clauses(_repo)
return if module_stream_rules.blank?
module_stream_rules.map(&:module_stream_id)
def generate_clauses(repo)
rules = module_stream_rules || []
ids = rules.map(&:module_stream_id)
if self.original_module_streams
ids.concat(repo.module_streams_without_errata.map(&:id))
end
ids
end

def original_module_streams=(value)
self[:original_module_streams] = value
end
end
end
11 changes: 11 additions & 0 deletions app/models/katello/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,17 @@ def packages_without_errata
end
end

def module_streams_without_errata
module_stream_errata = Katello::ModuleStreamErratumPackage.joins(:erratum_package => {:erratum => :repository_errata})
.where("#{RepositoryErratum.table_name}.repository_id" => self.id)
.pluck("#{Katello::ModuleStreamErratumPackage.table_name}.module_stream_id")
if module_stream_errata.any?
self.module_streams.where("#{ModuleStream.table_name}.id NOT in (?)", module_stream_errata)
else
self.module_streams
end
end

def self.with_errata(errata)
joins(:repository_errata).where("#{Katello::RepositoryErratum.table_name}.erratum_id" => errata)
end
Expand Down
3 changes: 2 additions & 1 deletion app/services/katello/pulp/repository/yum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ def generate_copy_clauses(filters, rpm_filenames)
remove = clause_gen.remove_clause
remove_clauses = {filters: {unit: remove}} if remove
else
copy_clauses = {}
non_modular_rpms = ::Katello::Rpm.in_repositories(repo).non_modular.pluck(:filename)
copy_clauses = non_modular_rpms.blank? ? nil : {filters: {unit: ContentViewPackageFilter.generate_rpm_clauses(non_modular_rpms)}}
remove_clauses = nil
end

Expand Down
4 changes: 4 additions & 0 deletions app/views/katello/api/v2/content_view_filters/base.json.rabl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ if @resource.respond_to?(:package_rules)
attributes :original_packages
end

if @resource.respond_to?(:module_stream_rules)
attributes :original_module_streams
end

node :rules do |filter|
if filter.respond_to?(:package_rules)
filter.package_rules.map do |rule|
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddOriginalModulesToContentViewModuleStreamFilter < ActiveRecord::Migration[6.0]
def change
add_column :katello_content_view_filters, :original_module_streams, :boolean, :default => false, :null => false
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,33 @@
* @name Bastion.content-views.controller:FilterDetailsController
*
* @requires $scope
* @requires $q
* @requires translate
* @requires Notification
* @requires Filter
*
* @description
* Handles fetching a filter.
*/
angular.module('Bastion.content-views').controller('FilterDetailsController',
['$scope', 'Filter', function ($scope, Filter) {
['$scope', '$q', 'translate', 'Notification', 'Filter', function ($scope, $q, translate, Notification, Filter) {
$scope.filter = Filter.get({'content_view_id': $scope.$stateParams.contentViewId, filterId: $scope.$stateParams.filterId});

$scope.filter = Filter.get({'content_view_id': $scope.$stateParams.contentViewId, filterId: $scope.$stateParams.filterId});
$scope.updateFilter = function (filter) {
var deferred = $q.defer();

$scope.updateFilter = function (filter) {
filter.$update();
};
filter.$update(function (response) {
deferred.resolve(response);
Notification.setSuccessMessage(translate('Filter Updated - ' + $scope.filter.name));
}, function (response) {
deferred.reject(response);
angular.forEach(response.data.errors, function (errorMessage) {
Notification.setErrorMessage(translate("An error occurred saving the Filter: ") + errorMessage);
});
});

return deferred.promise;
};

}]
);
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
<div data-extend-template="layouts/partials/table.html">
<div data-block="filters">
<div class="checkbox">
<label>
<input type="checkbox"
ng-model="filter.original_module_streams"
ng-change="updateFilter(filter)"/>

<span ng-show="filter.inclusion" translate>
Include all Module Streams with no errata.
</span>

<span ng-show="!filter.inclusion" translate>
Exclude all Module Streams with no errata.
</span>
</label>
</div>
</div>

<div data-block="list-actions">
<button type="button" class="btn btn-primary"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('Controller: FilterDetailsController', function() {
var filter = Filter.get({id: 1});
spyOn(filter, '$update');
$scope.updateFilter(filter);
expect(filter.$update).toHaveBeenCalled();
expect(filter.$update).toHaveBeenCalledWith(jasmine.any(Function), jasmine.any(Function));;
});

});

0 comments on commit 28dce7b

Please sign in to comment.