Convert all forms to use util.Page form support
[cascardo/ipsilon.git] / ipsilon / admin / login.py
index b8325c8..70b477f 100755 (executable)
@@ -28,7 +28,7 @@ from ipsilon.login.common import FACILITY
 class LoginPluginsOrder(Page):
 
     def __init__(self, site, parent):
-        super(LoginPluginsOrder, self).__init__(site)
+        super(LoginPluginsOrder, self).__init__(site, form=True)
         self.url = '%s/order' % parent.url
         self.menu = [parent]
 
@@ -91,12 +91,6 @@ class LoginPluginsOrder(Page):
                               menu=self.menu, action=self.url,
                               options=self._site[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, parent):
@@ -114,9 +108,43 @@ class LoginPlugins(Page):
 
         self.order = LoginPluginsOrder(self._site, self)
 
-    def root(self, *args, **kwargs):
+    def root_with_msg(self, message=None, message_type=None):
         login_plugins = self._site[FACILITY]
+        ordered = []
+        for p in login_plugins['enabled']:
+            ordered.append(p.name)
         return self._template('admin/login.html', title=self.title,
+                              message=message,
+                              message_type=message_type,
                               available=login_plugins['available'],
-                              enabled=login_plugins['enabled'],
+                              enabled=ordered,
                               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