3 # Copyright (C) 2014 Simo Sorce <simo@redhat.com>
5 # see file 'COPYING' for use and warranty information
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 from ipsilon.util.page import Page
23 from ipsilon.providers.common import FACILITY
24 from ipsilon.admin.common import AdminPluginPage
27 class ProviderPlugins(Page):
28 def __init__(self, site, parent):
29 super(ProviderPlugins, self).__init__(site)
31 self.title = 'Identity Providers'
32 self.url = '%s/providers' % parent.url
33 self.facility = FACILITY
34 parent.add_subtree('providers', self)
36 for plugin in self._site[FACILITY]['available']:
37 cherrypy.log.error('Admin provider plugin: %s' % plugin)
38 obj = self._site[FACILITY]['available'][plugin]
39 page = AdminPluginPage(obj, self._site, self)
40 if hasattr(obj, 'admin'):
42 self.add_subtree(plugin, page)
44 def root_with_msg(self, message=None, message_type=None):
45 plugins = self._site[FACILITY]
46 return self._template('admin/providers.html', title=self.title,
49 message_type=message_type,
50 available=plugins['available'],
51 enabled=plugins['enabled'],
52 menu=self._master.menu)
54 def root(self, *args, **kwargs):
55 return self.root_with_msg()
57 def enable(self, plugin):
59 plugins = self._site[FACILITY]
60 if plugin not in plugins['available']:
61 msg = "Unknown plugin %s" % plugin
62 return self.root_with_msg(msg, "error")
63 obj = plugins['available'][plugin]
64 if obj not in plugins['enabled']:
65 obj.enable(self._site)
66 msg = "Plugin %s enabled" % obj.name
67 return self.root_with_msg(msg, "success")
70 def disable(self, plugin):
72 plugins = self._site[FACILITY]
73 if plugin not in plugins['available']:
74 msg = "Unknown plugin %s" % plugin
75 return self.root_with_msg(msg, "error")
76 obj = plugins['available'][plugin]
77 if obj in plugins['enabled']:
78 obj.disable(self._site)
79 msg = "Plugin %s disabled" % obj.name
80 return self.root_with_msg(msg, "success")
81 disable.exposed = True