• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

yast / yast-security / 7348705966

28 Dec 2023 02:50PM UTC coverage: 39.237% (-0.3%) from 39.568%
7348705966

Pull #157

github

web-flow
Merge 7db7fc531 into a9a6f29de
Pull Request #157: Update rubocop

68 of 442 new or added lines in 17 files covered. (15.38%)

40 existing lines in 4 files now uncovered.

1378 of 3512 relevant lines covered (39.24%)

5.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/include/security/routines.rb
1
# ------------------------------------------------------------------------------
2
# Copyright (c) 2006-2012 Novell, Inc. All Rights Reserved.
3
#
4
#
5
# This program is free software; you can redistribute it and/or modify it under
6
# the terms of version 2 of the GNU General Public License as published by the
7
# Free Software Foundation.
8
#
9
# This program is distributed in the hope that it will be useful, but WITHOUT
10
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License along with
14
# this program; if not, contact Novell, Inc.
15
#
16
# To contact Novell about this file by physical or electronic mail, you may find
17
# current contact information at www.novell.com.
18
# ------------------------------------------------------------------------------
19

20
# File:        include/security/routines.ycp
21
# Module:        Security configuration
22
# Summary:        Routines
23
# Authors:        Michal Svec <msvec@suse.cz>
24
#
25
# $Id$
26
#
27
# These functions are used for the user interface creation
28
# and interaction.
29
# <pre>
30
# Usage:
31
#   include "security/ui.ycp";
32
#   map WIDGETS = CallFunction(`your_widgets());
33
# </pre>
34
module Yast
×
35
  module SecurityRoutinesInclude
×
36
    def initialize_security_routines(include_target)
×
37
      Yast.import "UI"
×
38

39
      textdomain "security"
×
40

41
      Yast.import "Popup"
×
42
      Yast.import "Security"
×
43

44
      Yast.include include_target, "security/widgets.rb"
×
45
    end
×
46

47
    # Vertical separator
48
    # @return vertical separator
49
    def VSeparator
×
50
      VSpacing(Opt(:vstretch), 0.1)
×
51
    end
×
52

53
    # Horizontal separator
54
    # @return horizontal separator
55
    def HSeparator
×
56
      HSpacing(Opt(:hstretch), 0.1)
×
57
    end
×
58

59
    # Return a widget from the WIDGETS map created acording to the ID.
60
    # @param [String] widget_id security setting identifier
61
    # @return created widget
62
    # @see <a href="widgets.html">widgets.ycp</a>
NEW
63
    def settings2widget(widget_id)
×
NEW
64
      m = Ops.get_map(@WIDGETS, widget_id, {})
×
65
      label = Ops.get_string(m, "Label", "")
×
66
      widget = Ops.get_string(m, "Widget", "")
×
NEW
67
      value = Ops.get(Security.Settings, widget_id, "")
×
68
      minval = Ops.get_integer(m, "MinValue", 0)
×
69
      maxval = Ops.get_integer(m, "MaxValue", 2147483647)
×
70

71
      # "Widget" == "CheckBox"
72
      if widget == "CheckBox"
×
73
        enabled = false
×
74
        enabled = true if value == "yes"
×
NEW
75
        chbox = CheckBox(Id(widget_id), label, enabled)
×
76
        if Ops.get_string(m, "Notify", "no") == "yes"
×
NEW
77
          chbox = CheckBox(Id(widget_id), Opt(:notify), label, enabled)
×
78
        end
×
79
        return VBox(Left(chbox), VSeparator())
×
80
      end
×
81

82
      # "Widget" == "TextEntry"
83
      if widget == "TextEntry"
×
NEW
84
        return VBox(Left(TextEntry(Id(widget_id), label, value)), VSeparator())
×
85
      end
×
86

87
      # "Widget" == "IntField"
88
      if widget == "IntField"
×
89
        intval = Builtins.tointeger(value)
×
NEW
90
        intval = 0 if intval.nil?
×
91
        return VBox(
×
NEW
92
          Left(IntField(Id(widget_id), label, minval, maxval, intval)),
×
93
          VSeparator()
×
94
        )
×
95
      end
×
96

97
      # "Widget" == "???"
98
      if widget != "ComboBox"
×
99
        Builtins.y2error("Unknown widget: %1", widget)
×
100
        return VSeparator()
×
101
      end
×
102

103
      # "Widget" == "ComboBox"
104
      li = Ops.get_list(m, "Options", [])
×
105
      combo = []
×
106
      i = 0
×
107
      selected = false
×
108

109
      while Ops.less_than(i, Builtins.size(li))
×
110
        # string|list it
