Blame SOURCES/invalid_profile_id_1247677.patch

fd2bce
From d0a558b6e150e7d78caa16b33ca9029f2d4cfc1f Mon Sep 17 00:00:00 2001
fd2bce
From: Vratislav Podzimek <vpodzime@redhat.com>
fd2bce
Date: Mon, 3 Aug 2015 13:28:20 +0200
fd2bce
Subject: [PATCH 2/7] Do not continue with and invalid profile ID (#1247677)
fd2bce
fd2bce
If an invalid profile ID is given, we need to stop the installation and, report
fd2bce
an error and let user choose a different profile.
fd2bce
fd2bce
Signed-off-by: Vratislav Podzimek <vpodzime@redhat.com>
fd2bce
---
fd2bce
 org_fedora_oscap/gui/spokes/oscap.py | 46 ++++++++++++++++++++++++++++--------
fd2bce
 1 file changed, 36 insertions(+), 10 deletions(-)
fd2bce
fd2bce
diff --git a/org_fedora_oscap/gui/spokes/oscap.py b/org_fedora_oscap/gui/spokes/oscap.py
fd2bce
index 38dabc1..06107a3 100644
fd2bce
--- a/org_fedora_oscap/gui/spokes/oscap.py
fd2bce
+++ b/org_fedora_oscap/gui/spokes/oscap.py
fd2bce
@@ -420,7 +420,13 @@ class OSCAPSpoke(NormalSpoke):
fd2bce
         self.refresh()
fd2bce
 
fd2bce
         # try to switch to the chosen profile (if any)
fd2bce
-        self._switch_profile()
fd2bce
+        selected = self._switch_profile()
fd2bce
+
fd2bce
+        if self._addon_data.profile_id and not selected:
fd2bce
+            # profile ID given, but it was impossible to select it -> invalid
fd2bce
+            # profile ID given
fd2bce
+            self._invalid_profile_id()
fd2bce
+            return
fd2bce
 
fd2bce
         # initialize the self._addon_data.rule_data
fd2bce
         self._addon_data.rule_data = self._rule_data
fd2bce
@@ -439,7 +445,7 @@ class OSCAPSpoke(NormalSpoke):
fd2bce
             self._fetching = False
fd2bce
 
fd2bce
         # no error
fd2bce
-        self._error = None
fd2bce
+        self._set_error(None)
fd2bce
 
fd2bce
     @property
fd2bce
     def _using_ds(self):
fd2bce
@@ -595,7 +601,7 @@ class OSCAPSpoke(NormalSpoke):
fd2bce
 
fd2bce
         if not profile_id:
fd2bce
             # no profile specified, nothing to do
fd2bce
-            return
fd2bce
+            return False
fd2bce
 
fd2bce
         itr = self._profiles_store.get_iter_first()
fd2bce
         while itr:
fd2bce
@@ -609,7 +615,7 @@ class OSCAPSpoke(NormalSpoke):
fd2bce
 
fd2bce
             if not all((ds, xccdf, profile_id)):
fd2bce
                 # something is not set -> do nothing
fd2bce
-                return
fd2bce
+                return False
fd2bce
         else:
fd2bce
             ds = None
fd2bce
             xccdf = None
fd2bce
@@ -628,25 +634,39 @@ class OSCAPSpoke(NormalSpoke):
fd2bce
         # remember the active profile
fd2bce
         self._active_profile = profile_id
fd2bce
 
fd2bce
+        return True
fd2bce
+
fd2bce
     @gtk_action_wait
fd2bce
     @dry_run_skip
fd2bce
     def _switch_profile(self):
fd2bce
-        """Switches to a current selected profile."""
fd2bce
+        """Switches to a current selected profile.
fd2bce
+
fd2bce
+        :returns: whether some profile was selected or not
fd2bce
+
fd2bce
+        """
fd2bce
 
fd2bce
+        self._set_error(None)
fd2bce
         profile = self._current_profile_id
fd2bce
         if not profile:
fd2bce
-            return
fd2bce
+            return False
fd2bce
 
fd2bce
         self._unselect_profile(self._active_profile)
fd2bce
-        self._select_profile(profile)
fd2bce
+        ret = self._select_profile(profile)
fd2bce
 
fd2bce
         # update messages according to the newly chosen profile
fd2bce
         self._update_message_store()
fd2bce
 
fd2bce
+        return ret
fd2bce
+
fd2bce
     @set_ready
fd2bce
     def _set_error(self, msg):
fd2bce
-        self._error = msg
fd2bce
-        self.set_error(msg)
fd2bce
+        """Set or clear error message"""
fd2bce
+        if msg:
fd2bce
+            self._error = msg
fd2bce
+            self.set_error(msg)
fd2bce
+        else:
fd2bce
+            self._error = None
fd2bce
+            self.clear_info()
fd2bce
 
fd2bce
     @gtk_action_wait
fd2bce
     def _invalid_content(self):
fd2bce
@@ -710,6 +730,12 @@ class OSCAPSpoke(NormalSpoke):
fd2bce
         self._set_error(msg)
fd2bce
 
fd2bce
     @gtk_action_wait
fd2bce
+    def _invalid_profile_id(self):
fd2bce
+        msg = _("Profile with ID '%s' not defined in the content. Select a different profile, please") % self._addon_data.profile_id
fd2bce
+        self._set_error(msg)
fd2bce
+        self._addon_data.profile_id = None
fd2bce
+
fd2bce
+    @gtk_action_wait
fd2bce
     def _switch_dry_run(self, dry_run):
fd2bce
         self._choose_button.set_sensitive(not dry_run)
fd2bce
 
fd2bce
@@ -822,7 +848,7 @@ class OSCAPSpoke(NormalSpoke):
fd2bce
 
fd2bce
         if not self._addon_data.content_defined or not self._active_profile:
fd2bce
             # no errors for no content or no profile
fd2bce
-            self._error = None
fd2bce
+            self._set_error(None)
fd2bce
 
fd2bce
         # store currently selected values to the addon data attributes
fd2bce
         if self._using_ds:
fd2bce
-- 
fd2bce
2.1.0
fd2bce