[node-patches] Change in ovirt-node[master]: [DRAFT] setup: Fix security page password validation

fabiand at fedoraproject.org fabiand at fedoraproject.org
Mon May 27 08:59:33 UTC 2013


Fabian Deutsch has uploaded a new change for review.

Change subject: [DRAFT] setup: Fix security page password validation
......................................................................

[DRAFT] setup: Fix security page password validation

Previousl ythe password validation was broken on the security page. Now
it's fixed.

Change-Id: Ib6b8ff2d44d390c36e9fddfde2c501f02d7c5012
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M src/ovirt/node/base.py
M src/ovirt/node/plugins.py
M src/ovirt/node/setup/core/security_page.py
3 files changed, 29 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/79/15079/1

diff --git a/src/ovirt/node/base.py b/src/ovirt/node/base.py
index 5d6d12f..5f3bba2 100644
--- a/src/ovirt/node/base.py
+++ b/src/ovirt/node/base.py
@@ -30,7 +30,6 @@
     """Base class for all objects.
     With a logger and a simple signaling mechanism - see Gtk+
     """
-
     @property
     def logger(self):
         """Logger."""
diff --git a/src/ovirt/node/plugins.py b/src/ovirt/node/plugins.py
index 642863d..4c2f9a3 100644
--- a/src/ovirt/node/plugins.py
+++ b/src/ovirt/node/plugins.py
@@ -19,7 +19,7 @@
 # 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 base, exceptions, ui
-import imp
+from ovirt.node.exceptions import InvalidData
 import logging
 import pkgutil
 
@@ -308,18 +308,26 @@
 
         self.logger.debug("Passing UI change to callback on_change: %s" %
                           change)
+
         try:
             if self.validate_changes:
                 self.validate(change)
             self.on_change(change)
-        except exceptions.InvalidData:
+        except InvalidData:
+            self.__invalid_changes.update(change)
             self.on_valid(False)
             raise
+
+        self.__invalid_changes.drop(change.keys())
+        self.__add_change(change)
+        self.on_valid(True)
+
+        return True
+
+    def __add_change(self, change):
         self.__changes.update(change)
         self.logger.debug("Sum of all UI changes up to now: %s" %
                           self.__changes)
-        self.on_valid(True)
-        return True
 
     def _on_ui_save(self):
         """Called when data should be saved
@@ -352,6 +360,7 @@
         if successfull_merge:
             self.logger.info("Changes were merged successfully")
             self.__changes = {}
+            self.__invalid_changes = {}
         else:
             self.logger.info("Changes were not merged.")
 
diff --git a/src/ovirt/node/setup/core/security_page.py b/src/ovirt/node/setup/core/security_page.py
index 1972715..d0a3190 100644
--- a/src/ovirt/node/setup/core/security_page.py
+++ b/src/ovirt/node/setup/core/security_page.py
@@ -18,8 +18,9 @@
 # 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 utils, plugins, ui, valid, exceptions
+from ovirt.node import utils, plugins, ui, valid
 from ovirt.node.config import defaults
+from ovirt.node.exceptions import InvalidData
 from ovirt.node.plugins import Changeset
 
 """
@@ -28,8 +29,6 @@
 
 
 class Plugin(plugins.NodePlugin):
-    _model = {}
-
     def name(self):
         return "Security"
 
@@ -72,15 +71,24 @@
         return page
 
     def on_change(self, changes):
+        # We need to also retrieve the invalid changes, b/c e.g. the pw field
+        # is invalid (and so th elast change which happened in the pw field)
+        # as long as the pw_confirm field isn't populated with the same value.
+        all_changes = self.pending_changes(only_effective_changes=False,
+                                           include_invalid=True)
+        model = self.model()
+        model.update(all_changes)
+        model.update(changes)
+
         if changes.contains_any(["passwd.admin.password",
                                  "passwd.admin.password_confirmation"]):
-            self._model.update(changes)
-            model = self._model
+
             admin_pw = model.get("passwd.admin.password", "")
-            admin_pw_conf = model.get("passwd.admin.password_confirmation", "")
+            admin_pw_conf = \
+                model.get("passwd.admin.password_confirmation", "")
 
             if admin_pw != admin_pw_conf:
-                raise exceptions.InvalidData("Passwords must be the same.")
+                raise InvalidData("Passwords must be the same.")
             else:
                 self.widgets["passwd.admin.password"].valid(True)
                 self.widgets["passwd.admin.password_confirmation"].valid(True)
@@ -109,7 +117,7 @@
         if changes.contains_any(passwd_keys):
             pw, pwc = effective_model.values_for(passwd_keys)
             if pw != pwc:
-                raise exceptions.InvalidData("Passwords do not match")
+                raise InvalidData("Passwords do not match")
             passwd = utils.security.Passwd()
 
             # Create a custom transaction element, because the password


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

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