[node-patches] Change in ovirt-node[master]: tui: Correct password checking

fabiand at fedoraproject.org fabiand at fedoraproject.org
Fri Dec 14 08:33:36 UTC 2012


Fabian Deutsch has uploaded a new change for review.

Change subject: tui: Correct password checking
......................................................................

tui: Correct password checking

Previously the password checking on the security page did not work, this
is fixed now.

Change-Id: Iebe584c81483345750b77a1bb79c66c8a8621814
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/tui/src/ovirt/node/plugins.py
M scripts/tui/src/ovirt/node/setup/security_page.py
M scripts/tui/src/ovirt/node/ui/__init__.py
M scripts/tui/src/ovirt/node/ui/builder.py
M scripts/tui/src/ovirt/node/ui/widgets.py
5 files changed, 53 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/56/10056/1

diff --git a/scripts/tui/src/ovirt/node/plugins.py b/scripts/tui/src/ovirt/node/plugins.py
index ac1225f..6144c8b 100644
--- a/scripts/tui/src/ovirt/node/plugins.py
+++ b/scripts/tui/src/ovirt/node/plugins.py
@@ -284,17 +284,22 @@
         self.logger.debug("Request to discard model changes: %s" % changes)
         self.__changes = {}
 
-    def pending_changes(self, only_effective_changes=True):
+    def pending_changes(self, only_effective_changes=True,
+                        include_invalid=False):
         """Return all changes which happened since the last on_merge call
 
         Args:
             only_effective_changes: Boolean if all or only the effective
                 changes are returned.
+            include_invalid: If the invalid changes should be included
         Returns:
             dict of changes
         """
