Skip to content

Commit

Permalink
Merge pull request #113 from yast/disable_unavailable_extensions
Browse files Browse the repository at this point in the history
Disable unavailable extensions (bnc#883148)
  • Loading branch information
lslezak committed Jun 23, 2014
2 parents 4fe81a5 + fbf3ac6 commit ceddd6a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/lib/registration/addon.rb
Expand Up @@ -110,6 +110,8 @@ def label
def selectable?
# Do not support unregister
return false if registered?
# Do not select not available addons
return false if !available?
# Do not allow to select child without selected or already registered parent
return false if depends_on && !(depends_on.selected? || depends_on.registered?)
# Do not allow to unselect parent if any children is selected
Expand All @@ -118,5 +120,14 @@ def selectable?
return true
end

# is the addon available? SMT may have mirrored only some extensions,
# the not mirrored extensions are marked as not available
# @return [Boolean] true if the addon is available to register
def available?
# explicitly check for false, undefined (nil) means it is available,
# it's only reported by SMT
@pure_addon.available != false
end

end
end
6 changes: 5 additions & 1 deletion src/lib/registration/ui/addon_selection_dialog.rb
Expand Up @@ -118,9 +118,13 @@ def addon_checkbox(addon, extra_spacing)
end

def addon_checkbox_element(addon)
# checkbox label for an unavailable extension
# (%s is an extension name)
label = addon.available? ? addon.label : (_("%s (not available)") % addon.label)

CheckBox(Id(addon.identifier),
Opt(:notify),
addon.label,
label,
addon.selected? || addon.registered?)
end

Expand Down
17 changes: 17 additions & 0 deletions test/addon_spec.rb
Expand Up @@ -151,6 +151,23 @@
child.selected
expect(parent.selectable?).to be_false
end

it "returns false when the addon is not available" do
product = addon_generator("available" => false)
addon = Registration::Addon.new(product)
expect(addon.selectable?).to be_false
end

it "returns true when the addon is available" do
product = addon_generator("available" => true)
addon = Registration::Addon.new(product)
expect(addon.selectable?).to be_true
end

it "returns true when the addon availability is not set" do
expect(addon.selectable?).to be_true
end

end

end
1 change: 1 addition & 0 deletions test/factories.rb
Expand Up @@ -3,6 +3,7 @@

def suse_connect_product_generator(attrs={})
params = {}
params["available"] = attrs["available"] if attrs.has_key?("available")
params['name'] = attrs['name'] || "Product#{rand(100000)}"
params['friendly_name'] = attrs['friendly_name'] || "The best cool #{params['name']}"
params['description'] = attrs['description'] || "Bla bla bla bla!"
Expand Down

0 comments on commit ceddd6a

Please sign in to comment.