~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-04-22 02:04:13 UTC
  • Revision ID: grantw@unimelb.edu.au-20090422020413-v2lfi31t0fh5gxfu
Allow revocation of group memberships by tutors and lecturers.
(Google Code issue #143)

Show diffs side-by-side

added added

removed removed

Lines of Context:
659
659
 
660
660
    return(cjson.encode({'response': 'okay'}))
661
661
 
 
662
@require_method('POST')
 
663
@require_role_anywhere('tutor', 'lecturer')
 
664
def handle_unassign_group(req, fields):
 
665
    """Remove a user from a project group.
 
666
 
 
667
    The user is removed from the group in the database, and access to the
 
668
    group Subversion repository is revoked.
 
669
 
 
670
    Note that any checkouts will remain, although they will be unusable.
 
671
    """
 
672
 
 
673
    # Get required fields
 
674
    login = fields.getfirst('login')
 
675
    groupid = fields.getfirst('groupid')
 
676
    if login is None or groupid is None:
 
677
        raise BadRequest("Required: login, groupid")
 
678
 
 
679
    group = req.store.get(ivle.database.ProjectGroup, int(groupid))
 
680
    user = ivle.database.User.get_by_login(req.store, login)
 
681
 
 
682
    # Remove membership from the database
 
683
    # We can't keep a transaction open until the end here, as usrmgt-server
 
684
    # needs to see the changes!
 
685
    group.members.remove(user)
 
686
    req.store.commit()
 
687
 
 
688
    # Rebuild the svn config file
 
689
    # Contact the usrmgt server
 
690
    msg = {'rebuild_svn_group_config': {}}
 
691
    try:
 
692
        usrmgt = chat.chat(usrmgt_host, usrmgt_port, msg, usrmgt_magic)
 
693
    except cjson.DecodeError, e:
 
694
        raise Exception("Could not understand usrmgt server response: %s" +
 
695
                        e.message)
 
696
 
 
697
        if 'response' not in usrmgt or usrmgt['response']=='failure':
 
698
            raise Exception("Failure creating repository: " + str(usrmgt))
 
699
 
 
700
    return(cjson.encode({'response': 'okay'}))
 
701
 
662
702
# Map action names (from the path)
663
703
# to actual function objects
664
704
actions_map = {
672
712
    "get_group_membership": handle_get_group_membership,
673
713
    "create_group": handle_create_group,
674
714
    "assign_group": handle_assign_group,
 
715
    "unassign_group": handle_unassign_group,
675
716
}