-        return self.__effective_changes() if only_effective_changes \
-                                          else self.__changes
+        changes = self.__effective_changes() if only_effective_changes \
+                                             else self.__changes
+        if include_invalid:
+            changes.update(self.__invalid_changes)
+        return changes
 
     def is_valid_changes(self):
         """If all changes are valid or not
@@ -384,9 +389,10 @@
 class WidgetsHelper(dict, base.Base):
     """A helper class to handle widgets
     """
-    def __init__(self):
+    def __init__(self, widgets={}):
         super(WidgetsHelper, self).__init__()
         base.Base.__init__(self)
+        self.update(widgets)
 
     def subset(self, paths):
         return [self[p] for p in paths]
@@ -412,4 +418,15 @@
             """Enable or disable all widgets of this group
             """
             self.logger.debug("Enabling widget group: %s" % self)
-            map(lambda w: w.enabled(is_enable), self.widgethelper.subset(self))
+            map(lambda w: w.enabled(is_enable), self.elements())
+
+        def text(self, text):
+            """Enable or disable all widgets of this group
+            """
+            self.logger.debug("Setting text of widget group: %s" % self)
+            map(lambda w: w.set_text(text), self.elements())
+
+        def elements(self):
+            """Return the UI elements of this group
+            """
+            return self.widgethelper.subset(self)
\ No newline at end of file
diff --git a/scripts/tui/src/ovirt/node/setup/security_page.py b/scripts/tui/src/ovirt/node/setup/security_page.py
index d4e95f4..96295af 100644
--- a/scripts/tui/src/ovirt/node/setup/security_page.py
+++ b/scripts/tui/src/ovirt/node/setup/security_page.py
@@ -73,21 +73,27 @@
                 "Confirm Password:")),
         ]
         # Save it "locally" as a dict, for better accessability
-        self._widgets = dict(widgets)
+        self._widgets = plugins.WidgetsHelper(dict(widgets))
 
         page = ui.Page(widgets)
         return page
 
     def on_change(self, changes):
         m = self.model()
-        m.update(self.pending_changes() or {})
+        m.update(self.pending_changes(False, True))
+        m.update(changes)
         effective_model = ChangesHelper(m)
 
         passwd_keys = ["passwd.admin.password",
                        "passwd.admin.password_confirmation"]
+        passwd_widget_group = self._widgets.group(passwd_keys)
         if effective_model.any_key_in_change(passwd_keys):
             passwd, passwdc = effective_model.get_key_values(passwd_keys)
-            if passwd != passwdc:
+            if passwd == passwdc:
+                # Remove all potential error messages
+                map(lambda e: e.valid(True), passwd_widget_group.elements())
+            else:
+                # Throw an error message
                 raise exceptions.InvalidData("Passwords do not match.")
 
     def on_merge(self, effective_changes):
@@ -119,10 +125,15 @@
                 raise exceptions.InvalidData("Passwords do not match")
             passwd = utils.security.Passwd()
 
+            # Create a custom transaction element, because the password
+            # is not handled/saved in the defaults file
             class SetAdminPasswd(utils.Transaction.Element):
+                title = "Setting admin password"
+
                 def commit(self):
                     self.logger.debug("Setting admin password.")
                     passwd.set_password("admin", pw)
+
             txs += [SetAdminPasswd()]
 
         progress_dialog = ui.TransactionProgressDialog(txs, self)
diff --git a/scripts/tui/src/ovirt/node/ui/__init__.py b/scripts/tui/src/ovirt/node/ui/__init__.py
index 3f915fb..0e1c883 100644
--- a/scripts/tui/src/ovirt/node/ui/__init__.py
+++ b/scripts/tui/src/ovirt/node/ui/__init__.py
@@ -174,6 +174,13 @@
         super(Entry, self).__init__(label, enabled)
         self.label = label
         self.align_vertical = align_vertical
+        self.valid(True)
+
+    @Element.signal_change
+    def valid(self, is_valid):
+        if is_valid in [True, False]:
+            self._valid = is_valid
+        return self._valid
 
 
 class PasswordEntry(Entry):
diff --git a/scripts/tui/src/ovirt/node/ui/builder.py b/scripts/tui/src/ovirt/node/ui/builder.py
index 2ebc855..b0f51d4 100644
--- a/scripts/tui/src/ovirt/node/ui/builder.py
+++ b/scripts/tui/src/ovirt/node/ui/builder.py
@@ -143,6 +143,11 @@
 
     item.connect_signal("enabled", on_item_enabled_change_cb)
 
+    def on_item_valid_change_cb(w, v):
+            widget.valid(v)
+
+    item.connect_signal("valid", on_item_valid_change_cb)
+
     def on_widget_value_change(widget, new_value):
         LOGGER.debug("Entry %s changed, calling callback: '%s'" % (widget,
                                                                    path))
diff --git a/scripts/tui/src/ovirt/node/ui/widgets.py b/scripts/tui/src/ovirt/node/ui/widgets.py
index cc56648..f3eab3f 100644
--- a/scripts/tui/src/ovirt/node/ui/widgets.py
+++ b/scripts/tui/src/ovirt/node/ui/widgets.py
@@ -275,10 +275,8 @@
         alignment_widget = urwid.Columns
         if self._align_vertical:
             alignment_widget = urwid.Pile
-        self._columns = alignment_widget([
-                                            self._label_attrmap,
-                                            input_widget
-                                        ])
+        self._columns = alignment_widget([self._label_attrmap,
+                                          input_widget])
 
         self._notice = urwid.Text("")
         self._notice_attrmap = urwid.AttrMap(self._notice,
@@ -309,7 +307,9 @@
         attr_map_label = {None: "plugin.widget.entry.label"}
         attr_map_edit = {None: "plugin.widget.entry"}
         attr_map_linebox = {None: "plugin.widget.entry.frame"}
-        if not is_valid:
+        if is_valid:
+            self.set_notice(None)
+        else:
             attr_map_label = {None: "plugin.widget.entry.label.invalid"}
             attr_map_edit = {None: "plugin.widget.entry.invalid"}
             attr_map_linebox = {None: "plugin.widget.entry.frame.invalid"}


--
To view, visit http://gerrit.ovirt.org/10056
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iebe584c81483345750b77a1bb79c66c8a8621814
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Fabian Deutsch <fabiand at fedoraproject.org>



More information about the node-patches mailing list