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

« back to all changes in this revision

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

  • Committer: mattgiuca
  • Date: 2008-01-22 02:16:13 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:262
studpath: Added "authorize" function which checks the logged in user against
the path they are trying to access.
fileservice, server, download: Call authorize before doing anything.
    Note: server does a bit more because in public mode it checks svn status
    instead of calling studpath.authorize (NYI).

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
 
46
46
    serve_file(req, user, path)
47
47
 
 
48
def authorize(req):
 
49
    """Given a request, checks whether req.username is allowed to
 
50
    access req.path. Returns None on authorization success. Raises
 
51
    HTTP_FORBIDDEN on failure.
 
52
    """
 
53
    if req.publicmode:
 
54
        # Public mode authorization: any user can access any other user's
 
55
        # files, BUT the accessed file needs to have its "published" flag
 
56
        # turned on in the SVN status.
 
57
        # TODO
 
58
        pass
 
59
    else:
 
60
        # Private mode authorization: standard (only logged in user can access
 
61
        # their own files, and can access all of them).
 
62
        studpath.authorize(req)
 
63
 
48
64
def serve_file(req, owner, filename):
49
65
    """Serves a file, using one of three possibilities: interpreting the file,
50
66
    serving it directly, or denying it and returning a 403 Forbidden error.
55
71
    owner: Username of the user who owns the file being served.
56
72
    filename: Filename in the local file system.
57
73
    """
 
74
    # Authorize access. If failure, this throws a HTTP_FORBIDDEN error.
 
75
    authorize(req)
58
76
 
59
77
    # First get the mime type of this file
60
78
    # (Note that importing common.util has already initialised mime types)