示例#1
0
    def action(self):
        connections = userdb.load_connection_config(lock=True)
        if html.request.has_var("_delete"):
            index = int(html.request.var("_delete"))
            connection = connections[index]
            c = wato_confirm(
                _("Confirm deletion of LDAP connection"),
                _("Do you really want to delete the LDAP connection <b>%s</b>?"
                  ) % (connection["id"]))
            if c:
                self._add_change(
                    "delete-ldap-connection",
                    _("Deleted LDAP connection %s") % (connection["id"]))
                del connections[index]
                userdb.save_connection_config(connections)
            elif c is False:
                return ""
            else:
                return

        elif html.request.has_var("_move"):
            if not html.check_transaction():
                return

            from_pos = html.get_integer_input("_move")
            to_pos = html.get_integer_input("_index")
            connection = connections[from_pos]
            self._add_change(
                "move-ldap-connection",
                _("Changed position of LDAP connection %s to %d") %
                (connection["id"], to_pos))
            del connections[from_pos]  # make to_pos now match!
            connections[to_pos:to_pos] = [connection]
            userdb.save_connection_config(connections)
示例#2
0
    def action(self):
        if not html.check_transaction():
            return

        vs = self._valuespec()
        self._connection_cfg = vs.from_html_vars("connection")
        vs.validate_value(self._connection_cfg, "connection")

        if self._new:
            self._connections.insert(0, self._connection_cfg)
            self._connection_id = self._connection_cfg["id"]
        else:
            self._connection_cfg["id"] = self._connection_id
            self._connections[self._connection_nr] = self._connection_cfg

        if self._new:
            log_what = "new-ldap-connection"
            log_text = _("Created new LDAP connection")
        else:
            log_what = "edit-ldap-connection"
            log_text = _("Changed LDAP connection %s") % self._connection_id
        self._add_change(log_what, log_text)

        userdb.save_connection_config(self._connections)
        config.user_connections = self._connections  # make directly available on current page
        if html.request.var("_save"):
            return "ldap_config"
        else:
            # Fix the case where a user hit "Save & Test" during creation
            html.request.set_var('id', self._connection_id)