-
Notifications
You must be signed in to change notification settings - Fork 19
/
setup_errors_presenter.rb
152 lines (127 loc) · 4.44 KB
/
setup_errors_presenter.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
# Copyright (c) [2017-2022] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.
require "yast"
require "yast/i18n"
require "y2storage"
require "y2storage/with_security_policies"
Yast.import "HTML"
module Y2Storage
# Class to represent storage setup errors
class SetupErrorsPresenter
include Yast::I18n
include WithSecurityPolicies
# Constructor
#
# @param setup_checker [SetupChecker]
def initialize(setup_checker)
textdomain "storage"
@setup_checker = setup_checker
end
# HTML represetation of the storage setup errors
#
# @note An empty string is returned when there is no error.
#
# @return [String]
def to_html
errors_html || warnings_html || ""
end
private
# @return [SetupChecker] checker for the current setup
attr_reader :setup_checker
# HTML representation for all warnings
#
# @return [String, nil] nil if there is no warning
def warnings_html
warnings = [
boot_warnings_html,
product_warnings_html,
mount_warnings_html,
security_policy_warnings_html
].compact
return nil if warnings.empty?
warnings.join(Yast::HTML.Newline)
end
# HTML representation for boot warnings
#
# @return [String, nil] nil if there is no boot warning
def boot_warnings_html
warnings = setup_checker.boot_warnings
header = _("The system might not be able to boot:\n")
create_html(header, warnings)
end
# HTML representation for mandatory product warnings
#
# @return [String, nil] nil if there is no product warning
def product_warnings_html
warnings = setup_checker.product_warnings
header = _(
"The system could not work properly because the following product " \
"requirements were not fulfilled:\n"
)
create_html(header, warnings)
end
# HTML representation for warnings about the mount points
#
# @return [String, nil] nil if there is no mount warning
def mount_warnings_html
warnings = setup_checker.mount_warnings
header = _(
"The system could fail to initialize some mount point during boot:\n"
)
create_html(header, warnings)
end
# HTML representation for warnings from the enabled security policy
#
# @return [String, nil] nil if warnings cannot be represented, see {#with_security_policies}
def security_policy_warnings_html
policy = setup_checker.security_policy
failing_rules = setup_checker.security_policy_failing_rules
return nil if policy.nil? || failing_rules.none?
with_security_policies do
require "y2security/security_policies/rule_presenter"
header = format(_("The system does not comply with the %s security policy:"), policy.name)
sorted_rules = failing_rules.sort_by { |r| r.identifiers.first }
warnings = sorted_rules.map { |r| Y2Security::SecurityPolicies::RulePresenter.new(r).to_html }
header + Yast::HTML.List(warnings)
end
end
# HTML representation for fatal booting errors
#
# @return [String, nil] nil if there is no error
def errors_html
errors = setup_checker.errors
# TRANSLATORS
header = _("The system cannot be installed because the following errors were found:\n")
create_html(header, errors)
end
# HTML representation for a set of errors
#
# @note The representation is composed by a header message and the list error messages.
#
# @param header [String] header text
# @param errors [Array<SetupError>] list of errors
#
# @return [String, nil] nil if there is no error
def create_html(header, errors)
return nil if errors.empty?
error_messages = errors.map(&:message)
header + Yast::HTML.List(error_messages)
end
end
end