Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the user visible patterns configurable, added MicroOS products #916

Merged
merged 15 commits into from
Dec 6, 2023
Merged
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: [])
lslezak marked this conversation as resolved.
Show resolved Hide resolved
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
lslezak marked this conversation as resolved.
Show resolved Hide resolved
@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
Loading