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

« back to all changes in this revision

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

ivle.webapp.browser: Move to ivle.webapp.filesystem.browser.

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