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

« back to all changes in this revision

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

  • Committer: Matt Giuca
  • Date: 2009-04-28 10:43:41 UTC
  • Revision ID: matt.giuca@gmail.com-20090428104341-gb7721sqfr5zwmzz
ivle.makeuser: make_svn_auth now requires a config argument.

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
 
from ivle.webapp.base.plugins import BasePlugin
 
22
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
 
23
from ivle.webapp.errors import NotFound, Unauthorized
23
24
import ivle.database
24
25
import ivle.util
25
26
 
27
28
# (as returned by the get_user action)
28
29
user_fields_list = (
29
30
    "login", "state", "unixid", "email", "nick", "fullname",
30
 
    "rolenm", "studentid", "acct_exp", "pass_exp", "last_login",
 
31
    "admin", "studentid", "acct_exp", "pass_exp", "last_login",
31
32
    "svn_pass"
32
33
)
33
34
 
38
39
    def __init__(self, req, login):
39
40
        super(UserRESTView, self).__init__(self, req, login)
40
41
        self.context = ivle.database.User.get_by_login(req.store, login)
 
42
        if self.context is None:
 
43
            raise NotFound()
41
44
 
 
45
    @require_permission('view')
42
46
    def GET(self, req):
43
47
        # XXX Check Caps
44
48
        user = ivle.util.object_to_dict(user_fields_list, self.context)
50
54
        user['local_password'] = self.context.passhash is not None
51
55
        return user
52
56
 
53
 
    def PATCH(self, req, data):
54
 
        # XXX Check Caps
55
 
        # XXX Admins can set extra fields
56
 
        # Note: Cannot change password here (use change_password named op)
57
 
 
58
 
        for f in user_fields_list:
59
 
            try:
60
 
                field = data[f]
61
 
                if isinstance(field, str):
62
 
                    field = unicode(field)
63
 
                setattr(self.context, f, field)
64
 
            except KeyError:
65
 
                continue
66
 
 
67
57
class UserSettingsView(XHTMLView):
68
58
    template = 'user-settings.html'
69
 
    appname = 'settings'
 
59
    tab = 'settings'
 
60
    permission = 'edit'
70
61
 
71
62
    def __init__(self, req, login):
72
63
        self.context = ivle.database.User.get_by_login(req.store, login)
 
64
        if self.context is None:
 
65
            raise NotFound()
73
66
 
74
67
    def populate(self, req, ctx):
75
 
        if not self.context:
76
 
            raise NotFound()
 
68
        self.plugin_scripts[Plugin] = ['settings.js']
 
69
        req.scripts_init = ['revert_settings']
77
70
 
78
 
        req.scripts = [
79
 
            "/media/settings/settings.js",
80
 
            "/media/common/json2.js",
81
 
            "/media/common/util.js",
82
 
        ]
83
 
        req.scripts_init = [
84
 
            "revert_settings"
85
 
        ]
86
71
        ctx['login'] = self.context.login
87
72
 
88
 
class Plugin(BasePlugin):
 
73
class Plugin(ViewPlugin, MediaPlugin):
89
74
    """
90
75
    The Plugin class for the user plugin.
91
76
    """
94
79
    # (regex str, handler class, kwargs dict)
95
80
    # The kwargs dict is passed to the __init__ of the view object
96
81
    urls = [
97
 
        ('users/:login/+settings', UserSettingsView),
98
 
        ('api/users/:login', UserRESTView),
 
82
        ('~:login/+settings', UserSettingsView),
 
83
        ('api/~:login', UserRESTView),
99
84
    ]
 
85
 
 
86
    media = 'user-media'