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

« back to all changes in this revision

Viewing changes to www/common/studpath.py

  • Committer: mattgiuca
  • Date: 2008-01-22 22:28:27 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:266
Added Publishing feature. This feature is complete except it currently isn't
available in the JavaScript interface.

fileservice: Added new JSON property "published", for each file under revision
control. Added new actions svnpublish and svnunpublish.
common/studpath: Added "published" function (to check if a file is published),
and "authorize_public" to authorize in public mode.
server: Now calls studpath.authorize_public for public mode (instead of just
authorizing everything).

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
import os
28
28
 
 
29
import pysvn
 
30
 
29
31
import conf
30
32
from common import util
31
33
 
 
34
# Make a Subversion client object (for published)
 
35
svnclient = pysvn.Client()
 
36
 
32
37
def url_to_local(urlpath):
33
38
    """Given a URL path (part of a URL query string, see below), returns a
34
39
    tuple of
96
101
 
97
102
    return (user, jail, path)
98
103
 
 
104
def published(path):
 
105
    """Given a path on the LOCAL file system, determines whether the path has
 
106
    its "ivle:published" property active (in subversion). Returns True
 
107
    or False."""
 
108
    # Read SVN properties for this path
 
109
    try:
 
110
        props = svnclient.propget("ivle:published", path, recurse=False)
 
111
    except pysvn.ClientError:
 
112
        # Not under version control? Then it isn't published.
 
113
        return False
 
114
    return len(props) > 0
 
115
 
99
116
def authorize(req):
100
117
    """Given a request, checks whether req.username is allowed to
101
118
    access req.path. Returns None on authorization success. Raises
114
131
    (owner, _) = util.split_path(urlpath)
115
132
    if req.username != owner:
116
133
        req.throw_error(req.HTTP_FORBIDDEN)
 
134
 
 
135
def authorize_public(req):
 
136
    """A different kind of authorization. Rather than making sure the
 
137
    logged-in user owns the file, this checks if the file has been published
 
138
    (ignoring the user). This is for the "public mode" of the serve app.
 
139
 
 
140
    Same interface as "authorize" - None on success, HTTP_FORBIDDEN exception
 
141
    raised on failure.
 
142
    """
 
143
    _, path = url_to_local(req.path)
 
144
    if not published(path):
 
145
        req.throw_error(req.HTTP_FORBIDDEN)