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

« back to all changes in this revision

Viewing changes to ivle/webapp/admin/user.py

Fix some issues with undefined variables in view template contexts. Genshi 0.5
is much less lenient.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
# Author: Matt Giuca, Will Grant
19
19
 
20
 
from ivle.webapp.base.rest import JSONRESTView, require_permission
 
20
from ivle.webapp.base.rest import JSONRESTView
21
21
from ivle.webapp.base.xhtml import XHTMLView
22
22
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
23
23
from ivle.webapp.errors import NotFound, Unauthorized
42
42
        if self.context is None:
43
43
            raise NotFound()
44
44
 
45
 
    @require_permission('view')
46
45
    def GET(self, req):
47
46
        # XXX Check Caps
48
47
        user = ivle.util.object_to_dict(user_fields_list, self.context)
54
53
        user['local_password'] = self.context.passhash is not None
55
54
        return user
56
55
 
57
 
    @require_permission('edit')
58
56
    def PATCH(self, req, data):
 
57
        # XXX Check Caps
59
58
        # XXX Admins can set extra fields
60
59
        # Note: Cannot change password here (use change_password named op)
61
60
 
71
70
class UserSettingsView(XHTMLView):
72
71
    template = 'user-settings.html'
73
72
    appname = 'settings'
74
 
    permission = 'edit'
75
73
 
76
74
    def __init__(self, req, login):
77
75
        self.context = ivle.database.User.get_by_login(req.store, login)
78
76
        if self.context is None:
79
77
            raise NotFound()
80
78
 
 
79
        if req.user is None or (req.user is not self.context and
 
80
                                req.user.rolenm != 'admin'):
 
81
            raise Unauthorized()
 
82
 
81
83
    def populate(self, req, ctx):
82
84
        self.plugin_scripts[Plugin] = ['settings.js']
83
85
        req.scripts_init = ['revert_settings']