Skip to content

Commit

Permalink
Merge efe319f into f3d621e
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed Jul 1, 2019
2 parents f3d621e + efe319f commit 67c4225
Show file tree
Hide file tree
Showing 7 changed files with 356 additions and 24 deletions.
6 changes: 6 additions & 0 deletions package/yast2-registration.changes
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Fri Jun 14 07:15:21 UTC 2019 - David Diaz <dgonzalez@suse.com>

- Do not abort when an addon license is refused (bsc#1114018).
- 3.3.0

-------------------------------------------------------------------
Mon Feb 18 13:11:12 UTC 2019 - lslezak@suse.cz

Expand Down
6 changes: 3 additions & 3 deletions package/yast2-registration.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-registration
Version: 3.2.18
Version: 3.3.0
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand All @@ -44,8 +44,8 @@ Requires: SUSEConnect >= 0.2.37

Requires: yast2-slp >= 3.1.9
Requires: yast2-add-on >= 3.1.8
# packager/product_patterns.rb
Requires: yast2-packager >= 3.1.95
# Packager ProductLicense#HandleLicenseDialogRet allowing "refuse" action
Requires: yast2-packager >= 3.3.1
Requires: yast2-update >= 3.1.36

BuildRequires: yast2 >= 3.1.26
Expand Down
8 changes: 3 additions & 5 deletions src/clients/inst_scc.rb
Expand Up @@ -135,9 +135,6 @@ def select_addons
# FIXME: available_addons is called just to fill cache with popup
return :cancel if get_available_addons == :cancel

# FIXME: workaround to reference between old way and new storage in Addon metaclass
@selected_addons = Registration::Addon.selected
::Registration::Storage::InstallationOptions.instance.selected_addons = @selected_addons
Registration::UI::AddonSelectionRegistrationDialog.run(@registration)
end

Expand All @@ -161,7 +158,8 @@ def get_available_addons
# back returns directly to the extensions selection
def register_addons
return false if init_registration == :cancel
ret = registration_ui.register_addons(@selected_addons, @known_reg_codes)

ret = registration_ui.register_addons(Registration::Addon.to_register, @known_reg_codes)
ret = :extensions if ret == :back
ret
end
Expand Down Expand Up @@ -204,7 +202,7 @@ def registration_check

# display EULAs for the selected addons
def addon_eula
::Registration::UI::AddonEulaDialog.run(@selected_addons)
::Registration::UI::AddonEulaDialog.run(Registration::Addon.selected)
end

# remember the user entered values so they can be stored to the AutoYast
Expand Down
38 changes: 37 additions & 1 deletion src/lib/registration/addon.rb
Expand Up @@ -64,6 +64,20 @@ def selected
@selected ||= []
end

# Returns only those selected addons with accepted EULA
#
# @return [Array<Addon>]
def accepted
selected.reject(&:eula_refused?)
end

# Returns only those selected addons with accepted EULA but pending to be registered
#
# @return [Array<Addon>]
def to_register
accepted - registered
end

# return add-ons which are registered but not installed in the system
# and are available to install
# @return [Array<Addon>] the list of add-ons
Expand Down Expand Up @@ -105,9 +119,11 @@ def create_addon_with_deps(root)

extend Forwardable

attr_reader :children
attr_reader :children, :eula_accepted
attr_accessor :depends_on, :regcode

alias_method :eula_accepted?, :eula_accepted

# delegate methods to underlaying suse connect object
def_delegators :@pure_addon,
:arch,
Expand All @@ -128,6 +144,7 @@ def create_addon_with_deps(root)
# @param pure_addon [SUSE::Connect::Product] a pure add-on from the registration server
def initialize(pure_addon)
@pure_addon = pure_addon
@eula_accepted = false
@children = []
end

Expand Down Expand Up @@ -231,5 +248,24 @@ def matches_remote_product?(remote_product)
send(attr) == remote_product.send(attr)
end
end

# Set the EULA as accepted
def accept_eula
@eula_accepted = true
end

# Whether the eula has been refused
#
# @return [Boolean] true if EULA acceptance was required but refused; false otherwise
def eula_refused?
eula_acceptance_needed? && !eula_accepted
end

# Whether the EULA acceptance is required
#
# @return [Boolean] true if a not empty EULA url is present; false otherwise
def eula_acceptance_needed?
!eula_url.to_s.strip.empty?
end
end
end
32 changes: 17 additions & 15 deletions src/lib/registration/ui/addon_eula_dialog.rb
Expand Up @@ -35,7 +35,8 @@ def initialize(selected_addons)
@addons = selected_addons
end

# display the EULA for each extension and wait for a button click
# Display the EULA for each extension and wait for a button click
#
# @return [Symbol] user input (:next, :back, :abort, :halt)
def run
Yast::Wizard.SetContents(
Expand All @@ -47,22 +48,17 @@ def run
false
)

# Default: no EULA specified => accepted
eula_ret = :accepted

addons.each do |addon|
next unless addon.eula_url && !addon.eula_url.empty?
next unless addon.eula_acceptance_needed?
next if addon.registered?

log.info "Addon '#{addon.name}' has an EULA at #{addon.eula_url}"
eula_ret = accept_eula(addon)
result = accept_eula(addon)

# any declined license needs to be handled separately
break if eula_ret != :accepted
return result unless result == :next
end

# go back or abort if any EULA has not been accepted, let the user
# deselect the not accepted extension
eula_ret == :accepted ? :next : eula_ret
:next
end

private
Expand Down Expand Up @@ -116,23 +112,29 @@ def setup_eula_dialog(addon, eula_reader, tmpdir)
# @return [Symbol] :accepted, :back, :abort, :halt - user input
def run_eula_dialog(eula_reader)
base_product = false
cancel_action = "abort"
cancel_action = "refuse"
ret = Yast::ProductLicense.HandleLicenseDialogRet(arg_ref(eula_reader.licenses),
base_product, cancel_action)
log.debug "EULA dialog result: #{ret}"

ret
end

# ask user to accept an addon EULA
# @param [Addon] addon the addon
# @return [Symbol] :accepted, :back, :abort, :halt
# @return [Symbol] :next, :back, :abort, :halt
def accept_eula(addon)
Dir.mktmpdir("extension-eula-") do |tmpdir|
return :back unless download_eula(addon, tmpdir)
eula_reader = EulaReader.new(tmpdir)

eula_reader = EulaReader.new(tmpdir)
setup_eula_dialog(addon, eula_reader, tmpdir)
run_eula_dialog(eula_reader)

result = run_eula_dialog(eula_reader)
addon.accept_eula if result == :accepted

return :next if [:accepted, :refused].include?(result)
result
end
ensure
Yast::ProductLicense.CleanUp()
Expand Down
161 changes: 161 additions & 0 deletions test/addon_spec.rb
Expand Up @@ -85,6 +85,97 @@
end
end

describe ".accepted" do
let(:eula_url) { "http://example.eula.url" }
let(:params) { { "eula_url" => eula_url } }
let(:wo_eula) { Registration::Addon.new(addon_generator) }
let(:refused) { Registration::Addon.new(addon_generator(params)) }
let(:accepted) { Registration::Addon.new(addon_generator(params)) }
let(:not_selected) { Registration::Addon.new(addon_generator(params)) }
let(:registration) do
double(
get_addon_list: [wo_eula, refused, accepted, not_selected]
)
end

before do
wo_eula.selected
refused.selected
accepted.selected

accepted.accept_eula
not_selected.accept_eula
end

it "returns a collection" do
expect(described_class.accepted).to be_a(Array)
end

it "includes selected addons w/o required EULA" do
expect(described_class.accepted).to include(wo_eula)
end

it "includes selected addons with accepted EULA" do
expect(described_class.accepted).to include(accepted)
end

it "does not includes selected addons with refused EULA" do
expect(described_class.accepted).to_not include(refused)
end

it "does not includes not selected addons" do
expect(described_class.accepted).to_not include(not_selected)
end
end

describe ".to_register" do
let(:eula_url) { "http://example.eula.url" }
let(:params) { { "eula_url" => eula_url } }
let(:wo_eula) { Registration::Addon.new(addon_generator) }
let(:refused) { Registration::Addon.new(addon_generator(params)) }
let(:accepted) { Registration::Addon.new(addon_generator(params)) }
let(:registered) { Registration::Addon.new(addon_generator(params)) }
let(:not_selected) { Registration::Addon.new(addon_generator(params)) }
let(:available_addons) { [wo_eula, refused, accepted, registered, not_selected] }
let(:registration) do
double(
get_addon_list: available_addons
)
end

before do
available_addons.each(&:selected)

accepted.accept_eula
registered.accept_eula
registered.registered
end

it "returns a collection" do
expect(described_class.accepted).to be_a(Array)
end

it "includes selected addons w/o required EULA" do
expect(described_class.accepted).to include(wo_eula)
end

it "includes selected addons with accepted EULA" do
expect(described_class.accepted).to include(accepted)
end

it "does not include selected addons with refused EULA" do
expect(described_class.to_register).to_not include(refused)
end

it "does not includes not selected addons" do
expect(described_class.accepted).to_not include(not_selected)
end

it "does not include already registered addons" do
expect(described_class.to_register).to_not include(registered)
end
end

describe ".registered" do
it "returns array of already registered addons" do
expect(Registration::Addon.registered).to be_a(Array)
Expand Down Expand Up @@ -130,6 +221,76 @@
end
end

describe "#accept_eula" do
it "sets EULA as accepted" do
addon.accept_eula

expect(addon.eula_accepted).to eq(true)
end
end

describe "#eula_refused?" do
context "when EULA acceptance is not required" do
before do
allow(addon).to receive(:eula_acceptance_needed?).and_return(false)
end

it "returns false" do
expect(addon.eula_refused?).to eq(false)
end
end

context "when EULA acceptance is required" do
before do
allow(addon).to receive(:eula_acceptance_needed?).and_return(true)
end

context "and the license was accepted" do
it "returns false" do
addon.accept_eula

expect(addon.eula_refused?).to eq(false)
end
end

context "and the license was not accepted" do
it "returns true" do
expect(addon.eula_refused?).to eq(true)
end
end
end
end

context "#eula_acceptance_needed" do
let(:eula_url) { nil }

before do
allow(addon).to receive(:eula_url).and_return(eula_url)
end

context "when the EULA URL is nil" do
it "returns false" do
expect(addon.eula_acceptance_needed?).to eq(false)
end
end

context "when there is an empty EULA url" do
let(:eula_url) { " " }

it "returns false" do
expect(addon.eula_acceptance_needed?).to eq(false)
end
end

context "when there is a NOT empty EULA url" do
let(:eula_url) { "http://example.eula.url" }

it "returns true" do
expect(addon.eula_acceptance_needed?).to eq(true)
end
end
end

describe "#unregistered" do
it "marks addon as unregistered" do
Registration::Addon.registered << addon
Expand Down

0 comments on commit 67c4225

Please sign in to comment.