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):
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
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
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
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
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
def __init__(self, site):
self._site = site
- self.providers = []
loader = PluginLoader(Info, FACILITY, 'InfoProvider')
self._site[FACILITY] = loader.get_plugin_data()
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):