[node-patches] Change in ovirt-node[master]: ui: Fix password validation on several pages

fabiand at fedoraproject.org fabiand at fedoraproject.org
Fri Feb 22 12:18:08 UTC 2013


Fabian Deutsch has uploaded a new change for review.

Change subject: ui: Fix password validation on several pages
......................................................................

ui: Fix password validation on several pages

Change-Id: Ib8736cffa3aedfc0561bbda8cc94dd28caece693
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/tui/src/ovirt/node/installer/password_page.py
M scripts/tui/src/ovirt/node/plugins.py
M scripts/tui/src/ovirt/node/setup/security_page.py
M scripts/tui/src/ovirt/node/setup/snmp_page.py
4 files changed, 30 insertions(+), 38 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/12/12312/1

diff --git a/scripts/tui/src/ovirt/node/installer/password_page.py b/scripts/tui/src/ovirt/node/installer/password_page.py
index 2f3e2d5..c2e1f6f 100644
--- a/scripts/tui/src/ovirt/node/installer/password_page.py
+++ b/scripts/tui/src/ovirt/node/installer/password_page.py
@@ -18,8 +18,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301, USA.  A copy of the GNU General Public License is
 # also available at http://www.gnu.org/copyleft/gpl.html.
-from ovirt.node import plugins, ui, valid
-from ovirt.node.plugins import Validator
+from ovirt.node import plugins, ui, exceptions
 
 """
 Password page of the installer
@@ -33,16 +32,13 @@
         return "Console Password"
 
     def rank(self):
-        return 50
+        return 15
 
     def model(self):
         return self._model or {}
 
     def validators(self):
-        return {"root.password_confirmation":
-                Validator.SameAsIn(self, "root.password", "Password") |
-                valid.Empty()
-                }
+        return {}
 
     def ui_content(self):
         ws = [ui.Header("header[0]",
@@ -60,8 +56,15 @@
         return page
 
     def on_change(self, changes):
-        if changes.contains_any(["root.password_confirmation"]):
+        if changes.contains_any(["root.password",
+                                 "root.password_confirmation"]):
             self._model.update(changes)
+            if self._model.get("root.password", "") != \
+                self._model.get("root.password_confirmation", ""):
+                raise exceptions.InvalidData("Passwords must be the same.")
+            else:
+                self.widgets["root.password"].valid(True)
+                self.widgets["root.password_confirmation"].valid(True)
 
     def on_merge(self, effective_changes):
         changes = self.pending_changes(False)
diff --git a/scripts/tui/src/ovirt/node/plugins.py b/scripts/tui/src/ovirt/node/plugins.py
index 3ed9da4..494c035 100644
--- a/scripts/tui/src/ovirt/node/plugins.py
+++ b/scripts/tui/src/ovirt/node/plugins.py
@@ -503,20 +503,3 @@
             """Return the UI elements of this group
             """
             return self.uielements.subset(self)
-
-
-class Validator:
-    class SameAsIn(valid.Validator):
-        """Validator to validate a value against the value from other paths
-        """
-        def __init__(self, plugin, other_path, other_name):
-            self._plugin = plugin
-            self._paths = [other_path]
-            self.description = "the same value as field '%s'" % other_name
-            super(Validator.SameAsIn, self).__init__()
-
-        def validate(self, value):
-            all_changes = {p: None for p in self._paths}
-            all_changes.update(self._plugin.pending_changes(False, True))
-            return all((v == value for path, v in all_changes.items()
-                        if path in self._paths))
diff --git a/scripts/tui/src/ovirt/node/setup/security_page.py b/scripts/tui/src/ovirt/node/setup/security_page.py
index 39acaf3..6265306 100644
--- a/scripts/tui/src/ovirt/node/setup/security_page.py
+++ b/scripts/tui/src/ovirt/node/setup/security_page.py
@@ -49,15 +49,11 @@
         return model
 
     def validators(self):
-        same_as_password = plugins.Validator.SameAsIn(self,
-                                                      "passwd.admin.password",
-                                                      "Password")
         number_or_empty = valid.Number(bounds=[0, None]) | \
             valid.Empty()
 
         return {"strongrng.num_bytes": number_or_empty,
-                "passwd.admin.password": valid.Text(),
-                "passwd.admin.password_confirmation": same_as_password,
+                "passwd.admin.password": valid.Text()
                 }
 
     def ui_content(self):
@@ -77,7 +73,14 @@
         return page
 
     def on_change(self, changes):
-        pass
+        if changes.contains_any(["passwd.admin.password",
+                                 "passwd.admin.password_confirmation"]):
+            if self._model.get("passwd.admin.password", "") != \
+                self._model.get("passwd.admin.password_confirmation", ""):
+                raise exceptions.InvalidData("Passwords must be the same.")
+            else:
+                self.widgets["passwd.admin.password"].valid(True)
+                self.widgets["passwd.admin.password_confirmation"].valid(True)
 
     def on_merge(self, effective_changes):
         self.logger.debug("Saving security page")
diff --git a/scripts/tui/src/ovirt/node/setup/snmp_page.py b/scripts/tui/src/ovirt/node/setup/snmp_page.py
index 03e1c1d..397ba1c 100644
--- a/scripts/tui/src/ovirt/node/setup/snmp_page.py
+++ b/scripts/tui/src/ovirt/node/setup/snmp_page.py
@@ -18,7 +18,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301, USA.  A copy of the GNU General Public License is
 # also available at http://www.gnu.org/copyleft/gpl.html.
-from ovirt.node import plugins, valid, ui, utils
+from ovirt.node import plugins, valid, ui, utils, exceptions
 from ovirt.node.config import defaults
 from ovirt.node.plugins import Changeset
 
@@ -50,11 +50,7 @@
         return model
 
     def validators(self):
-        same_as_password = plugins.Validator.SameAsIn(self,
-                                                      "snmp.password",
-                                                      "Password")
-        return {"snmp.password": valid.Text(),
-                "snmp.password_confirmation": same_as_password,
+        return {"snmp.password": valid.Text()
                 }
 
     def ui_content(self):
@@ -72,7 +68,14 @@
         return page
 
     def on_change(self, changes):
-        pass
+        if changes.contains_any(["snmp.password",
+                                 "snmp.password_confirmation"]):
+            if self._model.get("snmp.password", "") != \
+                self._model.get("snmp.password_confirmation", ""):
+                raise exceptions.InvalidData("Passwords must be the same.")
+            else:
+                self.widgets["snmp.password"].valid(True)
+                self.widgets["snmp.password_confirmation"].valid(True)
 
     def on_merge(self, effective_changes):
         self.logger.debug("Saving SNMP page")


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib8736cffa3aedfc0561bbda8cc94dd28caece693
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