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

« back to all changes in this revision

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

  • Committer: Matt Giuca
  • Date: 2009-05-19 02:54:08 UTC
  • mfrom: (1258 trunk)
  • mto: This revision was merged to the branch mainline in revision 1322.
  • Revision ID: matt.giuca@gmail.com-20090519025408-19c7cjl7w6ot6frm
MergedĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
139
139
 
140
140
import ivle.database
141
141
from ivle import (util, chat)
142
 
from ivle.conf import (usrmgt_host, usrmgt_port, usrmgt_magic)
143
142
from ivle.webapp.security import get_user_details
144
143
import ivle.pulldown_subj
145
144
 
249
248
 
250
249
    # Try and contact the usrmgt server
251
250
    try:
252
 
        response = chat.chat(usrmgt_host, usrmgt_port, msg, usrmgt_magic)
 
251
        response = chat.chat(req.config['usrmgt']['host'],
 
252
                             req.config['usrmgt']['port'],
 
253
                             msg,
 
254
                             req.config['usrmgt']['magic'],
 
255
                            )
253
256
    except cjson.DecodeError:
254
257
        # Gave back rubbish - set the response to failure
255
258
        response = {'response': 'usrmgt-failure'}
564
567
 
565
568
    # Contact the usrmgt server
566
569
    try:
567
 
        usrmgt = chat.chat(usrmgt_host, usrmgt_port, msg, usrmgt_magic)
 
570
        usrmgt = chat.chat(req.config['usrmgt']['host'],
 
571
                           req.config['usrmgt']['port'],
 
572
                           msg,
 
573
                           req.config['usrmgt']['magic'],
 
574
                          )
568
575
    except cjson.DecodeError, e:
569
576
        raise Exception("Could not understand usrmgt server response:" +
570
577
                        e.message)
649
656
    # Contact the usrmgt server
650
657
    msg = {'rebuild_svn_group_config': {}}
651
658
    try:
652
 
        usrmgt = chat.chat(usrmgt_host, usrmgt_port, msg, usrmgt_magic)
 
659
        usrmgt = chat.chat(req.config['usrmgt']['host'],
 
660
                           req.config['usrmgt']['port'],
 
661
                           msg,
 
662
                           req.config['usrmgt']['magic'],
 
663
                          )
 
664
    except cjson.DecodeError, e:
 
665
        raise Exception("Could not understand usrmgt server response: %s" +
 
666
                        e.message)
 
667
 
 
668
        if 'response' not in usrmgt or usrmgt['response']=='failure':
 
669
            raise Exception("Failure creating repository: " + str(usrmgt))
 
670
 
 
671
    return(cjson.encode({'response': 'okay'}))
 
672
 
 
673
@require_method('POST')
 
674
@require_role_anywhere('tutor', 'lecturer')
 
675
def handle_unassign_group(req, fields):
 
676
    """Remove a user from a project group.
 
677
 
 
678
    The user is removed from the group in the database, and access to the
 
679
    group Subversion repository is revoked.
 
680
 
 
681
    Note that any checkouts will remain, although they will be unusable.
 
682
    """
 
683
 
 
684
    # Get required fields
 
685
    login = fields.getfirst('login')
 
686
    groupid = fields.getfirst('groupid')
 
687
    if login is None or groupid is None:
 
688
        raise BadRequest("Required: login, groupid")
 
689
 
 
690
    group = req.store.get(ivle.database.ProjectGroup, int(groupid))
 
691
    user = ivle.database.User.get_by_login(req.store, login)
 
692
 
 
693
    # Remove membership from the database
 
694
    # We can't keep a transaction open until the end here, as usrmgt-server
 
695
    # needs to see the changes!
 
696
    group.members.remove(user)
 
697
    req.store.commit()
 
698
 
 
699
    # Rebuild the svn config file
 
700
    # Contact the usrmgt server
 
701
    msg = {'rebuild_svn_group_config': {}}
 
702
    try:
 
703
        usrmgt = chat.chat(req.config['usrmgt']['host'],
 
704
                           req.config['usrmgt']['port'],
 
705
                           msg,
 
706
                           req.config['usrmgt']['magic'],
 
707
                          )
653
708
    except cjson.DecodeError, e:
654
709
        raise Exception("Could not understand usrmgt server response: %s" +
655
710
                        e.message)
672
727
    "get_group_membership": handle_get_group_membership,
673
728
    "create_group": handle_create_group,
674
729
    "assign_group": handle_assign_group,
 
730
    "unassign_group": handle_unassign_group,
675
731
}