~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: 2009-12-09 00:02:49 UTC
  • mto: This revision was merged to the branch mainline in revision 1384.
  • Revision ID: grantw@unimelb.edu.au-20091209000249-y1teiw7yxkyhuhvd
Indicate when there is nobody assigned to a project, and link to the page to fix that.

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