Changeset 2482 for package_branches


Ignore:
Timestamp:
Sep 27, 2009, 7:55:09 PM (15 years ago)
Author:
quentin
Message:

Implement administrator mode

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

Legend:

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

    r2481 r2482  
    6262                                                 'from invirt import database']
    6363
     64    def __getattr__(self, name):
     65        if name in ("admin", "overlord"):
     66            if not cherrypy.request.login in getAfsGroupMembers(config.adminacl, config.authz[0].cell):
     67                raise InvalidInput('username', cherrypy.request.login,
     68                                   'Not in admin group %s.' % config.adminacl)
     69            cherrypy.request.state = State(cherrypy.request.login, isadmin=True)
     70            return self
     71        else:
     72            return super(InvirtWeb, self).__getattr__(name)
    6473
    6574    @cherrypy.expose
     
    701710            'hostname' : socket.getfqdn()}])
    702711
    703 def admin(username, state, path, fields):
    704     if path == '':
    705         return ({'Status': '303 See Other',
    706                  'Location': 'admin/'},
    707                 "You shouldn't see this message.")
    708     if not username in getAfsGroupMembers(config.adminacl, 'athena.mit.edu'):
    709         raise InvalidInput('username', username,
    710                            'Not in admin group %s.' % config.adminacl)
    711     newstate = State(username, isadmin=True)
    712     newstate.environ = state.environ
    713     return handler(username, newstate, path, fields)
    714 
    715712mapping = dict(
    716713               modify=modify,
    717                unauth=unauthFront,
    718                admin=admin,
    719                overlord=admin)
     714               unauth=unauthFront)
    720715
    721716def printHeaders(headers):
  • package_branches/invirt-web/cherrypy/code/templates/skeleton.mako

    r2432 r2482  
    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;
     
    5050% if not simple:
    5151% if cherrypy.request.login:
    52 <p class="loggedin">Welcome, <span class="name">${cherrypy.request.login}</span>.</p>
     52<p class="loggedin">Welcome, <span class="name">${cherrypy.request.login}</span>.
     53% if cherrypy.request.state.isadmin:
     54You are currently authenticated as an administrator.
     55% endif
     56</p>
    5357% endif
    5458
  • package_branches/invirt-web/cherrypy/code/view.py

    r2422 r2482  
    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.