1099.1.1
by Matt Giuca
Began implementing new dispatch framework (with Will Grant and Nick Chadwick). |
1 |
# IVLE - Informatics Virtual Learning Environment
|
2 |
# Copyright (C) 2007-2009 The University of Melbourne
|
|
3 |
#
|
|
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
16 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
17 |
||
18 |
# Author: Matt Giuca, Will Grant
|
|
19 |
||
20 |
from ivle.webapp.base.views import JSONRESTView |
|
21 |
from ivle.webapp.base.plugins import BasePlugin |
|
22 |
import ivle.database |
|
23 |
import ivle.util |
|
24 |
||
25 |
# List of fields returned as part of the user JSON dictionary
|
|
26 |
# (as returned by the get_user action)
|
|
27 |
user_fields_list = ( |
|
28 |
"login", "state", "unixid", "email", "nick", "fullname", |
|
29 |
"rolenm", "studentid", "acct_exp", "pass_exp", "last_login", |
|
30 |
"svn_pass"
|
|
31 |
)
|
|
32 |
||
33 |
class UserRESTView(JSONRESTView): |
|
34 |
"""
|
|
35 |
A REST interface to the user object.
|
|
36 |
"""
|
|
37 |
def __init__(self, req, login): |
|
38 |
super(UserRESTView, self).__init__(self, req, login) |
|
39 |
self.context = ivle.database.User.get_by_login(req.store, login) |
|
40 |
||
41 |
def GET(self, req): |
|
42 |
# XXX Check Caps
|
|
43 |
user = ivle.util.object_to_dict(user_fields_list, self.context) |
|
44 |
# Convert time stamps to nice strings
|
|
45 |
for k in 'pass_exp', 'acct_exp', 'last_login': |
|
46 |
if user[k] is not None: |
|
47 |
user[k] = unicode(user[k]) |
|
48 |
||
49 |
user['local_password'] = self.context.passhash is not None |
|
50 |
return user |
|
51 |
||
52 |
def PATCH(self, req, data): |
|
53 |
# XXX Check Caps
|
|
54 |
# XXX Admins can set extra fields
|
|
55 |
# Note: Cannot change password here (use change_password named op)
|
|
56 |
||
57 |
for f in user_fields_list: |
|
58 |
try: |
|
59 |
field = data[f] |
|
60 |
if isinstance(field, str): |
|
61 |
field = unicode(field) |
|
62 |
setattr(self.context, f, field) |
|
63 |
except KeyError: |
|
64 |
continue
|
|
65 |
||
66 |
class Plugin(BasePlugin): |
|
67 |
"""
|
|
68 |
The Plugin class for the user plugin.
|
|
69 |
"""
|
|
70 |
# Magic attribute: urls
|
|
71 |
# Sequence of pairs/triples of
|
|
72 |
# (regex str, handler class, kwargs dict)
|
|
73 |
# The kwargs dict is passed to the __init__ of the view object
|
|
74 |
urls = [ |
|
1099.1.2
by William Grant
ivle.webapp.admin.user.Plugin: Use 'users' in the URL, not 'user'. |
75 |
('api/users/:login', UserRESTView) |
1099.1.1
by Matt Giuca
Began implementing new dispatch framework (with Will Grant and Nick Chadwick). |
76 |
]
|