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

« back to all changes in this revision

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

  • Committer: William Grant
  • Date: 2009-02-25 23:04:11 UTC
  • Revision ID: grantw@unimelb.edu.au-20090225230411-lbdyl32ir0m3d59b
Make all of the services executable.

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
 
20
from ivle.webapp.base.rest import JSONRESTView, require_permission
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
 
    "rolenm", "studentid", "acct_exp", "pass_exp", "last_login",
 
31
    "admin", "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')
45
46
    def GET(self, req):
46
47
        # XXX Check Caps
47
48
        user = ivle.util.object_to_dict(user_fields_list, self.context)
53
54
        user['local_password'] = self.context.passhash is not None
54
55
        return user
55
56
 
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
 
 
70
57
class UserSettingsView(XHTMLView):
71
58
    template = 'user-settings.html'
72
 
    appname = 'settings'
 
59
    tab = 'settings'
 
60
    permission = 'edit'
73
61
 
74
62
    def __init__(self, req, login):
75
63
        self.context = ivle.database.User.get_by_login(req.store, login)
76
64
        if self.context is None:
77
65
            raise NotFound()
78
66
 
79
 
        if req.user is None or (req.user is not self.context and
80
 
                                req.user.rolenm != 'admin'):
81
 
            raise Unauthorized()
82
 
 
83
67
    def populate(self, req, ctx):
84
68
        self.plugin_scripts[Plugin] = ['settings.js']
85
69
        req.scripts_init = ['revert_settings']