24
24
from ivle.webapp.base.rest import JSONRESTView, require_permission
25
25
from ivle.webapp.base.xhtml import XHTMLView
26
26
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
27
from ivle.webapp.errors import NotFound, Unauthorized
27
from ivle.webapp.admin.publishing import root_to_user, user_url
28
28
import ivle.database
42
42
A REST interface to the user object.
44
def __init__(self, req, login):
45
super(UserRESTView, self).__init__(self, req, login)
46
self.context = ivle.database.User.get_by_login(req.store, login)
47
if self.context is None:
50
45
@require_permission('view')
51
46
def GET(self, req):
71
66
permission = 'edit'
73
def __init__(self, req, login):
74
self.context = ivle.database.User.get_by_login(req.store, login)
75
if self.context is None:
78
68
def filter(self, stream, ctx):
79
69
return stream | HTMLFormFiller(data=ctx['data'])
117
107
template = 'templates/user-admin.html'
120
def __init__(self, req, login):
121
self.context = ivle.database.User.get_by_login(req.store, login)
122
if self.context is None:
125
110
def authorize(self, req):
126
111
"""Only allow access if the requesting user is an admin."""
127
112
return req.user.admin
164
149
permission = 'edit'
166
def __init__(self, req, login):
167
self.context = ivle.database.User.get_by_login(req.store, login)
168
if self.context is None:
171
151
def authorize(self, req):
172
152
"""Only allow access if the requesting user holds the permission,
173
153
and the target user has a password set. Otherwise we might be
201
181
template = 'templates/user-password-reset.html'
204
def __init__(self, req, login):
205
self.context = ivle.database.User.get_by_login(req.store, login)
206
if self.context is None:
209
184
def authorize(self, req):
210
185
"""Only allow access if the requesting user is an admin."""
211
186
return req.user.admin
231
206
The Plugin class for the user plugin.
233
# Magic attribute: urls
234
# Sequence of pairs/triples of
235
# (regex str, handler class, kwargs dict)
236
# The kwargs dict is passed to the __init__ of the view object
238
('~:login/+edit', UserEditView),
239
('~:login/+admin', UserAdminView),
240
('~:login/+changepassword', PasswordChangeView),
241
('~:login/+resetpassword', PasswordResetView),
242
('api/~:login', UserRESTView),
209
forward_routes = (root_to_user,)
210
reverse_routes = (user_url,)
211
views = [(ivle.database.User, '+edit', UserEditView),
212
(ivle.database.User, '+admin', UserAdminView),
213
(ivle.database.User, '+changepassword', PasswordChangeView),
214
(ivle.database.User, '+resetpassword', PasswordResetView),
215
(ivle.database.User, '+index', UserRESTView, 'api'),
218
public_forward_routes = forward_routes
219
public_reverse_routes = reverse_routes
245
221
media = 'user-media'