Fix storing login plugin status and order
authorSimo Sorce <simo@redhat.com>
Fri, 26 Sep 2014 21:38:30 +0000 (17:38 -0400)
committerPatrick Uiterwijk <puiterwijk@redhat.com>
Mon, 6 Oct 2014 18:27:49 +0000 (20:27 +0200)
When plugins were enabled or disabled their status was not stored
in the database, unless the order was explicitly manipulated.
Moreover if the order was changed that fact would not be refrlected
in the actual authntication order until a restart.
Fix the code to always permanently store the enabled/disabled status,
and to immediately change the authentication order.

Signed-off-by: Simo Sorce <simo@redhat.com>
Reviewed-by: Patrick Uiterwijk <puiterwijk@redhat.com>
ipsilon/admin/login.py

index 62522fc..bb79f90 100755 (executable)
@@ -25,6 +25,15 @@ from ipsilon.admin.common import AdminPluginPage
 from ipsilon.login.common import FACILITY
 
 
+def save_enabled_plugins(names):
+    po = PluginObject()
+    po.name = "global"
+    globalconf = dict()
+    globalconf['order'] = ','.join(names)
+    po.set_config(globalconf)
+    po.save_plugin_config(FACILITY)
+
+
 class LoginPluginsOrder(Page):
 
     def __init__(self, site, parent):
@@ -32,6 +41,18 @@ class LoginPluginsOrder(Page):
         self.url = '%s/order' % parent.url
         self.menu = [parent]
 
+    def _reorder_plugins(self, order):
+        plugins = self._site[FACILITY]['available']
+        root = self._site[FACILITY]['root']
+        prev_obj = None
+        for name in order:
+            if prev_obj is None:
+                root.first_login = plugins[name]
+            else:
+                prev_obj.next_login = plugins[name]
+            prev_obj = plugins[name]
+        prev_obj.next_login = None
+
     @admin_protect
     def GET(self, *args, **kwargs):
         opts = [p.name for p in self._site[FACILITY]['enabled']]
@@ -66,12 +87,8 @@ class LoginPluginsOrder(Page):
                                 new_names.append(val)
                                 new_plugins.append(plugins_by_name[val])
 
-                    po = PluginObject()
-                    po.name = "global"
-                    globalconf = dict()
-                    globalconf['order'] = ','.join(new_names)
-                    po.set_config(globalconf)
-                    po.save_plugin_config(FACILITY)
+                    save_enabled_plugins(new_names)
+                    self._reorder_plugins(new_names)
 
                     # When all is saved update also live config. The
                     # live config is a list of the actual plugin
@@ -139,6 +156,7 @@ class LoginPlugins(Page):
         obj = plugins['available'][plugin]
         if obj not in plugins['enabled']:
             obj.enable(self._site)
+            save_enabled_plugins(list(x.name for x in plugins['enabled']))
             msg = "Plugin %s enabled" % obj.name
         return self.root_with_msg(msg, "success")
     enable.exposed = True
@@ -152,6 +170,7 @@ class LoginPlugins(Page):
         obj = plugins['available'][plugin]
         if obj in plugins['enabled']:
             obj.disable(self._site)
+            save_enabled_plugins(list(x.name for x in plugins['enabled']))
             msg = "Plugin %s disabled" % obj.name
         return self.root_with_msg(msg, "success")
     disable.exposed = True