-
Notifications
You must be signed in to change notification settings - Fork 19
/
addon_eula_dialog.rb
165 lines (140 loc) · 5.47 KB
/
addon_eula_dialog.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
require "yast"
require "registration/eula_downloader"
require "registration/eula_reader"
require "registration/helpers"
require "y2packager/product_license"
module Registration
module UI
# class for displaying and handling the add-on EULA dialog
class AddonEulaDialog
include Yast::Logger
include Yast::I18n
include Yast::UIShortcuts
include Yast
attr_reader :addons
Yast.import "Popup"
Yast.import "ProductLicense"
Yast.import "Report"
Yast.import "Wizard"
Yast.import "InstShowInfo"
# display and run the dialog for accepting the extensions EULAs
# @param selected_addons [Array<Addon>]
def self.run(selected_addons)
dialog = AddonEulaDialog.new(selected_addons)
dialog.run
end
# constructor
# @param selected_addons [Array<Addon>]
def initialize(selected_addons)
textdomain "registration"
@addons = selected_addons
end
# 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(
# dialog title
_("License Agreement"),
Label(_("Downloading Licenses...")),
"",
false,
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)
# any declined license needs to be handled separately
break if eula_ret != :accepted
end
# 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
# download the addon EULAs to a temp dir
# @param [Addon] addon the addon
# @param [String] tmpdir target where to download the files
def download_eula(addon, tmpdir)
Yast::Popup.Feedback(
_("Downloading License Agreement..."),
addon.label
) do
# download the license (with translations)
loader = EulaDownloader.new(addon.eula_url, tmpdir,
insecure: Helpers.insecure_registration)
loader.download
end
true
rescue StandardError => e
log.error "Download failed: #{e.message}: #{e.backtrace}"
# %s is an extension name, e.g. "SUSE Linux Enterprise Software Development Kit"
Yast::Report.Error(_("Downloading the license for\n%s\nfailed.") % addon.label)
return false
end
# prepare data for displaying the EULA dialog
# @param [Addon] addon the addon
# @param [EulaReader] eula_reader read eulas
# @param [String] tmpdir target with the downloaded files
def setup_eula_dialog(addon, eula_reader, tmpdir)
id = "#{addon.label} extension EULA"
Yast::ProductLicense.SetAcceptanceNeeded(id, true)
Yast::ProductLicense.license_file_print = addon.eula_url
# %s is an extension name, e.g. "SUSE Linux Enterprise Software Development Kit"
title = _("%s License Agreement") % addon.label
enable_back = true
Yast::ProductLicense.DisplayLicenseDialogWithTitle(eula_reader.languages, enable_back,
eula_reader.current_language, arg_ref(eula_reader.licenses), id, title)
# display beta warning if present
display_optional_info(File.join(tmpdir, "README.BETA"))
end
# Run the EULA agreement dialog.
# @param [EulaReader] eula_reader read EULAs
# @return [Symbol] :accepted, :back
def run_eula_dialog(eula_reader)
base_product = false
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.
# 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] :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 :accepted if license && license.accepted?
setup_eula_dialog(addon, eula_reader, tmpdir)
ret = run_eula_dialog(eula_reader)
license.accept! if ret == :accepted
ret
end
ensure
Yast::ProductLicense.CleanUp()
end
# read a file if it exists and display it in a popup
# @param info_file [String] the message is read from this file
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
content = Yast::SCR.Read(path(".target.string"), license_file)
return nil unless content
Y2Packager::ProductLicense.find(addon.identifier, content: content)
end
end
end
end