diff options
author | Simo Sorce <simo@redhat.com> | 2014-03-24 16:59:41 -0400 |
---|---|---|
committer | Simo Sorce <simo@redhat.com> | 2014-03-26 15:25:56 -0400 |
commit | a5be918364744f92d73aa4b6589f3b9b33235d6d (patch) | |
tree | 366f41498c6f6c82f98d4deceed4315cf3973640 /ipsilon/admin/common.py | |
parent | 667901638f082e05b4ac61a14f4ddc07ec987742 (diff) | |
download | ipsilon-a5be918364744f92d73aa4b6589f3b9b33235d6d.tar.gz ipsilon-a5be918364744f92d73aa4b6589f3b9b33235d6d.tar.xz ipsilon-a5be918364744f92d73aa4b6589f3b9b33235d6d.zip |
Move login plugin configuration to its own module
move also the template, in preparation for handling other configuration
data in the main page.
Signed-off-by: Simo Sorce <simo@redhat.com>
Diffstat (limited to 'ipsilon/admin/common.py')
-rwxr-xr-x | ipsilon/admin/common.py | 120 |
1 files changed, 16 insertions, 104 deletions
diff --git a/ipsilon/admin/common.py b/ipsilon/admin/common.py index 2897237..0a46797 100755 --- a/ipsilon/admin/common.py +++ b/ipsilon/admin/common.py @@ -17,20 +17,19 @@ # 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.data import Store from ipsilon.util.page import Page from ipsilon.util.page import admin_protect -from ipsilon.util.plugin import PluginObject -import cherrypy -from ipsilon.login.common import FACILITY as LOGIN_FACILITY -class LoginPluginPage(Page): +class AdminPluginPage(Page): - def __init__(self, obj, site, baseurl): - super(LoginPluginPage, self).__init__(site) + def __init__(self, obj, site, baseurl, facility): + super(AdminPluginPage, self).__init__(site) self._obj = obj self.url = '%s/%s' % (baseurl, obj.name) + self.facility = facility # Get the defaults self.plugin_config = obj.get_config_desc() @@ -43,9 +42,10 @@ class LoginPluginPage(Page): @admin_protect def GET(self, *args, **kwargs): - return self._template('admin/login_plugin.html', + return self._template('admin/plugin_config.html', title='%s plugin' % self._obj.name, - name='admin_login_%s_form' % self._obj.name, + name='admin_%s_%s_form' % (self.facility, + self._obj.name), action=self.url, options=self.plugin_config) @@ -67,7 +67,7 @@ class LoginPluginPage(Page): # First we try to save in the database try: store = Store() - store.save_plugin_config(LOGIN_FACILITY, + store.save_plugin_config(self.facility, self._obj.name, new_values) message = "New configuration saved." message_type = "success" @@ -80,11 +80,12 @@ class LoginPluginPage(Page): self._obj.set_config_value(name, value) self.plugin_config[name][2] = value - return self._template('admin/login_plugin.html', + return self._template('admin/plugin_config.html', message=message, message_type=message_type, title='%s plugin' % self._obj.name, - name='admin_login_%s_form' % self._obj.name, + name='admin_%s_%s_form' % (self.facility, + self._obj.name), action=self.url, options=self.plugin_config) @@ -95,100 +96,11 @@ class LoginPluginPage(Page): return op(*args, **kwargs) -class LoginPluginsOrder(Page): - - def __init__(self, site, baseurl): - super(LoginPluginsOrder, self).__init__(site) - self.url = '%s/order' % baseurl - - @admin_protect - def GET(self, *args, **kwargs): - return self._template('admin/login_order.html', - title='login plugins order', - name='admin_login_order_form', - action=self.url, - options=self._site[LOGIN_FACILITY]['enabled']) - - @admin_protect - def POST(self, *args, **kwargs): - message = "Nothing was modified." - message_type = "info" - valid = self._site[LOGIN_FACILITY]['enabled'] - - if 'order' in kwargs: - order = kwargs['order'].split(',') - if len(order) != 0: - new_values = [] - try: - for v in order: - val = v.strip() - if val not in valid: - error = "Invalid plugin name: %s" % val - raise ValueError(error) - new_values.append(val) - if len(new_values) < len(valid): - for val in valid: - if val not in new_values: - new_values.append(val) - - po = PluginObject() - po.name = "global" - globalconf = dict() - globalconf['order'] = ','.join(new_values) - po.set_config(globalconf) - po.save_plugin_config(LOGIN_FACILITY) - - # When all is saved update also live config - self._site[LOGIN_FACILITY]['enabled'] = new_values - - message = "New configuration saved." - message_type = "success" - - except ValueError, e: - message = str(e) - message_type = "error" - - except Exception, e: # pylint: disable=broad-except - message = "Failed to save data!" - message_type = "error" - - return self._template('admin/login_order.html', - message=message, - message_type=message_type, - title='login plugins order', - name='admin_login_order_form', - action=self.url, - options=self._site[LOGIN_FACILITY]['enabled']) - - def root(self, *args, **kwargs): - cherrypy.log.error("method: %s" % cherrypy.request.method) - op = getattr(self, cherrypy.request.method, self.GET) - if callable(op): - return op(*args, **kwargs) - - -class LoginPlugins(Page): - def __init__(self, site, baseurl): - super(LoginPlugins, self).__init__(site) - self.url = '%s/login' % baseurl - - for plugin in self._site[LOGIN_FACILITY]['available']: - cherrypy.log.error('Admin login plugin: %s' % plugin) - obj = self._site[LOGIN_FACILITY]['available'][plugin] - self.__dict__[plugin] = LoginPluginPage(obj, self._site, self.url) - - self.order = LoginPluginsOrder(self._site, self.url) - - class Admin(Page): - def __init__(self, *args, **kwargs): - super(Admin, self).__init__(*args, **kwargs) - self.url = '%s/admin' % self.basepath - self.login = LoginPlugins(self._site, self.url) + def __init__(self, site, mount): + super(Admin, self).__init__(site) + self.url = '%s/%s' % (self.basepath, mount) def root(self, *args, **kwargs): - login_plugins = self._site[LOGIN_FACILITY] - return self._template('admin/index.html', title='Administration', - available=login_plugins['available'], - enabled=login_plugins['enabled']) + return self._template('admin/index.html', title='Configuration') |