diff options
-rwxr-xr-x | ipsilon/admin/providers.py | 11 | ||||
-rwxr-xr-x | ipsilon/providers/common.py | 52 | ||||
-rw-r--r-- | templates/admin/providers.html | 2 |
3 files changed, 46 insertions, 19 deletions
diff --git a/ipsilon/admin/providers.py b/ipsilon/admin/providers.py index 1a2df7c..ba5e1e7 100755 --- a/ipsilon/admin/providers.py +++ b/ipsilon/admin/providers.py @@ -43,12 +43,17 @@ class ProviderPlugins(Page): def root_with_msg(self, message=None, message_type=None): plugins = self._site[FACILITY] + enabled_plugins = [] + for item in plugins['available']: + plugin = plugins['available'][item] + if plugin.is_enabled: + enabled_plugins.append(item) return self._template('admin/providers.html', title=self.title, baseurl=self.url, message=message, message_type=message_type, available=plugins['available'], - enabled=plugins['enabled'], + enabled=enabled_plugins, menu=self._master.menu) def root(self, *args, **kwargs): @@ -61,7 +66,7 @@ class ProviderPlugins(Page): msg = "Unknown plugin %s" % plugin return self.root_with_msg(msg, "error") obj = plugins['available'][plugin] - if obj not in plugins['enabled']: + if not obj.is_enabled: obj.enable(self._site) msg = "Plugin %s enabled" % obj.name return self.root_with_msg(msg, "success") @@ -74,7 +79,7 @@ class ProviderPlugins(Page): msg = "Unknown plugin %s" % plugin return self.root_with_msg(msg, "error") obj = plugins['available'][plugin] - if obj in plugins['enabled']: + if obj.is_enabled: obj.disable(self._site) msg = "Plugin %s disabled" % obj.name return self.root_with_msg(msg, "success") diff --git a/ipsilon/providers/common.py b/ipsilon/providers/common.py index f9c1311..b1eab1a 100755 --- a/ipsilon/providers/common.py +++ b/ipsilon/providers/common.py @@ -43,6 +43,7 @@ class ProviderBase(PluginObject): super(ProviderBase, self).__init__() self.name = name self.path = path + self.tree = None self.admin = None def _debug(self, fact): @@ -52,32 +53,55 @@ class ProviderBase(PluginObject): def get_tree(self, site): raise NotImplementedError - def enable(self, site): - plugins = site[FACILITY] - if self in plugins['enabled']: + def register(self, site): + if self.tree: + # already registered return # configure self + plugins = site[FACILITY] if self.name in plugins['config']: self.set_config(plugins['config'][self.name]) + # init pages and admin interfaces + self.tree = self.get_tree(site) + + self._debug('IdP Provider registered: %s' % self.name) + + if self.get_config_value('enabled') == '1': + # and add self to the root + root = site[FACILITY]['root'] + root.add_subtree(self.name, self.tree) + self._debug('IdP Provider enabled: %s' % self.name) + + @property + def is_enabled(self): + if self.get_config_value('enabled') == '1': + return True + return False + + def enable(self, site): + if self.is_enabled: + return + # and add self to the root - root = plugins['root'] - root.add_subtree(self.name, self.get_tree(site)) + root = site[FACILITY]['root'] + root.add_subtree(self.name, self.tree) - plugins['enabled'].append(self) + self.set_config_value('enabled', '1') + self.save_plugin_config(FACILITY) self._debug('IdP Provider enabled: %s' % self.name) def disable(self, site): - plugins = site[FACILITY] - if self not in plugins['enabled']: + if not self.is_enabled: return # remove self to the root - root = plugins['root'] + root = site[FACILITY]['root'] root.del_subtree(self.name) - plugins['enabled'].remove(self) + self.set_config_value('enabled', '0') + self.save_plugin_config(FACILITY) self._debug('IdP Provider disabled: %s' % self.name) @@ -123,11 +147,9 @@ class LoadProviders(object): self._debug('Available providers: %s' % str(available)) providers['root'] = root - for item in providers['whitelist']: - self._debug('IdP Provider in whitelist: %s' % item) - if item not in providers['available']: - continue - providers['available'][item].enable(site) + for item in providers['available']: + plugin = providers['available'][item] + plugin.register(site) def _debug(self, fact): if cherrypy.config.get('debug', False): diff --git a/templates/admin/providers.html b/templates/admin/providers.html index fbeb54d..66230d7 100644 --- a/templates/admin/providers.html +++ b/templates/admin/providers.html @@ -7,7 +7,7 @@ <div class="row"> <div class="col-md-3 col-sm-3 col-xs-6">{{ p }}</div> <div class="col-md-3 col-sm-3 col-xs-6"> - {% if available[p] in enabled %} + {% if p in enabled %} <a class="btn btn-default" href="{{ baseurl }}/disable/{{ p }}">Disable</a> <a class="btn btn-default" href="{{ baseurl }}/{{ p }}">Configure</a> {% if available[p].admin %} |