Ignore:
Timestamp:
Dec 20, 2009, 9:45:38 PM (15 years ago)
Author:
broder
Message:

Implement administrator mode

Location:
package_branches/invirt-web/cherrypy-rebased/code
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • package_branches/invirt-web/cherrypy-rebased/code/main.py

    r2689 r2690  
    5656                                                 'from invirt import database']
    5757
     58    def __getattr__(self, name):
     59        if name in ("admin", "overlord"):
     60            if not cherrypy.request.login in getAfsGroupMembers(config.adminacl, config.authz[0].cell):
     61                raise InvalidInput('username', cherrypy.request.login,
     62                                   'Not in admin group %s.' % config.adminacl)
     63            cherrypy.request.state = State(cherrypy.request.login, isadmin=True)
     64            return self
     65        else:
     66            return super(InvirtWeb, self).__getattr__(name)
    5867
    5968    @cherrypy.expose
     
    646655            'hostname' : socket.getfqdn()}])
    647656
    648 def admin(username, state, path, fields):
    649     if path == '':
    650         return ({'Status': '303 See Other',
    651                  'Location': 'admin/'},
    652                 "You shouldn't see this message.")
    653     if not username in getAfsGroupMembers(config.adminacl, 'athena.mit.edu'):
    654         raise InvalidInput('username', username,
    655                            'Not in admin group %s.' % config.adminacl)
    656     newstate = State(username, isadmin=True)
    657     newstate.environ = state.environ
    658     return handler(username, newstate, path, fields)
    659 
    660657mapping = dict(
    661658               modify=modify,
    662                unauth=unauthFront,
    663                admin=admin,
    664                overlord=admin)
     659               unauth=unauthFront)
    665660
    666661def printHeaders(headers):
  • package_branches/invirt-web/cherrypy-rebased/code/templates/skeleton.mako

    r2678 r2690  
    66<html>
    77<head><title>${self.title()} &mdash; XVM</title>
    8   <base href="${cherrypy.request.base}" />
    9   <link href="static/favicon.ico" type="image/x-icon" rel="shortcut icon">
    10   <link rel="stylesheet" href="static/style.css" type="text/css" />
    11   <link rel="stylesheet" href="static/layout.css" type="text/css" media="screen" />
    12   <script type="text/javascript" src="static/prototype.js"></script>
     8  <base href="${cherrypy.request.base}${"/admin/" if cherrypy.request.state.isadmin else ""}" />
     9  <link href="/static/favicon.ico" type="image/x-icon" rel="shortcut icon">
     10  <link rel="stylesheet" href="/static/style.css" type="text/css" />
     11  <link rel="stylesheet" href="/static/layout.css" type="text/css" media="screen" />
     12  <script type="text/javascript" src="/static/prototype.js"></script>
    1313  <script type="text/javascript">
    1414var helpWin = null;
     
    4949% if not simple:
    5050% if cherrypy.request.login:
    51 <p class="loggedin">Welcome, <span class="name">${cherrypy.request.login}</span>.</p>
     51<p class="loggedin">Welcome, <span class="name">${cherrypy.request.login}</span>.
     52% if cherrypy.request.state.isadmin:
     53You are currently authenticated as an administrator.
     54% endif
     55</p>
    5256% endif
    5357
  • package_branches/invirt-web/cherrypy-rebased/code/view.py

    r2685 r2690  
    113113def invirtwebstate_init():
    114114    """Initialize the cherrypy.request.state object from Invirt"""
    115     cherrypy.request.state = State(cherrypy.request.login)
     115    if not hasattr(cherrypy.request, "state"):
     116        cherrypy.request.state = State(cherrypy.request.login)
    116117
    117118cherrypy.tools.invirtwebstate = cherrypy.Tool('on_start_resource', invirtwebstate_init, priority=100)
Note: See TracChangeset for help on using the changeset viewer.