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

« back to all changes in this revision

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

fixed a slight bug on line 155, which referenced a non-existant variable

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
 
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
 
 
57
    @require_permission('edit')
53
58
    def PATCH(self, req, data):
54
 
        # XXX Check Caps
55
59
        # XXX Admins can set extra fields
56
60
        # Note: Cannot change password here (use change_password named op)
57
61
 
67
71
class UserSettingsView(XHTMLView):
68
72
    template = 'user-settings.html'
69
73
    appname = 'settings'
 
74
    permission = 'edit'
70
75
 
71
76
    def __init__(self, req, login):
72
77
        self.context = ivle.database.User.get_by_login(req.store, login)
 
78
        if self.context is None:
 
79
            raise NotFound()
73
80
 
74
81
    def populate(self, req, ctx):
75
 
        if not self.context:
76
 
            raise NotFound()
 
82
        self.plugin_scripts[Plugin] = ['settings.js']
 
83
        req.scripts_init = ['revert_settings']
77
84
 
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
85
        ctx['login'] = self.context.login
87
86
 
88
 
class Plugin(BasePlugin):
 
87
class Plugin(ViewPlugin, MediaPlugin):
89
88
    """
90
89
    The Plugin class for the user plugin.
91
90
    """
94
93
    # (regex str, handler class, kwargs dict)
95
94
    # The kwargs dict is passed to the __init__ of the view object
96
95
    urls = [
97
 
        ('users/:login/+settings', UserSettingsView),
98
 
        ('api/users/:login', UserRESTView),
 
96
        ('~:login/+settings', UserSettingsView),
 
97
        ('api/~:login', UserRESTView),
99
98
    ]
 
99
 
 
100
    media = 'user-media'