Implement administrator mode
authorQuentin Smith <quentin@mit.edu>
Sun, 27 Sep 2009 23:55:09 +0000 (19:55 -0400)
committerQuentin Smith <quentin@mit.edu>
Sun, 27 Sep 2009 23:55:09 +0000 (19:55 -0400)
svn path=/package_branches/invirt-web/cherrypy-rebased/; revision=2690

code/main.py
code/templates/skeleton.mako
code/view.py

index 473647f..5de084e 100755 (executable)
@@ -55,6 +55,15 @@ class InvirtWeb(View):
         self._cp_config['tools.mako.imports'] = ['from invirt.config import structs as config',
                                                  'from invirt import database']
 
         self._cp_config['tools.mako.imports'] = ['from invirt.config import structs as config',
                                                  'from invirt import database']
 
+    def __getattr__(self, name):
+        if name in ("admin", "overlord"):
+            if not cherrypy.request.login in getAfsGroupMembers(config.adminacl, config.authz[0].cell):
+                raise InvalidInput('username', cherrypy.request.login,
+                                   'Not in admin group %s.' % config.adminacl)
+            cherrypy.request.state = State(cherrypy.request.login, isadmin=True)
+            return self
+        else:
+            return super(InvirtWeb, self).__getattr__(name)
 
     @cherrypy.expose
     @cherrypy.tools.mako(filename="/list.mako")
 
     @cherrypy.expose
     @cherrypy.tools.mako(filename="/list.mako")
@@ -645,23 +654,9 @@ def unauthFront(_, _2, _3, fields):
     return templates.unauth(searchList=[{'simple' : True, 
             'hostname' : socket.getfqdn()}])
 
     return templates.unauth(searchList=[{'simple' : True, 
             'hostname' : socket.getfqdn()}])
 
-def admin(username, state, path, fields):
-    if path == '':
-        return ({'Status': '303 See Other',
-                 'Location': 'admin/'},
-                "You shouldn't see this message.")
-    if not username in getAfsGroupMembers(config.adminacl, 'athena.mit.edu'):
-        raise InvalidInput('username', username,
-                           'Not in admin group %s.' % config.adminacl)
-    newstate = State(username, isadmin=True)
-    newstate.environ = state.environ
-    return handler(username, newstate, path, fields)
-
 mapping = dict(
                modify=modify,
 mapping = dict(
                modify=modify,
-               unauth=unauthFront,
-               admin=admin,
-               overlord=admin)
+               unauth=unauthFront)
 
 def printHeaders(headers):
     """Print a dictionary as HTTP headers."""
 
 def printHeaders(headers):
     """Print a dictionary as HTTP headers."""
index 9c60c56..a53d2bf 100644 (file)
@@ -5,11 +5,11 @@ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html>
 <head><title>${self.title()} &mdash; XVM</title>
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html>
 <head><title>${self.title()} &mdash; XVM</title>
-  <base href="${cherrypy.request.base}" />
-  <link href="static/favicon.ico" type="image/x-icon" rel="shortcut icon">
-  <link rel="stylesheet" href="static/style.css" type="text/css" />
-  <link rel="stylesheet" href="static/layout.css" type="text/css" media="screen" />
-  <script type="text/javascript" src="static/prototype.js"></script>
+  <base href="${cherrypy.request.base}${"/admin/" if cherrypy.request.state.isadmin else ""}" />
+  <link href="/static/favicon.ico" type="image/x-icon" rel="shortcut icon">
+  <link rel="stylesheet" href="/static/style.css" type="text/css" />
+  <link rel="stylesheet" href="/static/layout.css" type="text/css" media="screen" />
+  <script type="text/javascript" src="/static/prototype.js"></script>
   <script type="text/javascript">
 var helpWin = null;
 function closeWin(){
   <script type="text/javascript">
 var helpWin = null;
 function closeWin(){
@@ -48,7 +48,11 @@ function helppopup(name){
 
 % if not simple:
 % if cherrypy.request.login:
 
 % if not simple:
 % if cherrypy.request.login:
-<p class="loggedin">Welcome, <span class="name">${cherrypy.request.login}</span>.</p>
+<p class="loggedin">Welcome, <span class="name">${cherrypy.request.login}</span>.
+% if cherrypy.request.state.isadmin:
+You are currently authenticated as an administrator.
+% endif
+</p>
 % endif
 
 <ul class="navigation">
 % endif
 
 <ul class="navigation">
index e1ba854..d15d53f 100644 (file)
@@ -112,7 +112,8 @@ cherrypy.tools.remote_user_login = cherrypy.Tool('on_start_resource', remote_use
 
 def invirtwebstate_init():
     """Initialize the cherrypy.request.state object from Invirt"""
 
 def invirtwebstate_init():
     """Initialize the cherrypy.request.state object from Invirt"""
-    cherrypy.request.state = State(cherrypy.request.login)
+    if not hasattr(cherrypy.request, "state"):
+        cherrypy.request.state = State(cherrypy.request.login)
 
 cherrypy.tools.invirtwebstate = cherrypy.Tool('on_start_resource', invirtwebstate_init, priority=100)
 
 
 cherrypy.tools.invirtwebstate = cherrypy.Tool('on_start_resource', invirtwebstate_init, priority=100)