22
22
from genshi.filters import HTMLFormFiller
24
24
from ivle.webapp import ApplicationRoot
25
from ivle.webapp.base.rest import JSONRESTView, require_permission
26
25
from ivle.webapp.base.xhtml import XHTMLView
27
26
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
28
27
from ivle.webapp.admin.publishing import root_to_user, user_url
29
28
from ivle.database import User
35
32
class UsersView(XHTMLView):
46
43
ctx['users'] = req.store.find(User).order_by(User.login)
49
# List of fields returned as part of the user JSON dictionary
50
# (as returned by the get_user action)
52
"login", "state", "unixid", "email", "nick", "fullname",
53
"admin", "studentid", "acct_exp", "pass_exp", "last_login",
57
class UserRESTView(JSONRESTView):
59
A REST interface to the user object.
62
@require_permission('view')
65
user = ivle.util.object_to_dict(user_fields_list, self.context)
66
# Convert time stamps to nice strings
67
for k in 'pass_exp', 'acct_exp', 'last_login':
68
if user[k] is not None:
69
user[k] = unicode(user[k])
71
user['local_password'] = self.context.passhash is not None
74
46
class UserEditSchema(formencode.Schema):
75
47
nick = formencode.validators.UnicodeString(not_empty=True)
76
48
email = formencode.validators.Email(not_empty=False,
238
210
forward_routes = (root_to_user,)
239
211
reverse_routes = (user_url,)
240
212
views = [(ApplicationRoot, 'users', UsersView),
241
(ivle.database.User, '+index', UserEditView),
242
(ivle.database.User, '+admin', UserAdminView),
243
(ivle.database.User, '+changepassword', PasswordChangeView),
244
(ivle.database.User, '+resetpassword', PasswordResetView),
245
(ivle.database.User, '+index', UserRESTView, 'api'),
213
(User, '+index', UserEditView),
214
(User, '+admin', UserAdminView),
215
(User, '+changepassword', PasswordChangeView),
216
(User, '+resetpassword', PasswordResetView),