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

« back to all changes in this revision

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

Reimplement setup/buildjail.sh in Python. This means that sites can configure
additional repositories and packages to include in the jail, without modifying
the source tree.

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
28
28
# (as returned by the get_user action)
29
29
user_fields_list = (
30
30
    "login", "state", "unixid", "email", "nick", "fullname",
31
 
    "admin", "studentid", "acct_exp", "pass_exp", "last_login",
 
31
    "rolenm", "studentid", "acct_exp", "pass_exp", "last_login",
32
32
    "svn_pass"
33
33
)
34
34
 
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
 
 
56
    def PATCH(self, req, data):
 
57
        # XXX Check Caps
 
58
        # XXX Admins can set extra fields
 
59
        # Note: Cannot change password here (use change_password named op)
 
60
 
 
61
        for f in user_fields_list:
 
62
            try:
 
63
                field = data[f]
 
64
                if isinstance(field, str):
 
65
                    field = unicode(field)
 
66
                setattr(self.context, f, field)
 
67
            except KeyError:
 
68
                continue
 
69
 
57
70
class UserSettingsView(XHTMLView):
58
 
    template = 'templates/user-settings.html'
59
 
    tab = 'settings'
60
 
    permission = 'edit'
 
71
    template = 'user-settings.html'
 
72
    appname = 'settings'
61
73
 
62
74
    def __init__(self, req, login):
63
75
        self.context = ivle.database.User.get_by_login(req.store, login)
64
76
        if self.context is None:
65
77
            raise NotFound()
66
78
 
 
79
        if req.user is None or (req.user is not self.context and
 
80
                                req.user.rolenm != 'admin'):
 
81
            raise Unauthorized()
 
82
 
67
83
    def populate(self, req, ctx):
68
84
        self.plugin_scripts[Plugin] = ['settings.js']
69
85
        req.scripts_init = ['revert_settings']