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

« back to all changes in this revision

Viewing changes to www/apps/userservice/__init__.py

  • Committer: dcoles
  • Date: 2008-07-22 01:22:36 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:930
Userservice: Added get_enrolments handler to allow a JSON query of a students 
enrolement details

Groups: Modified so consistent with db.py changes. Is returning a dict a more 
stable interface than tuples? Certainly more convenient for client side.

Show diffs side-by-side

added added

removed removed

Lines of Context:
81
81
# Disable a user's account. Does not work for no_agreement or pending users.
82
82
# login = Login name of user to disable.
83
83
 
 
84
# userservice/get_enrolments
 
85
# Required cap: None (for yourself)
 
86
# Returns a JSON encoded listing of a students is enrollments
 
87
 
84
88
import os
85
89
import sys
86
90
 
408
412
    req.content_type = "text/plain"
409
413
    req.write(response)
410
414
 
 
415
def handle_get_enrolments(req, fields):
 
416
    """
 
417
    Retrieve a user's enrolment details.
 
418
    """
 
419
    # For the moment we're only able to query ourselves
 
420
    fullpowers = False
 
421
    ## Only give full powers if this user has CAP_GETUSER
 
422
    ##fullpowers = req.user.hasCap(caps.CAP_GETUSER)
 
423
 
 
424
    try:
 
425
        login = fields.getfirst('login')
 
426
        if login is None:
 
427
            raise AttributeError()
 
428
        if not fullpowers and login != req.user.login:
 
429
            # Not allowed to edit other users
 
430
            req.throw_error(req.HTTP_FORBIDDEN,
 
431
            "You do not have permission to see another user's subjects.")
 
432
    except AttributeError:
 
433
        # If login not specified, update yourself
 
434
        login = req.user.login
 
435
 
 
436
    # Just talk direct to the DB
 
437
    db = common.db.DB()
 
438
    enrolments = db.get_enrolment(login)
 
439
    db.close()
 
440
    response = cjson.encode(enrolments)
 
441
    req.content_type = "text/plain"
 
442
    req.write(response)
 
443
 
411
444
# Map action names (from the path)
412
445
# to actual function objects
413
446
actions_map = {
416
449
    "create_user": handle_create_user,
417
450
    "update_user": handle_update_user,
418
451
    "get_user": handle_get_user,
 
452
    "get_enrolments": handle_get_enrolments,
419
453
}