From c45c1e7119935c9c91035f96c26605630c8372ba Mon Sep 17 00:00:00 2001 From: Martin Vidner Date: Tue, 19 May 2020 15:35:09 +0200 Subject: [PATCH] Declining/refusal of an addon license means canceling all addons. (bsc#1169577) Without this, an addon is still installed even if its license is declined. In commit 1c7d041f6b3e71dce6a6f6062f10b1d6f0121754, PR https://github.com/yast/yast-registration/pull/440 , the idea was that we can unselect an addon whose license was declined, and proceed with installing the remaining addons. But that does not work out with autoselected addons ( https://github.com/yast/yast-registration/pull/335 https://github.com/yast/yast-registration/pull/338 ) where we take into account the product dependencies. The new solution is to interpret a refusal of a license as the Abort button, which ends installation of ALL selected addons. --- src/lib/registration/clients/inst_scc.rb | 5 ++++- src/lib/registration/ui/addon_eula_dialog.rb | 22 ++++++++++++------- .../registration/ui/addon_eula_dialog_test.rb | 12 +++++----- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/lib/registration/clients/inst_scc.rb b/src/lib/registration/clients/inst_scc.rb index 3310ea128..05ec0ac57 100644 --- a/src/lib/registration/clients/inst_scc.rb +++ b/src/lib/registration/clients/inst_scc.rb @@ -306,7 +306,10 @@ def start_workflow next: "addon_eula" }, "addon_eula" => { - abort: :abort, + # Declining (refusing) any license means :abort is returned. + # We interpret it as aborting the adding of ALL addons so that + # we don't have to deal with their dependencies. + abort: "check", next: "register_addons" }, "register_addons" => { diff --git a/src/lib/registration/ui/addon_eula_dialog.rb b/src/lib/registration/ui/addon_eula_dialog.rb index 0891229b9..d17fddad9 100644 --- a/src/lib/registration/ui/addon_eula_dialog.rb +++ b/src/lib/registration/ui/addon_eula_dialog.rb @@ -48,6 +48,9 @@ def run false ) + # Default: no EULA specified => accepted + eula_ret = :accepted + addons.each do |addon| next unless addon.eula_acceptance_needed? next if addon.registered? @@ -55,10 +58,14 @@ def run log.info "Addon '#{addon.name}' has an EULA at #{addon.eula_url}" eula_ret = accept_eula(addon) - return eula_ret if eula_ret != :next + + # any declined license needs to be handled separately + break if eula_ret != :accepted end - :next + # 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 end private @@ -106,10 +113,10 @@ def setup_eula_dialog(addon, eula_reader, tmpdir) # run the EULA agreement dialog # @param [EulaReader] eula_reader read EULAs - # @return [Symbol] :accepted, :back, :abort, :halt - user input + # @return [Symbol] :accepted, :back, :abort - user input def run_eula_dialog(eula_reader) base_product = false - cancel_action = "refuse" + cancel_action = "abort" ret = Yast::ProductLicense.HandleLicenseDialogRet(arg_ref(eula_reader.licenses), base_product, cancel_action) log.debug "EULA dialog result: #{ret}" @@ -118,20 +125,18 @@ def run_eula_dialog(eula_reader) # ask user to accept an addon EULA # @param [Addon] addon the addon - # @return [Symbol] :back, :abort, :halt + # @return [Symbol] :accepted, :back, :abort def accept_eula(addon) Dir.mktmpdir("extension-eula-") do |tmpdir| return :back unless download_eula(addon, tmpdir) eula_reader = EulaReader.new(tmpdir) license = find_license(addon, eula_reader) - return :next if license && license.accepted? + return :accepted if license && license.accepted? setup_eula_dialog(addon, eula_reader, tmpdir) ret = run_eula_dialog(eula_reader) license.accept! if ret == :accepted - - return :next if [:accepted, :refused].include?(ret) ret end ensure @@ -144,6 +149,7 @@ def display_optional_info(info_file) Yast::InstShowInfo.show_info_txt(info_file) if File.exist?(info_file) end + # @return [Y2Packager::License] def find_license(addon, eula_reader) license_file = eula_reader.licenses[Y2Packager::License::DEFAULT_LANG] return nil unless license_file diff --git a/test/registration/ui/addon_eula_dialog_test.rb b/test/registration/ui/addon_eula_dialog_test.rb index 788301e22..a4751c67c 100644 --- a/test/registration/ui/addon_eula_dialog_test.rb +++ b/test/registration/ui/addon_eula_dialog_test.rb @@ -57,7 +57,7 @@ context "when there are EULA acceptances pending" do let(:addons) { [addon_with_eula, second_addon_with_eula] } - let(:first_dialog_response) { :refused } + let(:first_dialog_response) { :accepted } let(:second_dialog_response) { :accepted } before do @@ -124,15 +124,15 @@ before do allow(Yast::ProductLicense).to receive(:HandleLicenseDialogRet) - .and_return(:refused) + .and_return(:abort) end it "does not set it as accepted" do expect(product_license).to_not receive(:accept!) end - it "returns :next" do - expect(dialog.run).to eq(:next) + it "returns :abort" do + expect(dialog.run).to eq(:abort) end end end @@ -198,8 +198,8 @@ context "when the license was previously accepted" do let(:accepted?) { true } - it "returns :next" do - expect(dialog.send(:accept_eula, addon)).to eq(:next) + it "returns :accepted" do + expect(dialog.send(:accept_eula, addon)).to eq(:accepted) end it "does not show the eula" do