~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: 2010-02-18 05:33:30 UTC
  • Revision ID: matt.giuca@gmail.com-20100218053330-c3kuixsazmxtg49i
Correct locale setting for Subversion. Previously pysvn would throw a nasty
error on non-ASCII UTF-8 filenames, because its locale was not set to UTF-8.
Now locale.setlocale is called on all Python scripts which use pysvn
(ivle-fetchsubmissions, ivle.fileservice_lib, diffservice, svnlogservice).

bin/ivle-buildjail: Now runs locale-gen as root inside the jail when run with
-u. This is necessary to make en_US.UTF-8 a valid locale; otherwise ALL JAIL
CODE will now crash!

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import formencode.validators
22
22
from genshi.filters import HTMLFormFiller
23
23
 
 
24
from ivle.webapp import ApplicationRoot
24
25
from ivle.webapp.base.rest import JSONRESTView, require_permission
25
26
from ivle.webapp.base.xhtml import XHTMLView
26
27
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
27
28
from ivle.webapp.admin.publishing import root_to_user, user_url
 
29
from ivle.database import User
28
30
import ivle.database
29
31
import ivle.date
30
32
import ivle.util
31
33
 
 
34
 
 
35
class UsersView(XHTMLView):
 
36
    """A list of all IVLE users."""
 
37
    template = 'templates/users.html'
 
38
    tab = 'users'
 
39
    breadcrumb_text = 'Users'
 
40
 
 
41
    def authorize(self, req):
 
42
        return req.user and req.user.admin
 
43
 
 
44
    def populate(self, req, ctx):
 
45
        ctx['req'] = req
 
46
        ctx['users'] = req.store.find(User).order_by(User.login)
 
47
 
 
48
 
32
49
# List of fields returned as part of the user JSON dictionary
33
50
# (as returned by the get_user action)
34
51
user_fields_list = (
62
79
class UserEditView(XHTMLView):
63
80
    """A form to change a user's details."""
64
81
    template = 'templates/user-edit.html'
65
 
    tab = 'settings'
 
82
    tab = 'users'
66
83
    permission = 'edit'
67
84
 
68
85
    def filter(self, stream, ctx):
97
114
 
98
115
class UserAdminSchema(formencode.Schema):
99
116
    admin = formencode.validators.StringBoolean(if_missing=False)
 
117
    disabled = formencode.validators.StringBoolean(if_missing=False)
100
118
    fullname = formencode.validators.UnicodeString(not_empty=True)
101
119
    studentid = formencode.validators.UnicodeString(not_empty=False,
102
120
                                                    if_missing=None
105
123
class UserAdminView(XHTMLView):
106
124
    """A form for admins to change more of a user's details."""
107
125
    template = 'templates/user-admin.html'
108
 
    tab = 'settings'
 
126
    tab = 'users'
109
127
 
110
128
    def authorize(self, req):
111
129
        """Only allow access if the requesting user is an admin."""
112
 
        return req.user.admin
 
130
        return req.user and req.user.admin
113
131
 
114
132
    def filter(self, stream, ctx):
115
133
        return stream | HTMLFormFiller(data=ctx['data'])
121
139
                validator = UserAdminSchema()
122
140
                data = validator.to_python(data, state=req)
123
141
 
124
 
                self.context.admin = data['admin']
 
142
                if self.context is req.user:
 
143
                    # Admin checkbox is disabled -- assume unchanged
 
144
                    data['admin'] = self.context.admin
 
145
                    data['disabled'] = self.context.state == u'disabled'
 
146
                else:
 
147
                    self.context.admin = data['admin']
 
148
                    if self.context.state in (u'enabled', u'disabled'):
 
149
                        self.context.state = (u'disabled' if data['disabled']
 
150
                                else u'enabled')
125
151
                self.context.fullname = data['fullname'] \
126
152
                                        if data['fullname'] else None
127
153
                self.context.studentid = data['studentid'] \
132
158
                errors = e.unpack_errors()
133
159
        else:
134
160
            data = {'admin': self.context.admin,
 
161
                    'disabled': self.context.state == u'disabled',
135
162
                    'fullname': self.context.fullname,
136
163
                    'studentid': self.context.studentid,
137
164
                   }
139
166
 
140
167
        ctx['req'] = req
141
168
        ctx['user'] = self.context
 
169
        # Disable the Admin checkbox if editing oneself
 
170
        ctx['disable_admin'] = self.context is req.user
142
171
        ctx['data'] = data
143
172
        ctx['errors'] = errors
144
173
 
145
174
class PasswordChangeView(XHTMLView):
146
175
    """A form to change a user's password, with knowledge of the old one."""
147
176
    template = 'templates/user-password-change.html'
148
 
    tab = 'settings'
 
177
    tab = 'users'
149
178
    permission = 'edit'
150
179
 
151
180
    def authorize(self, req):
179
208
class PasswordResetView(XHTMLView):
180
209
    """A form to reset a user's password, without knowledge of the old one."""
181
210
    template = 'templates/user-password-reset.html'
182
 
    tab = 'settings'
 
211
    tab = 'users'
183
212
 
184
213
    def authorize(self, req):
185
214
        """Only allow access if the requesting user is an admin."""
186
 
        return req.user.admin
 
215
        return req.user and req.user.admin
187
216
 
188
217
    def populate(self, req, ctx):
189
218
        error = None
208
237
 
209
238
    forward_routes = (root_to_user,)
210
239
    reverse_routes = (user_url,)
211
 
    views = [(ivle.database.User, '+edit', UserEditView),
 
240
    views = [(ApplicationRoot, 'users', UsersView),
 
241
             (ivle.database.User, '+index', UserEditView),
212
242
             (ivle.database.User, '+admin', UserAdminView),
213
243
             (ivle.database.User, '+changepassword', PasswordChangeView),
214
244
             (ivle.database.User, '+resetpassword', PasswordResetView),
215
245
             (ivle.database.User, '+index', UserRESTView, 'api'),
216
246
             ]
217
247
 
 
248
    tabs = [
 
249
        ('users', 'Users', 'Display and edit all users',
 
250
         'users.png', 'users', 90, True)
 
251
    ]
 
252
 
218
253
    public_forward_routes = forward_routes
219
254
    public_reverse_routes = reverse_routes
220
255