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

« back to all changes in this revision

Viewing changes to ivle/webapp/userservice/__init__.py

  • Committer: William Grant
  • Date: 2009-02-24 13:29:44 UTC
  • Revision ID: grantw@unimelb.edu.au-20090224132944-lm29zd1li1rjg77p
Privileges (apart from admin) are now offering-local, not global.

Offering privileges are granted by Enrolment.role, and global admin
by User.admin. ivle.caps is dead.

Show diffs side-by-side

added added

removed removed

Lines of Context:
138
138
import cjson
139
139
 
140
140
import ivle.database
141
 
from ivle import (util, chat, caps)
 
141
from ivle import (util, chat)
142
142
from ivle.conf import (usrmgt_host, usrmgt_port, usrmgt_magic)
143
143
from ivle.webapp.security import get_user_details
144
144
import ivle.pulldown_subj
145
145
 
146
 
from ivle.rpc.decorators import require_method, require_cap
 
146
from ivle.rpc.decorators import require_method, require_role_anywhere, \
 
147
                                require_admin
147
148
 
148
149
from ivle.auth import AuthError, authenticate
149
150
import urllib
160
161
# (as returned by the get_user action)
161
162
user_fields_list = (
162
163
    "login", "state", "unixid", "email", "nick", "fullname",
163
 
    "rolenm", "studentid", "acct_exp", "pass_exp", "last_login",
 
164
    "admin", "studentid", "acct_exp", "pass_exp", "last_login",
164
165
    "svn_pass"
165
166
)
166
167
 
270
271
    req.write(cjson.encode(response))
271
272
 
272
273
create_user_fields_required = [
273
 
    'login', 'fullname', 'rolenm'
 
274
    'login', 'fullname',
274
275
]
275
276
create_user_fields_optional = [
276
 
    'password', 'nick', 'email', 'studentid'
 
277
    'admin', 'password', 'nick', 'email', 'studentid'
277
278
]
278
279
 
279
280
@require_method('POST')
280
 
@require_cap(caps.CAP_UPDATEUSER)
 
281
@require_admin
281
282
def handle_create_user(req, fields):
282
283
    """Create a new user, whose state is no_agreement.
283
284
    This does not create the user's jail, just an entry in the database which
296
297
        fullname    - The name of the user for results and/or other official
297
298
                      purposes.
298
299
                      STRING REQUIRED
299
 
        rolenm      - The user's role. Must be one of "anyone", "student",
300
 
                      "tutor", "lecturer", "admin".
301
 
                      STRING/ENUM REQUIRED
 
300
        admin       - Whether the user is an admin.
 
301
                      BOOLEAN REQUIRED
302
302
        studentid   - If supplied and not None, the student id of the user for
303
303
                      results and/or other official purposes.
304
304
                      STRING OPTIONAL
330
330
    'password', 'nick', 'email'
331
331
]
332
332
update_user_fields_admin = [
333
 
    'password', 'nick', 'email', 'rolenm', 'unixid', 'fullname',
 
333
    'password', 'nick', 'email', 'admin', 'unixid', 'fullname',
334
334
    'studentid'
335
335
]
336
336
 
338
338
def handle_update_user(req, fields):
339
339
    """Update a user's account details.
340
340
    This can be done in a limited form by any user, on their own account,
341
 
    or with full powers by a user with CAP_UPDATEUSER on any account.
 
341
    or with full powers by an admin user on any account.
342
342
    """
343
 
    # Only give full powers if this user has CAP_UPDATEUSER
344
 
    fullpowers = req.user.hasCap(caps.CAP_UPDATEUSER)
 
343
    # Only give full powers if this user is an admin.
 
344
    fullpowers = req.user.admin
345
345
    # List of fields that may be changed
346
346
    fieldlist = (update_user_fields_admin if fullpowers
347
347
        else update_user_fields_anyone)
392
392
    module is willing to give up, EXCEPT the following fields:
393
393
        svn_pass
394
394
    """
395
 
    # Only give full powers if this user has CAP_GETUSER
396
 
    fullpowers = req.user.hasCap(caps.CAP_GETUSER)
 
395
    # Only give full powers if this user is an admin
 
396
    fullpowers = req.user.admin
397
397
 
398
398
    try:
399
399
        login = fields.getfirst('login')
426
426
    """
427
427
    # For the moment we're only able to query ourselves
428
428
    fullpowers = False
429
 
    ## Only give full powers if this user has CAP_GETUSER
430
 
    ##fullpowers = req.user.hasCap(caps.CAP_GETUSER)
431
429
 
432
430
    try:
433
431
        user = ivle.database.User.get_by_login(req.store,
515
513
    req.write(response)
516
514
 
517
515
@require_method('POST')
518
 
@require_cap(caps.CAP_MANAGEGROUPS)
 
516
@require_role_anywhere('tutor', 'lecturer')
519
517
def handle_create_group(req, fields):
520
518
    """Required cap: CAP_MANAGEGROUPS
521
519
    Creates a project group in a specific project set
625
623
    req.write(response)
626
624
 
627
625
@require_method('POST')
628
 
@require_cap(caps.CAP_MANAGEGROUPS)
 
626
@require_role_anywhere('tutor', 'lecturer')
629
627
def handle_assign_group(req, fields):
630
628
    """ Required cap: CAP_MANAGEGROUPS
631
629
    Assigns a user to a project group