diff --git a/service/lib/agama/config.rb b/service/lib/agama/config.rb index 0e524d648c..0ae3ee2d96 100644 --- a/service/lib/agama/config.rb +++ b/service/lib/agama/config.rb @@ -170,10 +170,10 @@ def merge(config) # @param property [Symbol|String|nil] Property to retrieve of the elements. # # @return [Array] - def arch_elements_from(*keys, property: nil) + def arch_elements_from(*keys, property: nil, default: []) keys.map!(&:to_s) elements = products.dig(*keys) - return [] unless elements.is_a?(Array) + return default unless elements.is_a?(Array) elements.map do |element| if !element.is_a?(Hash) diff --git a/service/lib/agama/software/manager.rb b/service/lib/agama/software/manager.rb index be47087609..68296ab1ef 100644 --- a/service/lib/agama/software/manager.rb +++ b/service/lib/agama/software/manager.rb @@ -214,6 +214,11 @@ def patterns(filtered) patterns = Y2Packager::Resolvable.find({ kind: :pattern }, preload) patterns = patterns.select(&:user_visible) if filtered + # only display the configured patterns + if product.user_patterns + patterns.select! {|p| product.user_patterns.include?(p.name)} + end + patterns end diff --git a/service/lib/agama/software/product.rb b/service/lib/agama/software/product.rb index 24bb8c0b2b..5f2cd72da8 100644 --- a/service/lib/agama/software/product.rb +++ b/service/lib/agama/software/product.rb @@ -73,6 +73,11 @@ class Product # @return [Array] attr_accessor :optional_patterns + # Optional user selectable patterns + # + # @return [Array] + attr_accessor :user_patterns + # Product translations. # # @example @@ -94,6 +99,8 @@ def initialize(id) @optional_packages = [] @mandatory_patterns = [] @optional_patterns = [] + # nil = display all patterns, [] = display none patterns + @user_patterns = nil @translations = {} end diff --git a/service/lib/agama/software/product_builder.rb b/service/lib/agama/software/product_builder.rb index b4ecfeddf8..7ee3d270ca 100644 --- a/service/lib/agama/software/product_builder.rb +++ b/service/lib/agama/software/product_builder.rb @@ -47,6 +47,7 @@ def build product.optional_packages = data[:optional_packages] product.mandatory_patterns = data[:mandatory_patterns] product.optional_patterns = data[:optional_patterns] + product.user_patterns = data[:user_patterns] product.translations = attrs["translations"] || {} end end @@ -79,6 +80,9 @@ def product_data_from_config(id) ), optional_patterns: config.arch_elements_from( id, "software", "optional_patterns", property: :pattern + ), + user_patterns: config.arch_elements_from( + id, "software", "user_patterns", property: :pattern, default: nil ) } end