Work around quirk of CherryPy dispatching that causes username munging to not happen...
[invirt/packages/invirt-web.git] / code / main.py
index 9f57f84..0b8af46 100755 (executable)
@@ -51,11 +51,7 @@ class InvirtUnauthWeb(View):
     @cherrypy.expose
     @cherrypy.tools.mako(filename="/unauth.mako")
     def index(self):
-        d = dict(simple=True)
-        if os.path.exists("/etc/invirt/message"):
-            f = open('/etc/invirt/message')
-            d['serviceMessage']= f.read()
-        return d
+        return dict(simple=True)
 
 class InvirtWeb(View):
     def __init__(self):
@@ -101,6 +97,9 @@ class InvirtWeb(View):
         return d
 
     def __getattr__(self, name):
+        # At the point __getattr__ is called, tools haven't been run. Make sure the user is logged in.
+        cherrypy.tools.remote_user_login.callable()
+
         if name in ("admin", "overlord"):
             if not cherrypy.request.login in getAfsGroupMembers(config.adminacl, config.authz.afs.cells[0].cell):
                 raise InvalidInput('username', cherrypy.request.login,
@@ -524,9 +523,9 @@ def modifyDict(username, state, machine_id, fields):
     olddisk = {}
     session.begin()
     try:
-        kws = dict([(kw, fields[kw]) for kw in
+        kws = dict((kw, fields[kw]) for kw in
          'owner admin contact name description memory vmtype disksize'.split()
-                    if fields[kw]])
+                    if fields.get(kw))
         kws['machine_id'] = machine_id
         validate = validation.Validate(username, state, **kws)
         machine = validate.machine