~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-08-07 06:46:32 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:989
Groups: Added userservice/assign_group call. This allows a user with the 
CAP_MANAGEGROUPS permission to assign a user into a group. This records the 
assignment in the database and then regenerates a svn-groups.conf file which 
specifies which users can access which repository.

This commit introduces the /groups repository (which means a groups directory 
will have to be created in repositories area and the apache config will have to 
be updated to allow the new dav repositories to work - see the changes to 
ivle-svn.conf/ivle-both.conf and install_proc for exact details). There is also 
a new parameter svn_group_conf in the config file so you need to run `setup.py 
config` too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
556
556
    if req.method != "POST":
557
557
        req.throw_error(req.HTTP_METHOD_NOT_ALLOWED,
558
558
            "Only POST requests are valid methods to create_user.")
559
 
    # Check if this user has CAP_MANAGEPROJECTS
 
559
    # Check if this is allowed to manage groups
560
560
    if not req.user.hasCap(caps.CAP_MANAGEGROUPS):
561
561
        req.throw_error(req.HTTP_FORBIDDEN,
562
562
        "You do not have permission to manage groups.")
634
634
    req.content_type = "text/plain"
635
635
    req.write(response)
636
636
 
637
 
# TODO: write userservice/assign_to_group
638
 
# Required cap: CAP_MANAGEGROUPS
639
 
# Assigns a user to a project group
640
 
# Required: loginid, groupid
 
637
def handle_assign_group(req, fields):
 
638
    """ Required cap: CAP_MANAGEGROUPS
 
639
    Assigns a user to a project group
 
640
    Required:
 
641
        login, groupid
 
642
    """
 
643
    if req.method != "POST":
 
644
        req.throw_error(req.HTTP_METHOD_NOT_ALLOWED,
 
645
            "Only POST requests are valid methods to create_user.")
 
646
    # Check if this user is allowed to manage groups
 
647
    if not req.user.hasCap(caps.CAP_MANAGEGROUPS):
 
648
        req.throw_error(req.HTTP_FORBIDDEN,
 
649
        "You do not have permission to manage groups.")
 
650
    # Get required fields
 
651
    login = fields.getfirst('login')
 
652
    groupid = fields.getfirst('groupid')
 
653
    if login is None or groupid is None:
 
654
        req.throw_error(req.HTTP_BAD_REQUEST,
 
655
            "Required: login, groupid")
 
656
    groupid = int(groupid)
 
657
 
 
658
    # Talk to the DB
 
659
    db = common.db.DB()
 
660
    try:
 
661
        loginid = db.get_user_loginid(login)
 
662
    except common.db.DBException, e:
 
663
        req.throw_error(req.HTTP_BAD_REQUEST, repr(e))
 
664
 
 
665
    # Add assignment to database
 
666
    try:
 
667
        dbquery = db.insert(
 
668
            {
 
669
                'loginid': loginid,
 
670
                'groupid': groupid,
 
671
            },
 
672
            "group_member", # table
 
673
            frozenset(["loginid", "groupid"]), # fields
 
674
        )
 
675
    except pg.ProgrammingError, e:
 
676
        req.throw_error(req.HTTP_FORBIDDEN, repr(e))
 
677
 
 
678
    # Rebuild the svn config file
 
679
    # Contact the usrmgt server
 
680
    msg = {'rebuild_svn_group_config': {}}
 
681
    try:
 
682
        usrmgt = chat.chat(usrmgt_host, usrmgt_port, msg, usrmgt_magic)
 
683
    except cjson.DecodeError, e:
 
684
        req.throw_error(req.HTTP_INTERNAL_SERVER_ERROR,
 
685
            "Could not understand usrmgt server response: %s"%e.message)
 
686
 
 
687
    if 'response' not in usrmgt or usrmgt['response']=='failure':
 
688
        req.throw_error(req.HTTP_INTERNAL_SERVER_ERROR,
 
689
            "Failure creating repository: %s"%str(usrmgt))
 
690
 
 
691
 
 
692
    return(cjson.encode({'response': 'okay'}))
641
693
 
642
694
# Map action names (from the path)
643
695
# to actual function objects
650
702
    "create_project_set": handle_create_project_set,
651
703
    "create_project": handle_create_project,
652
704
    "create_group": handle_create_group,
 
705
    "assign_group": handle_assign_group,
653
706
}