Skip to content

Commit

Permalink
service - return only the configured patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Dec 4, 2023
1 parent 8e48e41 commit 405d3c6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions service/lib/agama/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions service/lib/agama/software/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions service/lib/agama/software/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ class Product
# @return [Array<String>]
attr_accessor :optional_patterns

# Optional user selectable patterns
#
# @return [Array<String>]
attr_accessor :user_patterns

# Product translations.
#
# @example
Expand All @@ -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

Expand Down
4 changes: 4 additions & 0 deletions service/lib/agama/software/product_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 405d3c6

Please sign in to comment.