summaryrefslogtreecommitdiffstats
path: root/ipsilon/admin/providers.py
blob: 26e96a7d5d18bf6bf4c26c8b83f004ae8ec958a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/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/>.


import cherrypy
from ipsilon.util.page import Page
from ipsilon.providers.common import FACILITY
from ipsilon.admin.common import AdminPluginPage


class ProviderPlugins(Page):
    def __init__(self, site, parent):
        super(ProviderPlugins, self).__init__(site)
        self._master = parent
        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]
            self.__dict__[plugin] = AdminPluginPage(obj, self)

    def root_with_msg(self, message=None, message_type=None):
        plugins = self._site[FACILITY]
        return self._template('admin/providers.html', title=self.title,
                              baseurl=self.url,
                              message=message,
                              message_type=message_type,
                              available=plugins['available'],
                              enabled=plugins['enabled'],
                              menu=self._master.menu)

    def root(self, *args, **kwargs):
        return self.root_with_msg()

    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 obj not in plugins['enabled']:
            obj.enable(self._site)
            msg = "Plugin %s enabled" % obj.name
        return self.root_with_msg(msg, "success")
    enable.exposed = True

    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 in plugins['enabled']:
            obj.disable(self._site)
            msg = "Plugin %s disabled" % obj.name
        return self.root_with_msg(msg, "success")
    disable.exposed = True