From a6ed2bba137df5fb8a9fb2931ccb2d92ca3fa0e0 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 26 Sep 2014 17:38:30 -0400 Subject: [PATCH] Fix storing login plugin status and order 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 Reviewed-by: Patrick Uiterwijk --- ipsilon/admin/login.py | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/ipsilon/admin/login.py b/ipsilon/admin/login.py index 62522fc..bb79f90 100755 --- a/ipsilon/admin/login.py +++ b/ipsilon/admin/login.py @@ -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 -- 2.20.1