Exemplo n.º 1
0
def create_invited_user(service_id):
    request_json = request.get_json()
    invited_user, errors = invited_user_schema.load(request_json)
    save_invited_user(invited_user)

    template = dao_get_template_by_id(
        current_app.config['INVITATION_EMAIL_TEMPLATE_ID'])
    service = Service.query.get(current_app.config['NOTIFY_SERVICE_ID'])

    saved_notification = persist_notification(
        template_id=template.id,
        template_version=template.version,
        recipient=invited_user.email_address,
        service=service,
        personalisation={
            'user_name':
            invited_user.from_user.name,
            'service_name':
            invited_user.service.name,
            'url':
            invited_user_url(
                invited_user.id,
                request_json.get('invite_link_host'),
            ),
        },
        notification_type=EMAIL_TYPE,
        api_key_id=None,
        key_type=KEY_TYPE_NORMAL,
        reply_to_text=invited_user.from_user.email_address)

    send_notification_to_queue(saved_notification,
                               False,
                               queue=QueueNames.NOTIFY)

    return jsonify(data=invited_user_schema.dump(invited_user).data), 201
Exemplo n.º 2
0
def update_invited_user(service_id, invited_user_id):
    fetched = get_invited_user(service_id=service_id, invited_user_id=invited_user_id)

    current_data = dict(invited_user_schema.dump(fetched).data.items())
    current_data.update(request.get_json())
    update_dict = invited_user_schema.load(current_data).data
    save_invited_user(update_dict)
    return jsonify(data=invited_user_schema.dump(fetched).data), 200