diff options
author | Simo Sorce <simo@redhat.com> | 2014-10-09 18:09:54 -0400 |
---|---|---|
committer | Patrick Uiterwijk <puiterwijk@redhat.com> | 2014-10-24 18:02:09 +0200 |
commit | 4989f12044937821befc681d04624a8611100be2 (patch) | |
tree | c4e8270130beea7ee17830afc1adc4328dbf11d2 | |
parent | 2e22f6de25903aa6bcaa9631e0c8d7345fddf88c (diff) | |
download | ipsilon-4989f12044937821befc681d04624a8611100be2.tar.gz ipsilon-4989f12044937821befc681d04624a8611100be2.tar.xz ipsilon-4989f12044937821befc681d04624a8611100be2.zip |
Fix storing info plugin status and order
This is the same issue already resolved for the login plugins in
commit a6ed2bba137df5fb8a9fb2931ccb2d92ca3fa0e0
Signed-off-by: Simo Sorce <simo@redhat.com>
Reviewed-by: Patrick Uiterwijk <puiterwijk@redhat.com>
-rwxr-xr-x | ipsilon/admin/info.py | 18 | ||||
-rwxr-xr-x | ipsilon/info/common.py | 44 |
2 files changed, 40 insertions, 22 deletions
diff --git a/ipsilon/admin/info.py b/ipsilon/admin/info.py index cea6b0e..d3f5284 100755 --- a/ipsilon/admin/info.py +++ b/ipsilon/admin/info.py @@ -10,6 +10,15 @@ from ipsilon.admin.common import AdminPage from ipsilon.info.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 InfoPluginsOrder(AdminPage): def __init__(self, site, parent): @@ -51,12 +60,7 @@ class InfoPluginsOrder(AdminPage): 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) # When all is saved update also live config. The # live config is a list of the actual plugin @@ -125,6 +129,7 @@ class InfoPlugins(AdminPage): 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.public_function = True @@ -139,6 +144,7 @@ class InfoPlugins(AdminPage): 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.public_function = True diff --git a/ipsilon/info/common.py b/ipsilon/info/common.py index 4fbb7ef..c4be8fe 100755 --- a/ipsilon/info/common.py +++ b/ipsilon/info/common.py @@ -13,11 +13,18 @@ class InfoProviderBase(PluginObject, Log): def __init__(self): super(InfoProviderBase, self).__init__() + self.enabled = False def get_user_attrs(self, user): raise NotImplementedError + @property + def is_enabled(self): + return self.enabled + def enable(self, site): + self.enabled = True + plugins = site[FACILITY] if self in plugins['enabled']: return @@ -30,6 +37,8 @@ class InfoProviderBase(PluginObject, Log): self.debug('Info plugin enabled: %s' % self.name) def disable(self, site): + self.enabled = False + plugins = site[FACILITY] if self not in plugins['enabled']: return @@ -45,7 +54,6 @@ class Info(Log): def __init__(self, site): self._site = site - self.providers = [] loader = PluginLoader(Info, FACILITY, 'InfoProvider') self._site[FACILITY] = loader.get_plugin_data() @@ -54,26 +62,30 @@ class Info(Log): available = plugins['available'].keys() self.debug('Available info providers: %s' % str(available)) + plugins['root'] = self for item in plugins['whitelist']: self.debug('Login plugin in whitelist: %s' % item) if item not in plugins['available']: self.debug('Info Plugin %s not found' % item) continue - self.providers.append((item, plugins['available'][item])) - self.debug('Added Info plugin: %s' % item) - - def get_user_attrs(self, user, provider=None): - if provider: - for p in self.providers: - if p[0] == provider: - return p[1].get_user_attrs(user) - else: - for p in self.providers: - ret = p[1].get_user_attrs(user) - if ret: - return ret - - return None + plugins['available'][item].enable(self._site) + + def get_user_attrs(self, user, requested=None): + plugins = self._site[FACILITY]['available'] + result = dict() + + for _, p in plugins.items(): + if requested is None: + if not p.is_enabled: + continue + else: + if requested != p.name: + continue + result = p.get_user_attrs(user) + if result: + break + + return result class InfoProviderInstaller(object): |