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

« back to all changes in this revision

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

[Uber-commit of holiday work because I lacked a local copy of the branch.]

 ivle.makeuser: Don't use jailconf.py as a header for the in-jail conf.py;
     generate the whole thing using string formatting operators and include
     the template inline.

 ivle.makeuser.make_conf_py: XXX the inclusion of ivle.conf.jail_base in
     the jail. It is simply there to placate ivle.studpath, and needs
     to go before we can entirely remove the in-jail config.

 ivle-buildjail:
   - Add. Converted from setup.buildjail.
   - Build the jail in __base_build__ and rsync it to __base__ when
     done, rather than operating only in ./jail
   - Rename --rebuildjail/-j to --recreate/-r, as the whole script
     is now for jail rebuilding. Also add a warning to the usage string about
     the large volume likely to be downloaded.
   - Check existence before removing trees.
   - Don't copy jailconf.py over conf.py in the jail. Also make
     sure that we remove conf.pyc.

 setup.configure:
   - Stop generating jailconf.py at all.
   - Add a jail_system_build setting, defaulting to __base_build__ next to
     the existing __base__.
   - Don't use an OptionParser before calling the real function, as that
     adds options dynamically.

 setup.install:
   - Add an option (-R) to avoid writing out svn revision info to
     $PREFIX/share/ivle/revision.txt.
   - Remove jail-copying things.
   - Install all services to the host, rather than just usrmgt-server. We do
     this so we can build the jail from the host without the source tree.
   - Shuffle some things, and don't install phpBB3 twice.
   - Add a --root argument, to take an alternate root directory to install
     into (as given to autotools in $DESTDIR).

 setup.build:
   - Allow running as non-root.
   - Take a --no-compile option to not byte-compile Python files.

 setup.util:
   - Include usrmgt-server in the list of services.
   - Add make_install_path(), a wrapper around os.path.join() that ensures
     the second path is relative.
   - Install ivle-buildjail with the other binaries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# IVLE - Informatics Virtual Learning Environment
2
 
# Copyright (C) 2007-2009 The University of Melbourne
3
 
#
4
 
# This program is free software; you can redistribute it and/or modify
5
 
# it under the terms of the GNU General Public License as published by
6
 
# the Free Software Foundation; either version 2 of the License, or
7
 
# (at your option) any later version.
8
 
#
9
 
# This program is distributed in the hope that it will be useful,
10
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
# GNU General Public License for more details.
13
 
#
14
 
# You should have received a copy of the GNU General Public License
15
 
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
 
 
18
 
# Author: Matt Giuca, Will Grant
19
 
 
20
 
from ivle.webapp.base.rest import JSONRESTView, require_permission
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
24
 
import ivle.database
25
 
import ivle.util
26
 
 
27
 
# List of fields returned as part of the user JSON dictionary
28
 
# (as returned by the get_user action)
29
 
user_fields_list = (
30
 
    "login", "state", "unixid", "email", "nick", "fullname",
31
 
    "admin", "studentid", "acct_exp", "pass_exp", "last_login",
32
 
    "svn_pass"
33
 
)
34
 
 
35
 
class UserRESTView(JSONRESTView):
36
 
    """
37
 
    A REST interface to the user object.
38
 
    """
39
 
    def __init__(self, req, login):
40
 
        super(UserRESTView, self).__init__(self, req, login)
41
 
        self.context = ivle.database.User.get_by_login(req.store, login)
42
 
        if self.context is None:
43
 
            raise NotFound()
44
 
 
45
 
    @require_permission('view')
46
 
    def GET(self, req):
47
 
        # XXX Check Caps
48
 
        user = ivle.util.object_to_dict(user_fields_list, self.context)
49
 
        # Convert time stamps to nice strings
50
 
        for k in 'pass_exp', 'acct_exp', 'last_login':
51
 
            if user[k] is not None:
52
 
                user[k] = unicode(user[k])
53
 
 
54
 
        user['local_password'] = self.context.passhash is not None
55
 
        return user
56
 
 
57
 
class UserSettingsView(XHTMLView):
58
 
    template = 'user-settings.html'
59
 
    tab = 'settings'
60
 
    permission = 'edit'
61
 
 
62
 
    def __init__(self, req, login):
63
 
        self.context = ivle.database.User.get_by_login(req.store, login)
64
 
        if self.context is None:
65
 
            raise NotFound()
66
 
 
67
 
    def populate(self, req, ctx):
68
 
        self.plugin_scripts[Plugin] = ['settings.js']
69
 
        req.scripts_init = ['revert_settings']
70
 
 
71
 
        ctx['login'] = self.context.login
72
 
 
73
 
class Plugin(ViewPlugin, MediaPlugin):
74
 
    """
75
 
    The Plugin class for the user plugin.
76
 
    """
77
 
    # Magic attribute: urls
78
 
    # Sequence of pairs/triples of
79
 
    # (regex str, handler class, kwargs dict)
80
 
    # The kwargs dict is passed to the __init__ of the view object
81
 
    urls = [
82
 
        ('~:login/+settings', UserSettingsView),
83
 
        ('api/~:login', UserRESTView),
84
 
    ]
85
 
 
86
 
    media = 'user-media'