summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2014-03-24 16:37:15 -0400
committerSimo Sorce <simo@redhat.com>2014-03-24 16:53:28 -0400
commit1e137be617dba1d0f3f85d594f5625926d3f46e9 (patch)
tree68abfb35e6490dc727b6f100f04cd169bccc37a3
parent8fe18393e0a3ff27e999a069207d48f782cca9f8 (diff)
downloadipsilon-1e137be617dba1d0f3f85d594f5625926d3f46e9.tar.gz
ipsilon-1e137be617dba1d0f3f85d594f5625926d3f46e9.tar.xz
ipsilon-1e137be617dba1d0f3f85d594f5625926d3f46e9.zip
Implement plugin ordering configuration
Allows to change the login plugins order from the admin configuration page. Signed-off-by: Simo Sorce <simo@redhat.com>
-rwxr-xr-xipsilon/admin/common.py75
-rw-r--r--templates/admin/index.html7
-rw-r--r--templates/admin/login_order.html25
3 files changed, 105 insertions, 2 deletions
diff --git a/ipsilon/admin/common.py b/ipsilon/admin/common.py
index 6e36669..10171dc 100755
--- a/ipsilon/admin/common.py
+++ b/ipsilon/admin/common.py
@@ -20,6 +20,7 @@
from ipsilon.util.data import Store
from ipsilon.util.page import Page
from ipsilon.util.user import UserSession
+from ipsilon.util.plugin import PluginObject
import cherrypy
from ipsilon.login.common import FACILITY as LOGIN_FACILITY
@@ -105,6 +106,78 @@ 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)
@@ -115,6 +188,8 @@ class LoginPlugins(Page):
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):
diff --git a/templates/admin/index.html b/templates/admin/index.html
index c22d249..1957a7f 100644
--- a/templates/admin/index.html
+++ b/templates/admin/index.html
@@ -18,6 +18,9 @@
{% endfor %}
<h3>Plugins order</h3>
- <p>[list here and form button to change?]</p>
+ <div class="col-md-3 col-sm-3 col-xs-6">{{ ', '.join(enabled) }}</div>
+ <div class="col-md-3 col-sm-3 col-xs-6">
+ <a class="btn btn-default" href="{{ basepath }}/admin/login/order">configure</a>
+ </div>
{% endif %}
-{% endblock %} \ No newline at end of file
+{% endblock %}
diff --git a/templates/admin/login_order.html b/templates/admin/login_order.html
new file mode 100644
index 0000000..c78fe55
--- /dev/null
+++ b/templates/admin/login_order.html
@@ -0,0 +1,25 @@
+{% extends "master-admin.html" %}
+{% block main %}
+ <h2>{{ title }}</h2>
+ {% if message %}
+ <div class="alert alert-{{message_type}}">
+ <p>{{ message }}</p>
+ </div>
+ {% endif %}
+ <div id="options">
+ <form role="form" id="{{ name }}" action="{{ action }}" method="post" enctype="application/x-www-form-urlencoded">
+
+ <div class="form-group">
+ <label for="order">Login plugins order:</label>
+ <input type="text" class="form-control" name="order" value="{{ ', '.join(options) }}" />
+ </div>
+ <span class="help-block">Plugins order</span>
+
+ <button id="submit" class="btn btn-primary" name="submit" type="submit" value="Submit">
+ Save
+ </button>
+ <a href="{{ basepath }}/admin" class="btn btn-default" title="Back">Back</a>
+ </form>
+ </div>
+{% endblock %}
+