Move admin_protect to a more generic module
[cascardo/ipsilon.git] / ipsilon / util / page.py
index 2cdca1c..7dda1d7 100755 (executable)
@@ -21,6 +21,17 @@ from ipsilon.util.user import UserSession
 import cherrypy
 
 
+def admin_protect(fn):
+
+    def check(*args, **kwargs):
+        if UserSession().get_user().is_admin:
+            return fn(*args, **kwargs)
+
+        raise cherrypy.HTTPError(403)
+
+    return check
+
+
 def protect():
     UserSession().remote_login()
 
@@ -62,6 +73,10 @@ class Page(object):
         m.update(kwargs)
         return t.render(**m)
 
+    def _debug(self, fact):
+        if cherrypy.config.get('debug', False):
+            cherrypy.log(fact)
+
     def default(self, *args, **kwargs):
         raise cherrypy.HTTPError(404)