summaryrefslogtreecommitdiffstats
path: root/ipsilon
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2014-10-15 20:04:14 -0400
committerPatrick Uiterwijk <puiterwijk@redhat.com>2014-10-27 16:31:38 +0100
commit3a81575a4625576895958c9a21c8b6c64307fcb9 (patch)
tree08c400999033089c404f6477e27d499cb8e75b32 /ipsilon
parentfb1c34e7aeac67a75c29a132ded87edeb557cdaf (diff)
downloadipsilon-3a81575a4625576895958c9a21c8b6c64307fcb9.tar.gz
ipsilon-3a81575a4625576895958c9a21c8b6c64307fcb9.tar.xz
ipsilon-3a81575a4625576895958c9a21c8b6c64307fcb9.zip
Reuse the AdminPlugins class for the providers too
This way we can remove even more duplicated code... \o/ Signed-off-by: Simo Sorce <simo@redhat.com> Reviewed-by: Patrick Uiterwijk <puiterwijk@redhat.com>
Diffstat (limited to 'ipsilon')
-rwxr-xr-xipsilon/admin/common.py14
-rwxr-xr-xipsilon/admin/providers.py87
-rwxr-xr-xipsilon/info/common.py12
-rwxr-xr-xipsilon/login/common.py9
4 files changed, 31 insertions, 91 deletions
diff --git a/ipsilon/admin/common.py b/ipsilon/admin/common.py
index 827038e..b3c318b 100755
--- a/ipsilon/admin/common.py
+++ b/ipsilon/admin/common.py
@@ -213,8 +213,14 @@ class AdminPlugins(AdminPage):
def root_with_msg(self, message=None, message_type=None):
plugins = self._site[self.facility]
enabled = []
- for p in plugins['enabled']:
- enabled.append(p.name)
+ if self.order:
+ for plugin in plugins['enabled']:
+ enabled.append(plugin.name)
+ else:
+ for _, plugin in plugins['available'].iteritems():
+ if plugin.is_enabled:
+ enabled.append(plugin.name)
+
targs = {'title': self.title,
'menu': self._master.menu,
'message': message,
@@ -240,7 +246,7 @@ class AdminPlugins(AdminPage):
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)
if self.order:
enabled = list(x.name for x in plugins['enabled'])
@@ -257,7 +263,7 @@ class AdminPlugins(AdminPage):
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)
if self.order:
enabled = list(x.name for x in plugins['enabled'])
diff --git a/ipsilon/admin/providers.py b/ipsilon/admin/providers.py
index 06e5f54..ddba535 100755
--- a/ipsilon/admin/providers.py
+++ b/ipsilon/admin/providers.py
@@ -1,89 +1,14 @@
#!/usr/bin/python
#
-# Copyright (C) 2014 Simo Sorce <simo@redhat.com>
-#
-# see file 'COPYING' for use and warranty information
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
+# Copyright (C) 2014 Ipsilon Contributors see COPYING for license
-import cherrypy
-from ipsilon.util.page import admin_protect
+from ipsilon.admin.common import AdminPlugins
from ipsilon.providers.common import FACILITY
-from ipsilon.admin.common import AdminPluginConfig
-from ipsilon.admin.common import AdminPage
-class ProviderPlugins(AdminPage):
+class ProviderPlugins(AdminPlugins):
def __init__(self, site, parent):
- super(ProviderPlugins, self).__init__(site)
- self._master = parent
+ super(ProviderPlugins, self).__init__('providers', site, parent,
+ FACILITY, ordered=False)
self.title = 'Identity Providers'
- self.url = '%s/providers' % parent.url
- self.facility = FACILITY
- parent.add_subtree('providers', self)
-
- for plugin in self._site[FACILITY]['available']:
- cherrypy.log.error('Admin provider plugin: %s' % plugin)
- obj = self._site[FACILITY]['available'][plugin]
- page = AdminPluginConfig(obj, self._site, self)
- if hasattr(obj, 'admin'):
- obj.admin.mount(page)
- self.add_subtree(plugin, 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=enabled_plugins,
- menu=self._master.menu)
-
- def root(self, *args, **kwargs):
- return self.root_with_msg()
-
- @admin_protect
- def enable(self, plugin):
- msg = None
- plugins = self._site[FACILITY]
- if plugin not in plugins['available']:
- msg = "Unknown plugin %s" % plugin
- return self.root_with_msg(msg, "error")
- obj = plugins['available'][plugin]
- if not obj.is_enabled:
- obj.enable(self._site)
- msg = "Plugin %s enabled" % obj.name
- return self.root_with_msg(msg, "success")
- enable.public_function = True
-
- @admin_protect
- def disable(self, plugin):
- msg = None
- plugins = self._site[FACILITY]
- if plugin not in plugins['available']:
- msg = "Unknown plugin %s" % plugin
- return self.root_with_msg(msg, "error")
- obj = plugins['available'][plugin]
- if obj.is_enabled:
- obj.disable(self._site)
- msg = "Plugin %s disabled" % obj.name
- return self.root_with_msg(msg, "success")
- disable.public_function = True
+ self.template = 'admin/providers.html'
diff --git a/ipsilon/info/common.py b/ipsilon/info/common.py
index 92a3ba2..62f80ef 100755
--- a/ipsilon/info/common.py
+++ b/ipsilon/info/common.py
@@ -13,18 +13,19 @@ class InfoProviderBase(PluginObject, Log):
def __init__(self):
super(InfoProviderBase, self).__init__()
- self.enabled = False
+ self._site = None
def get_user_attrs(self, user):
raise NotImplementedError
@property
def is_enabled(self):
- return self.enabled
+ if self._site:
+ return self in self._site[FACILITY]['enabled']
+ return False
def enable(self, site):
- self.enabled = True
-
+ self._site = site
plugins = site[FACILITY]
if self in plugins['enabled']:
return
@@ -37,8 +38,7 @@ class InfoProviderBase(PluginObject, Log):
self.debug('Info plugin enabled: %s' % self.name)
def disable(self, site):
- self.enabled = False
-
+ self._site = site
plugins = site[FACILITY]
if self not in plugins['enabled']:
return
diff --git a/ipsilon/login/common.py b/ipsilon/login/common.py
index 6cd1ca8..73422ae 100755
--- a/ipsilon/login/common.py
+++ b/ipsilon/login/common.py
@@ -34,6 +34,7 @@ class LoginManagerBase(PluginObject, Log):
def __init__(self):
super(LoginManagerBase, self).__init__()
+ self._site = None
self.path = '/'
self.next_login = None
self.info = None
@@ -115,7 +116,14 @@ class LoginManagerBase(PluginObject, Log):
def get_tree(self, site):
raise NotImplementedError
+ @property
+ def is_enabled(self):
+ if self._site:
+ return self in self._site[FACILITY]['enabled']
+ return False
+
def enable(self, site):
+ self._site = site
plugins = site[FACILITY]
if self in plugins['enabled']:
return
@@ -147,6 +155,7 @@ class LoginManagerBase(PluginObject, Log):
self.info = root.info
def disable(self, site):
+ self._site = site
plugins = site[FACILITY]
if self not in plugins['enabled']:
return