Exemplo n.º 1
0
def edit_trigger_group(trigger_group_id=None):
    received_token = request.headers.get('Authorization')
    access_token = AccessToken.find(received_token)
    if access_token is None:
        return "Invalid token", 401

    trigger_group = (TriggerGroup(
        chat_id=access_token.chat_id) if trigger_group_id is None else
                     TriggerGroup.query.get(trigger_group_id))
    trigger_group.save()

    if trigger_group is None:
        return "Not found", 404

    if trigger_group.chat_id != access_token.chat_id:
        return "Forbidden", 403

    group_attrs = request.get_json()
    trigger_group.update(
        ignore_case=group_attrs['ignore_case'],
        ignore_repeated_letters=group_attrs['ignore_repeated_letters'])
    update_trigger_group_attrs(trigger_group, group_attrs['answers'],
                               group_attrs['triggers'])

    return jsonify({
        "saved": True,
        "trigger_group_id": trigger_group.trigger_group_id
    })
Exemplo n.º 2
0
def delete_trigger_group(trigger_group_id):
    token = request.headers.get('Authorization')
    access_token = AccessToken.find(token)
    trigger_group = TriggerGroup.query.get(trigger_group_id)

    if access_token is None:
        return "Invalid", 401

    if trigger_group is None:
        return "Not found", 404

    if trigger_group.chat_id != access_token.chat_id:
        return "Forbidden", 403

    delete_answers(trigger_group)
    delete_triggers(trigger_group)
    trigger_group.delete()

    return jsonify({"deleted": True})
Exemplo n.º 3
0
def get_chat_associated_to_token(received_token):
    access_token = AccessToken.find(received_token)
    if access_token is None:
        return "Invalid token", 401

    return jsonify(access_token.chat.to_dict())