Skip to content

Commit

Permalink
Merge pull request #494 from yast/addon-with-refused-license
Browse files Browse the repository at this point in the history
Declining/refusal of an addon license means canceling all addons. (bsc#1169577)
  • Loading branch information
mvidner committed May 28, 2020
2 parents 3c20ade + 990f408 commit 681f07f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 19 deletions.
7 changes: 7 additions & 0 deletions package/yast2-registration.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu May 28 10:50:51 UTC 2020 - Martin Vidner <mvidner@suse.com>

- Declining/refusal of an addon license means canceling all addons.
(bsc#1169577)
- 4.1.26

-------------------------------------------------------------------
Thu Apr 9 12:35:25 UTC 2020 - Stefan Hundhammer <shundhammer@suse.com>

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-registration.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-registration
Version: 4.1.25
Version: 4.1.26
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
28 changes: 18 additions & 10 deletions src/lib/registration/ui/addon_eula_dialog.rb
Expand Up @@ -48,17 +48,23 @@ 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?

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 if any EULA has not been accepted, let the user
# deselect the not accepted extension
eula_ret == :accepted ? :next : eula_ret
end

private
Expand Down Expand Up @@ -104,34 +110,35 @@ def setup_eula_dialog(addon, eula_reader, tmpdir)
display_optional_info(File.join(tmpdir, "README.BETA"))
end

# run the EULA agreement dialog
# Run the EULA agreement dialog.
# @param [EulaReader] eula_reader read EULAs
# @return [Symbol] :accepted, :back, :abort, :halt - user input
# @return [Symbol] :accepted, :back
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)
ret = :back if ret == :abort
log.debug "EULA dialog result: #{ret}"
ret
end

# ask user to accept an addon EULA
# Ask user to accept an addon EULA.
# Declining (refusing) the license is translated into Back
# which will fit nicely from the caller's point of view.
# @param [Addon] addon the addon
# @return [Symbol] :back, :abort, :halt
# @return [Symbol] :accepted, :back
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
Expand All @@ -144,6 +151,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
Expand Down
16 changes: 8 additions & 8 deletions test/registration/ui/addon_eula_dialog_test.rb
Expand Up @@ -53,7 +53,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
Expand All @@ -72,8 +72,8 @@
context "and the user wants to abort" do
let(:first_dialog_response) { :abort }

it "returns :abort" do
expect(subject.run).to eq(:abort)
it "returns :back anyway" do
expect(subject.run).to eq(:back)
end
end

Expand Down Expand Up @@ -120,15 +120,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 :back" do
expect(dialog.run).to eq(:back)
end
end
end
Expand Down Expand Up @@ -194,8 +194,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
Expand Down

0 comments on commit 681f07f

Please sign in to comment.