示例#1
0
def save_report(payload):
    params = payload.get("HQ Parameters")
    # Find the user associated with the API key and the group they belong to.
    # If that group exists, add the report to the group
    api_key = params.get("api_key", None)
    user = User.query.filter(User.api_key == api_key).first()
    if user is not None:
        cr = CrashReport(**payload)
        if user.group:
            user.group.add_report(cr)

        cr.commit()

        return cr, "Success"
    else:
        return None, "Invalid or missing API Key."