~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/apps/server/__init__.py

  • Committer: William Grant
  • Date: 2009-01-22 04:47:42 UTC
  • mfrom: (1080.1.93 storm)
  • Revision ID: grantw@unimelb.edu.au-20090122044742-sa8gnww0ma2bm2rv
Merge Storm branch. ivle.db is dead. Watch out for the schema change.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
from ivle import (util, studpath, interpret)
31
31
import ivle.conf
 
32
from ivle.database import User
32
33
 
33
34
serveservice_path = os.path.join(ivle.conf.share_path, 'services/serveservice')
34
35
interpretservice_path = os.path.join(ivle.conf.share_path,
45
46
 
46
47
    # Get the username of the student whose work we are browsing, and the path
47
48
    # on the local machine where the file is stored.
48
 
    (user, path) = studpath.url_to_local(req.path)
 
49
    (login, path) = studpath.url_to_local(req.path)
49
50
 
50
 
    try:
51
 
        interpret.get_uid(user)
52
 
    except KeyError:
 
51
    owner = User.get_by_login(req.store, login)
 
52
    if not owner:
53
53
        # There is no user.
54
54
        req.throw_error(req.HTTP_NOT_FOUND,
55
55
            "The path specified is invalid.")
56
56
 
57
 
    serve_file(req, user, path)
 
57
    serve_file(req, owner, path)
58
58
 
59
59
def authorize(req):
60
60
    """Given a request, checks whether req.username is allowed to
76
76
    serving it directly, or denying it and returning a 403 Forbidden error.
77
77
    No return value. Writes to req (possibly throwing a server error exception
78
78
    using req.throw_error).
79
 
    
 
79
 
80
80
    req: An IVLE request object.
81
 
    owner: Username of the user who owns the file being served.
 
81
    owner: The user who owns the file being served.
82
82
    filename: Filename in the local file system.
83
83
    download:  Should the file be viewed in browser or downloaded
84
84
    """
86
86
    # We need a no-op trampoline run to ensure that the jail is mounted.
87
87
    # Otherwise we won't be able to authorise for public mode!
88
88
    noop_object = interpret.interpreter_objects["noop"]
89
 
    user_jail_dir = os.path.join(ivle.conf.jail_base, owner)
 
89
    user_jail_dir = os.path.join(ivle.conf.jail_base, owner.login)
90
90
    interpret.interpret_file(req, owner, user_jail_dir, '', noop_object)
91
91
 
92
92
    # Authorize access. If failure, this throws a HTTP_FORBIDDEN error.
93
93
    authorize(req)
94
 
    
 
94
 
95
95
    # Jump into the jail
96
96
    interp_object = interpret.interpreter_objects["cgi-python"]
97
97
    if download: