Пример #1
0
def create_group(name):
    group = api.find_group(name)

    if group is not None:
        return Response(response='Group already exists.',
                        status=404,
                        mimetype="application/json")
    else:
        group = api.create_group(name)
        return jsonify(group=group._asdict())
Пример #2
0
def get_group(name):
    group = api.find_group(name)

    if group is None:
        return Response(response='Group not found.',
                        status=404,
                        mimetype="application/json")

    if not group.users.all():
        return Response(response='Group has no associated users.',
                        status=404,
                        mimetype="application/json")

    return jsonify(group=group._asdict(),
                   users=[row._asdict() for row in group.users])
Пример #3
0
def delete_group(name):
    group = api.find_group(name)

    if group is None:
        return Response(response='Group not found.',
                        status=404,
                        mimetype="application/json")

    if not group.users.all():
        return Response(response='Group has no associated users.',
                        status=404,
                        mimetype="application/json")

    group = api.empty_users_in_group(group)
    return Response(response='All users removed from "%s".' % group.name,
                    status=200,
                    mimetype="application/json")
Пример #4
0
def update_group(name):
    group = api.find_group(name)

    if group is None:
        return Response(response='Group not found.',
                        status=404,
                        mimetype="application/json")

    params = request.get_json()
    users = params.get('users')
    if users:
        group = api.add_users_to_group(group, users)
        return jsonify(group=group._asdict(),
                       users=[row._asdict() for row in group.users])
    else:
        return Response(response='No users provided.',
                        status=404,
                        mimetype="application/json")