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

« back to all changes in this revision

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

  • Committer: William Grant
  • Date: 2010-02-15 05:37:50 UTC
  • Revision ID: grantw@unimelb.edu.au-20100215053750-hihmegnp8e7dshc2
Ignore test coverage files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
class UsersView(XHTMLView):
36
36
    """A list of all IVLE users."""
37
37
    template = 'templates/users.html'
 
38
    tab = 'users'
 
39
    breadcrumb_text = 'Users'
38
40
 
39
41
    def authorize(self, req):
40
 
        return req.user.admin
 
42
        return req.user and req.user.admin
41
43
 
42
44
    def populate(self, req, ctx):
43
45
        ctx['req'] = req
77
79
class UserEditView(XHTMLView):
78
80
    """A form to change a user's details."""
79
81
    template = 'templates/user-edit.html'
80
 
    tab = 'settings'
 
82
    tab = 'users'
81
83
    permission = 'edit'
82
84
 
83
85
    def filter(self, stream, ctx):
112
114
 
113
115
class UserAdminSchema(formencode.Schema):
114
116
    admin = formencode.validators.StringBoolean(if_missing=False)
 
117
    disabled = formencode.validators.StringBoolean(if_missing=False)
115
118
    fullname = formencode.validators.UnicodeString(not_empty=True)
116
119
    studentid = formencode.validators.UnicodeString(not_empty=False,
117
120
                                                    if_missing=None
120
123
class UserAdminView(XHTMLView):
121
124
    """A form for admins to change more of a user's details."""
122
125
    template = 'templates/user-admin.html'
123
 
    tab = 'settings'
 
126
    tab = 'users'
124
127
 
125
128
    def authorize(self, req):
126
129
        """Only allow access if the requesting user is an admin."""
127
 
        return req.user.admin
 
130
        return req.user and req.user.admin
128
131
 
129
132
    def filter(self, stream, ctx):
130
133
        return stream | HTMLFormFiller(data=ctx['data'])
136
139
                validator = UserAdminSchema()
137
140
                data = validator.to_python(data, state=req)
138
141
 
139
 
                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')
140
151
                self.context.fullname = data['fullname'] \
141
152
                                        if data['fullname'] else None
142
153
                self.context.studentid = data['studentid'] \
147
158
                errors = e.unpack_errors()
148
159
        else:
149
160
            data = {'admin': self.context.admin,
 
161
                    'disabled': self.context.state == u'disabled',
150
162
                    'fullname': self.context.fullname,
151
163
                    'studentid': self.context.studentid,
152
164
                   }
154
166
 
155
167
        ctx['req'] = req
156
168
        ctx['user'] = self.context
 
169
        # Disable the Admin checkbox if editing oneself
 
170
        ctx['disable_admin'] = self.context is req.user
157
171
        ctx['data'] = data
158
172
        ctx['errors'] = errors
159
173
 
160
174
class PasswordChangeView(XHTMLView):
161
175
    """A form to change a user's password, with knowledge of the old one."""
162
176
    template = 'templates/user-password-change.html'
163
 
    tab = 'settings'
 
177
    tab = 'users'
164
178
    permission = 'edit'
165
179
 
166
180
    def authorize(self, req):
194
208
class PasswordResetView(XHTMLView):
195
209
    """A form to reset a user's password, without knowledge of the old one."""
196
210
    template = 'templates/user-password-reset.html'
197
 
    tab = 'settings'
 
211
    tab = 'users'
198
212
 
199
213
    def authorize(self, req):
200
214
        """Only allow access if the requesting user is an admin."""
201
 
        return req.user.admin
 
215
        return req.user and req.user.admin
202
216
 
203
217
    def populate(self, req, ctx):
204
218
        error = None
231
245
             (ivle.database.User, '+index', UserRESTView, 'api'),
232
246
             ]
233
247
 
 
248
    tabs = [
 
249
        ('users', 'Users', 'Display and edit all users',
 
250
         'users.png', 'users', 90, True)
 
251
    ]
 
252
 
234
253
    public_forward_routes = forward_routes
235
254
    public_reverse_routes = reverse_routes
236
255