Exemple #1
0
def get_group(group_name):
    """Get the list of users belonging to a group"""
    gdal = GroupDAL(app.config['DB'])
    users = gdal.get(group_name)
    if users is None:
        return 'Not Found', status.HTTP_404_NOT_FOUND
    else:
        return json.dumps(list(users))
Exemple #2
0
def update_group(group_name):
    """Udate a group"""
    try:
        group = json.loads(request.data)
    except:
        return 'Bad Request', status.HTTP_400_BAD_REQUEST

    gdal = GroupDAL(app.config['DB'])
    try:
        gdal.schema(group)
    except MultipleInvalid:
        return 'Bad Request', status.HTTP_400_BAD_REQUEST

    if gdal.get(group_name) is not None:
        gdal.update(group_name, group)
        return json.dumps(group)
    else:
        return 'Not Found', status.HTTP_404_NOT_FOUND
Exemple #3
0
def create_group():
    """Create a new group"""
    try:
        group = json.loads(request.data)
    except:
        return 'Bad Request', status.HTTP_400_BAD_REQUEST

    gdal = GroupDAL(app.config['DB'])
    try:
        gdal.schema_group_name(group)
    except MultipleInvalid:
        return 'Bad Request', status.HTTP_400_BAD_REQUEST

    if gdal.get(group['name']) is not None:
        return 'Bad Request', status.HTTP_400_BAD_REQUEST

    gdal.create(group)

    return json.dumps(group)