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

« back to all changes in this revision

Viewing changes to ivle/studpath.py

  • Committer: matt.giuca
  • Date: 2009-01-14 10:10:12 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:branches%2Fstorm:1132
The new ivle.database.User class is now used in Request and usrmgt, which
    means it is now almost universally used in favour of ivle.user.User (now
    deprecated).

Noticeable change: The minor bug where the change to a user object in the
    database is not reflected in the user's session (eg. changing nick doesn't
    update title until log out).

ivle.dispatch:
    Session now contains 'login' (username string) rather than 'user' (full
        ivle.user.User object). This is a unicode string now.

    req.user is now a ivle.database.User object rather than an ivle.user.User
        object. This makes for a whole lot of really subtle differences, but
        largely conforms to the same interface. Note that strings must now all
        be unicode.

    login: Removed use of ivle.db. Now uses User object.

    html: Now handles unicode login and config options.

ivle.db: Removed update_user. Now replaced with Storm model.

ivle.database: Renamed has_cap back to hasCap (saved for later). Fixed small
    unicode bug.

ivle.makeuser.make_svn_auth now takes a store object.

usrmgt-server: Use new User class.

userservice: Now uses User class internally.
    get_user action now returns ISO 8601 date format, rather than a
        time tuple. (Wasn't being used).
    get_user action no longer transmits local_password (small security risk;
        note that it wasn't possible to see this for any user other than
        yourself unless admin).

ivle.util - added function object_to_dict.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
# Make a Subversion client object (for published)
35
35
svnclient = pysvn.Client()
36
36
 
37
 
def url_to_local(config, urlpath):
 
37
def url_to_local(urlpath):
38
38
    """Given a URL path (part of a URL query string, see below), returns a
39
39
    tuple of
40
40
        * the username of the student whose directory is being browsed
51
51
 
52
52
    Returns (None, None) if the path is empty.
53
53
 
54
 
    >>> stubconfig = {'paths': {'jails': {'mounts': '/jails'}}}
55
 
    >>> url_to_local(stubconfig, '')
56
 
    (None, None)
57
 
    >>> url_to_local(stubconfig, 'joe/foo/bar/baz')
58
 
    ('joe', '/jails/joe/home/joe/foo/bar/baz')
 
54
    See also: ivle.conf.jail_base
59
55
    """
60
 
 
61
56
    # First normalise the path
62
57
    urlpath = os.path.normpath(urlpath)
63
58
    # Now if it begins with ".." or separator, then it's illegal
73
68
    # accordance with our directory scheme.
74
69
    # (The first time is the name of the jail, the second is the user's home
75
70
    # directory within the jail).
76
 
    path = os.path.join(config['paths']['jails']['mounts'],
77
 
                        user, 'home', urlpath)
 
71
    path = os.path.join(ivle.conf.jail_base, user, 'home', urlpath)
78
72
 
79
73
    return (user, path)
80
74
 
87
81
    urlpath: See urlpath in url_to_local.
88
82
 
89
83
    >>> url_to_jailpaths("joe/mydir/myfile")
90
 
    ('joe', '/var/lib/ivle/jailmounts/joe', '/home/joe/mydir/myfile')
 
84
    ("joe", "/home/informatics/jails/joe", "home/joe/mydir/myfile")
91
85
 
92
86
    >>> url_to_jailpaths("")
93
87
    (None, None, None)
138
132
        return False
139
133
 
140
134
 
141
 
def authorize(req, user):
 
135
def authorize(req):
142
136
    """Given a request, checks whether req.user is allowed to
143
137
    access req.path. Returns None on authorization success. Raises
144
138
    HTTP_FORBIDDEN on failure.
151
145
    urlpath = os.path.normpath(req.path)
152
146
    # Now if it begins with ".." or separator, then it's illegal
153
147
    if urlpath.startswith("..") or urlpath.startswith(os.sep):
154
 
        return False
 
148
        req.throw_error(req.HTTP_FORBIDDEN)
155
149
 
156
150
    (owner, _) = util.split_path(urlpath)
157
 
    if user.login != owner:
158
 
        return False
159
 
    return True
 
151
    if req.user.login != owner:
 
152
        req.throw_error(req.HTTP_FORBIDDEN)
160
153
 
161
154
def authorize_public(req):
162
155
    """A different kind of authorization. Rather than making sure the
168
161
    Same interface as "authorize" - None on success, HTTP_FORBIDDEN exception
169
162
    raised on failure.
170
163
    """
171
 
    _, path = url_to_local(req.config, req.path)
172
 
 
173
 
    # Walk up the tree, and find the deepest directory.
174
 
    while not os.path.isdir(path):
175
 
        path = os.path.dirname(path)
176
 
 
177
 
    if not (worldreadable(path) and published(path)):
178
 
        return False
179
 
    return True
 
164
    _, path = url_to_local(req.path)
 
165
    dirpath, _ = os.path.split(path)
 
166
    if not (worldreadable(dirpath) and published(dirpath)):
 
167
        req.throw_error(req.HTTP_FORBIDDEN)