Ejemplo n.º 1
0
def delete(group_id):
    group = db_session.query(Group).get(group_id)  # type: Group
    if not group:
        abort(422, "Unknown group")

    db_session.delete(group)
    db_session.commit()
    return "OK"
Ejemplo n.º 2
0
def rotate_invite_code(group_id):
    group = db_session.query(Group).get(group_id)  # type: Group
    if not group:
        abort(422, "Unknown group")

    group.invite_code = str(uuid.uuid4())
    db_session.add(group)
    db_session.commit()

    return jsonify(group.as_json())
Ejemplo n.º 3
0
def create():
    admin_id = request.form["admin_id"]
    admin = db_session.query(User).get(admin_id)

    if not admin:
        abort(422, "Unknown admin_id")

    title = request.form["title"]

    group = Group(admin, title)
    db_session.add(group)
    db_session.commit()

    return jsonify(group.as_json())
Ejemplo n.º 4
0
def join(group_id):
    group = db_session.query(Group).get(group_id)  # type: Group
    if not group:
        abort(422, "Unknown group")

    user = db_session.query(User).get(request.form["user_id"])  # type: User
    if not user:
        abort(422, "Unknown user")

    user.groups.append(group)
    db_session.add(user)
    db_session.commit()

    return "OK"
Ejemplo n.º 5
0
def get_user_by_tg_id():
    user = None

    if "id" in request.args:
        tg_id = request.args["id"]
        user = db_session.query(User).filter_by(tg_id=tg_id).first()
        if user is None:
            user = User()
            user.tg_id = tg_id
    elif "username" in request.args:
        tg_username = request.args["username"]
        user = db_session.query(User).filter_by(tg_username=tg_username).first()

    if user is None:
        abort(404, "Cannot find specified user")

    if "allow_update" in request.args and request.args["allow_update"].lower() == "true":
        if "username" in request.args:
            user.tg_username = request.args["username"]

    db_session.add(user)
    db_session.commit()

    return jsonify(user.as_json())