Class List Method List File List

# Module: Yast::SudoDialogUserInclude

Defined in:
  ../../src/include/sudo/dialog-user.rb

## Instance Method Summary (collapse)

- - (Object) AddEditUserAliasDialog(what)
- - (Object) initialize_sudo_dialog_user(include_target)
- - (Object) RedrawUserAlias(members)
- - (Object) SaveUserAliases

## Instance Method Details

### - (`Object`) AddEditUserAliasDialog(what)

    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
    166
    167
    # File '../../src/include/sudo/dialog-user.rb', line 32

    def AddEditUserAliasDialog(what)
      caption = ""
      ua = Sudo.GetUserAliases2
      it = Ops.get(ua, Sudo.GetItem, {})

      alias_members = []
      name = ""
      items = []
      users = Convert.convert(
        Builtins.merge(Sudo.all_users, Sudo.GetAliasNames("user")),
        :from => "list",
        :to   => "list <string>"
      )

      if what == "Add"
        caption = _("New User Alias")
      elsif what == "Edit"
        alias_members = Ops.get_list(it, "mem", [])
        Builtins.foreach(alias_members) do |member|
          users = Builtins.filter(users) { |user| user != member }
        end
        name = Ops.get_string(it, "name", "")
        caption = _("Existing User Alias")
      end
      users = Builtins.sort(users) { |s1, s2| Ops.less_than(s1, s2) }

      contents = VBox(
        Left(InputField(Id("user_alias_name"), _("Alias Name (in CAPITALS)"))),
        VSpacing(1),
        Table(
          Id("user_alias_members"),
          Opt(:hstretch, :vstretch),
          Header(_("Alias Members")),
          []
        ),
        HBox(
          PushButton(
            Id("add_member"),
            Opt(:key_F3),
            Ops.add(Ops.add(" ", Label.AddButton), " ")
          ),
          PushButton(
            Id("remove_member"),
            Opt(:key_F5),
            Ops.add(Ops.add(" ", Label.DeleteButton), " ")
          ),
          HStretch()
        )
      )

      Wizard.SetContentsButtons(
        caption,
        contents,
        Ops.get_string(@HELPS, "user_alias", ""),
        Label.CancelButton,
        Label.OKButton
      )
      Wizard.HideAbortButton
      UI.ChangeWidget(
        Id("user_alias_name"),
        :ValidChars,
        "_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
      )
      UI.ChangeWidget(Id("user_alias_name"), :Value, name)

      RedrawUserAlias(alias_members)

      ret = nil
      while true
        ret = UI.UserInput
        # next
        if ret == :next
          new_alias = Builtins.toupper(
            Convert.to_string(UI.QueryWidget(Id("user_alias_name"), :Value))
          )
          if new_alias == ""
            Popup.Error(_("Alias name must not be empty."))
            UI.SetFocus(Id("user_alias_name"))
            next
          end
          if name != new_alias
            if Sudo.SearchAlias2(new_alias, Sudo.GetUserAliases2)
              Popup.Error(
                Builtins.sformat(
                  _("Alias with name %1 already exists"),
                  new_alias
                )
              )
              UI.SetFocus(Id("user_alias_name"))
              next
            end
          end
          if alias_members == []
            Popup.Error(_("Alias must have at least one member."))
            UI.SetFocus(Id("user_alias_members"))
            next
          end

          Ops.set(it, "name", new_alias)
          Ops.set(it, "mem", alias_members)
          Sudo.SetUserAlias(Sudo.GetItem, it)
          Sudo.SetModified
          break
          # back
        elsif ret == :back
          break
          # add users
        elsif ret == "add_member"
          new_member = AddUserDialog(users)

          if new_member != ""
            alias_members = Builtins.add(alias_members, new_member)
            users = Builtins.filter(users) { |s| s != new_member }
            RedrawUserAlias(alias_members)
          end
          # delete users
        elsif ret == "remove_member"
          current_item = Convert.to_string(
            UI.QueryWidget(Id("user_alias_members"), :CurrentItem)
          )
          alias_members = Builtins.filter(alias_members) do |s|
            s != current_item
          end
          users = Builtins.add(users, current_item)
          RedrawUserAlias(alias_members)
          # unknown
        else
          Builtins.y2error("unexpected retcode: %1", ret)
          next
        end
      end

      @initial_screen = "user_aliases"
      Wizard.RestoreNextButton
      deep_copy(ret)
    end

### - (`Object`) initialize_sudo_dialog_user(include_target)

    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    # File '../../src/include/sudo/dialog-user.rb', line 5

    def initialize_sudo_dialog_user(include_target)
      Yast.import "UI"
      textdomain "sudo"

      Yast.import "Label"
      Yast.import "Wizard"
      Yast.import "Sudo"
      Yast.import "Report"

      Yast.include include_target, "sudo/complex.rb"
      Yast.include include_target, "sudo/helps.rb"
    end

### - (`Object`) RedrawUserAlias(members)

    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    # File '../../src/include/sudo/dialog-user.rb', line 18

    def RedrawUserAlias(members)
      members = deep_copy(members)
      items = []

      Builtins.foreach(members) do |it|
        items = Builtins.add(items, Item(Id(it), it))
      end

      UI.ChangeWidget(Id("user_alias_members"), :Items, items)
      UI.ChangeWidget(Id("remove_member"), :Enabled, items != [])

      nil
    end

### - (`Object`) SaveUserAliases

    169
    170
    171
    # File '../../src/include/sudo/dialog-user.rb', line 169

    def SaveUserAliases
      :next
    end