~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.views import JSONRESTView
21
 
from ivle.webapp.base.plugins import BasePlugin
 
20
from ivle.webapp.base.rest import JSONRESTView
 
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
24
import ivle.database
23
25
import ivle.util
24
26
 
37
39
    def __init__(self, req, login):
38
40
        super(UserRESTView, self).__init__(self, req, login)
39
41
        self.context = ivle.database.User.get_by_login(req.store, login)
 
42
        if self.context is None:
 
43
            raise NotFound()
40
44
 
41
45
    def GET(self, req):
42
46
        # XXX Check Caps
63
67
            except KeyError:
64
68
                continue
65
69
 
66
 
class Plugin(BasePlugin):
 
70
class UserSettingsView(XHTMLView):
 
71
    template = 'user-settings.html'
 
72
    appname = 'settings'
 
73
 
 
74
    def __init__(self, req, login):
 
75
        self.context = ivle.database.User.get_by_login(req.store, login)
 
76
        if self.context is None:
 
77
            raise NotFound()
 
78
 
 
79
        if req.user is None or (req.user is not self.context and
 
80
                                req.user.rolenm != 'admin'):
 
81
            raise Unauthorized()
 
82
 
 
83
    def populate(self, req, ctx):
 
84
        self.plugin_scripts[Plugin] = ['settings.js']
 
85
        req.scripts_init = ['revert_settings']
 
86
 
 
87
        ctx['login'] = self.context.login
 
88
 
 
89
class Plugin(ViewPlugin, MediaPlugin):
67
90
    """
68
91
    The Plugin class for the user plugin.
69
92
    """
72
95
    # (regex str, handler class, kwargs dict)
73
96
    # The kwargs dict is passed to the __init__ of the view object
74
97
    urls = [
75
 
        ('api/users/:login', UserRESTView)
 
98
        ('~:login/+settings', UserSettingsView),
 
99
        ('api/~:login', UserRESTView),
76
100
    ]
 
101
 
 
102
    media = 'user-media'