Example #1
0
def delete_user(cm_id, caller_id, user_id, group_id):
    """
    Method deletes membership of a user from a specified group. Only group
    leader and user-to-delete may call this.

    @clmview_user
    @param_post{user_id,int} id of the user to delete from group
    @param_post{group_id,int} id of the managed group
    """
    if caller_id != user_id:
        User.is_leader(caller_id, group_id)

    try:
        mem = UserGroup.objects.filter(group_id__exact=group_id).filter(user_id__exact=user_id)[0]
    except:
        raise CLMException('user2group_get')

    for m in Message.objects.filter(user_id__exact=caller_id).filter(code__exact='group_request'):
        log.debug(caller_id, 'message params %s' % m.params)
        if json.loads(m.params).get('group_id', None) == id:
            log.debug(caller_id, 'delete message for group %s' % id)
            m.delete()

    try:
        mem.delete()
    except:
        raise CLMException('group_delete_user')
Example #2
0
def activate_user(cm_id, caller_id, user_id, group_id):
    """
    Method activates @prm{user_id} user in group @prm{group_id}. Activated
    user gains access to IsoImage-s shared by that group.

    @clmview_user
    @param_post{user_id,int} id of the user to activate
    @param_post{group_id,int} id of the group in which user must be activated
    """
    # check that the caller is leader
    User.is_leader(caller_id, group_id)

    try:
        mem = UserGroup.objects.filter(group_id__exact=group_id).filter(user_id__exact=user_id).filter(status__exact=group_states['waiting'])[0]
    except:
        raise CLMException('user2group_get')

    mem.status = group_states['ok']
    for m in Message.objects.filter(user_id__exact=caller_id).filter(code__exact='group_request'):
        if json.loads(m.params).get('group_id', None) == id:
            m.delete()
    try:
        mem.save()
    except:
        raise CLMException('user_activate')
Example #3
0
def delete_user(cm_id, caller_id, user_id, group_id):
    """
    Method deletes membership of a user from a specified group. Only group
    leader and user-to-delete may call this.

    @clmview_user
    @param_post{user_id,int} id of the user to delete from group
    @param_post{group_id,int} id of the managed group
    """
    if caller_id != user_id:
        User.is_leader(caller_id, group_id)

    try:
        mem = UserGroup.objects.filter(group_id__exact=group_id).filter(
            user_id__exact=user_id)[0]
    except:
        raise CLMException('user2group_get')

    for m in Message.objects.filter(user_id__exact=caller_id).filter(
            code__exact='group_request'):
        log.debug(caller_id, 'message params %s' % m.params)
        if json.loads(m.params).get('group_id', None) == id:
            log.debug(caller_id, 'delete message for group %s' % id)
            m.delete()

    try:
        mem.delete()
    except:
        raise CLMException('group_delete_user')
Example #4
0
def activate_user(cm_id, caller_id, user_id, group_id):
    """
    Method activates @prm{user_id} user in group @prm{group_id}. Activated
    user gains access to IsoImage-s shared by that group.

    @clmview_user
    @param_post{user_id,int} id of the user to activate
    @param_post{group_id,int} id of the group in which user must be activated
    """
    # check that the caller is leader
    User.is_leader(caller_id, group_id)

    try:
        mem = UserGroup.objects.filter(group_id__exact=group_id).filter(
            user_id__exact=user_id).filter(
                status__exact=group_states['waiting'])[0]
    except:
        raise CLMException('user2group_get')

    mem.status = group_states['ok']
    for m in Message.objects.filter(user_id__exact=caller_id).filter(
            code__exact='group_request'):
        if json.loads(m.params).get('group_id', None) == id:
            m.delete()
    try:
        mem.save()
    except:
        raise CLMException('user_activate')
Example #5
0
def change_owner(cm_id, caller_id, user_id, group_id):
    """
    Function changes owner of the specified group. Only owner may be the caller,
    otherwise exception is thrown. @prm{user_id} becomes new Group's leader.

    @clmview_user
    @param_post{user_id,int} id of the new owner
    @param_post{group_id,int} id of the managed Group
    """
    # check that the caller is leader
    User.is_leader(caller_id, group_id)

    group = Group.get(group_id)
    new_leader = User.get(user_id)

    group.leader = new_leader

    try:
        group.save()
    except:
        raise CLMException('group_change_owner')
Example #6
0
def change_owner(cm_id, caller_id, user_id, group_id):
    """
    Function changes owner of the specified group. Only owner may be the caller,
    otherwise exception is thrown. @prm{user_id} becomes new Group's leader.

    @clmview_user
    @param_post{user_id,int} id of the new owner
    @param_post{group_id,int} id of the managed Group
    """
    # check that the caller is leader
    User.is_leader(caller_id, group_id)

    group = Group.get(group_id)
    new_leader = User.get(user_id)

    group.leader = new_leader

    try:
        group.save()
    except:
        raise CLMException('group_change_owner')