111
        Builtins.y2debug("li=%1 (%2)", li, i)
×
112
        it = Ops.get(li, i)
×
NEW
113
        it = "" if it.nil?
×
114
        Builtins.y2debug("it=%1", it)
×
115
        id_t = ""
×
116
        id_s = ""
×
117
        if Ops.is_string?(it)
×
118
          id_t = Convert.to_string(it)
×
119
          id_s = Convert.to_string(it)
×
120
        else
×
NEW
121
          it_list = Convert.convert(it, from: "any", to: "list <string>")
×
122

123
          id_t = Ops.get(it_list, 0, "")
×
124
          id_s = Ops.get(it_list, 1, "")
×
125
        end
×
126
        if value == id_t
×
127
          combo = Builtins.add(combo, Item(Id(id_t), id_s, true))
×
128
          selected = true
×
129
        else
×
130
          combo = Builtins.add(combo, Item(Id(id_t), id_s))
×
131
        end
×
132
        i = Ops.add(i, 1)
×
133
      end
×
134
      if !selected && Ops.get_string(m, "Editable", "no") == "yes"
×
135
        combo = Builtins.add(combo, Item(Id(value), value, true))
×
136
      end
×
137

138
      opt_t = nil
×
139
      opt_t = Opt(:editable) if Ops.get_string(m, "Editable", "no") == "yes"
×
140
      if Ops.get_string(m, "Notify", "no") == "yes"
×
NEW
141
        opt_t = opt_t.nil? ? Opt(:notify) : Builtins.add(opt_t, :notify)
×
142
      end
×
NEW
143
      combobox = if opt_t.nil?
×
NEW
144
        ComboBox(Id(widget_id), label, combo)
×
145
      else
×
NEW
146
        ComboBox(Id(widget_id), opt_t, label, combo)
×
147
      end
×
148

149
      VBox(Left(combobox), VSeparator())
×
150
    end
×
151

152
    # Query the widget with `id(id) for its `Value
153
    # @param [String] id security setting identifier
NEW
154
    def widget2settings(id)
×
NEW
155
      ret = UI.QueryWidget(Id(id), :Value)
×
156
      new = ""
×
157
      if Ops.is_boolean?(ret)
×
NEW
158
        new = ret ? "yes" : "no"
×
159
      elsif Ops.is_integer?(ret)
×
160
        new = Builtins.sformat("%1", ret)
×
161
      elsif Ops.is_string?(ret)
×
162
        new = Convert.to_string(ret)
×
163
      else
×
164
        Builtins.y2error("Unknown widget type: %1", ret)
×
165
        new = nil
×
166
      end
×
167

NEW
168
      if !new.nil? && Ops.get(Security.Settings, id, "") != new
×
169
        Builtins.y2milestone(
×
170
          "Setting modified (%1): %2 -> %3)",
×
NEW
171
          id,
×
NEW
172
          Ops.get(Security.Settings, id, ""),
×
173
          new
×
174
        )
×
NEW
175
        Ops.set(Security.Settings, id, new)
×
176
        Security.modified = true
×
177
      end
×
178

179
      nil
×
180
    end
×
181

182
    # Frame with spacings
183
    # @param [Float] f1 horizontal spacing
184
    # @param [Float] f2 vertical spacing
185
    # @param [String] label frame label
186
    # @param [Yast::Term] content frame contents
187
    # @return frame with contents
NEW
188
    def XFrame(f1, f2, label, content)
×
189
      Frame(
×
NEW
190
        label,
×
NEW
191
        HBox(HSpacing(f1), VBox(VSpacing(f2), content, VSpacing(f2)), HSpacing(f1))
×
192
      )
×
193
    end
×
194

195
    # Check if minimum is less than maximum in the widget
196
    # @param [String] minID ID os the minimum widget
197
    # @param [String] maxID ID os the maximum widget
198
    # @return true or false
199
    def checkMinMax(minID, maxID)
×
200
      min = UI.QueryWidget(Id(minID), :Value)
×
201
      max = UI.QueryWidget(Id(maxID), :Value)
×
NEW
202
      if (Ops.is_integer?(min) || Ops.is_float?(min)) &&
×
NEW
203
          (Ops.is_integer?(max) || Ops.is_float?(max)) &&
×
NEW
204
          Ops.less_or_equal(min, max)
×
NEW
205
        return true
×
206
      end
×
207

208
      false
×
209
    end
×
210

211
    # If modified, ask for confirmation
212
    # @return true if abort is confirmed
213
    def ReallyAbort
×
214
      !Security.Modified || Popup.ReallyAbort(true)
×
215
    end
×
216
  end
×
217
end
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc