Example #1
0
def getsite():
    posted_entities = request.get_json()
    entities = data_access_layer.get_siteurls(posted_entities)

    return Response(
        stream_json(entities),
        mimetype='application/json'
    )
Example #2
0
def list(path):
    if request.method == "GET":
        path = path
        entities = data_access_layer.get_list(path, args=request.args)

    if request.method == "POST":
        entities = request.get_json()

    return Response(stream_json(entities), mimetype='application/json')
Example #3
0
def file(path):

    sharepoint_url = getattr(config, "sharepoint_url", None)
    if not sharepoint_url:
        return "Missing environment variable 'sharepoint_url' to use this url path", 500

    try:
        site, path, file_name, document_lib = determine_url_parts(
            sharepoint_url, path)
    except Exception as e:
        return Response(status=400, response=e)

    if request.method == "GET":
        if file_name:
            logger.info(f"Retrieving file from path '{path}'")
            file_resp = data_access_layer.get_file(path, site, document_lib)
            if file_resp:
                return file_resp
            Response(status=404, response="File not found")
        else:
            logger.info(f"Retrieving metadata for files on path '{path}'")
            path_children = data_access_layer.get_drive_path_nested_children(
                path, site, document_lib)
            return Response(stream_json(path_children),
                            mimetype="application/json")
            # return Response(status=404, response="Path not found.")

    if request.method == "POST":
        if request.files:
            failures = False
            for file in request.files:
                if request.files[file].filename == '':
                    continue
                file_resp = data_access_layer.add_file(request.files[file],
                                                       path, site,
                                                       document_lib)
                if not file_resp.ok:
                    failures = True
                    logger.error(
                        f"Failed to send file. Error: {file_resp.content}")
            if not failures:
                return Response(status=200)
        else:
            file_content = request.get_data()
            file_resp = data_access_layer.add_file(file_content, path, site,
                                                   document_lib)
            if file_resp.ok:
                return Response(status=200)
        return Response(
            status=500,
            response=
            "Failed to upload file to sharepoint. See ms logs for details.")