Skip to content

Commit

Permalink
Merge pull request #42 from dataiku/bug/sc-104210-fix-folder-creation…
Browse files Browse the repository at this point in the history
…-w-empty-rootpath

[sc-104210] fix folder creation with empty root path
  • Loading branch information
alexbourret authored Nov 9, 2022
2 parents 1c287bf + 461f6fd commit 90c1f30
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [Version 1.0.13](https://github.com/dataiku/dss-plugin-sharepoint-online/releases/tag/v1.0.13) - Bugfix release - 2022-10-13

- Allow file to be overwritten using export recipe without `clear before export` activated
- Fix folder creation when root path is left empty

## [Version 1.0.12](https://github.com/dataiku/dss-plugin-sharepoint-online/releases/tag/v1.0.12) - Feature and bugfix release - 2022-07-19

- Add site path overwrite for username / password permissions presets
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "sharepoint-online",
"version": "1.0.12",
"version": "1.0.13",
"meta": {
"label": "SharePoint Online",
"description": "Read and write data from/to your SharePoint Online account",
Expand Down
2 changes: 1 addition & 1 deletion python-connectors/sharepoint-online_lists/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SharePointListsConnector(Connector):

def __init__(self, config, plugin_config):
Connector.__init__(self, config, plugin_config)
logger.info('SharePoint Online plugin connector v1.0.12')
logger.info('SharePoint Online plugin connector v1.0.13')
self.sharepoint_list_title = self.config.get("sharepoint_list_title")
self.auth_type = config.get('auth_type')
logger.info('init:sharepoint_list_title={}, auth_type={}'.format(self.sharepoint_list_title, self.auth_type))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, root, config, plugin_config):
root = root[1:]
self.root = root
self.provider_root = "/"
logger.info('SharePoint Online plugin fs v1.0.12')
logger.info('SharePoint Online plugin fs v1.0.13')
logger.info('init:root={}'.format(self.root))

self.client = SharePointClient(config)
Expand Down
17 changes: 17 additions & 0 deletions python-lib/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,23 @@ def decode_retry_after_header(response):
return seconds_before_retry


def is_empty_path(path):
if not path:
return True
if path.strip("/") == "":
return True
return False


def merge_paths(first_path, second_path):
path_1 = first_path or ""
path_2 = second_path or ""
path_1 = path_1.strip("/")
path_2 = path_2.strip("/")
joined_path = "/".join([path_1, path_2])
return joined_path.strip("/")


class ItemsLimit():
def __init__(self, records_limit=-1):
self.has_no_limit = (records_limit == -1)
Expand Down
27 changes: 23 additions & 4 deletions python-lib/sharepoint_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
from robust_session import RobustSession
from sharepoint_constants import SharePointConstants
from dss_constants import DSSConstants
from common import is_email_address, get_value_from_path, parse_url, get_value_from_paths, is_request_performed, ItemsLimit
from common import (
is_email_address, get_value_from_path, parse_url,
get_value_from_paths, is_request_performed, ItemsLimit,
is_empty_path, merge_paths
)
from safe_logger import SafeLogger


Expand Down Expand Up @@ -181,6 +185,10 @@ def get_file_content(self, full_path):

def write_file_content(self, full_path, data):
self.file_size = len(data)

#Preventive file check out, in case it already exists on SP's side
self.check_out_file(full_path)

if self.file_size < SharePointConstants.MAX_FILE_SIZE_CONTINUOUS_UPLOAD:
# below 262MB, the file can be uploaded in one go
self.write_full_file_content(full_path, data)
Expand Down Expand Up @@ -236,6 +244,8 @@ def write_chunked_file_content(self, full_path, data):
return response

def create_folder(self, full_path):
if is_empty_path(full_path) and is_empty_path(self.sharepoint_root):
return
response = self.session.post(
self.get_add_folder_url(full_path)
)
Expand All @@ -257,6 +267,12 @@ def check_in_file(self, full_path):
self.session.post(file_check_in_url)
return

def check_out_file(self, full_path):
logger.info("Checking out {}.".format(full_path))
file_check_out_url = self.get_file_check_out_url(full_path)
self.session.post(file_check_out_url)
return

def recycle_file(self, full_path):
recycle_file_url = self.get_recycle_file_url(full_path)
response = self.session.post(recycle_file_url)
Expand Down Expand Up @@ -661,6 +677,9 @@ def get_recycle_folder_url(self, full_path):
def get_file_check_in_url(self, full_path):
return self.get_file_url(full_path) + "/CheckIn()"

def get_file_check_out_url(self, full_path):
return self.get_file_url(full_path) + "/CheckOut()"

def get_site_path(self, full_path):
return "'/{}/{}{}'".format(
self.escape_path(self.sharepoint_site),
Expand All @@ -669,9 +688,9 @@ def get_site_path(self, full_path):
)

def get_add_folder_url(self, full_path):
return self.get_base_url() + "/Folders/add('{}{}')".format(
self.sharepoint_root,
full_path
path = merge_paths(self.sharepoint_root, full_path)
return self.get_base_url() + "/Folders/add('{}')".format(
path
)

def get_file_add_url(self, full_path, file_name):
Expand Down
7 changes: 7 additions & 0 deletions tests/python/integration/test_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@ def test_run_sharepoint_online_authentication_modes(user_dss_clients):

def test_run_sharepoint_online_site_root_overwrite(user_dss_clients):
dss_scenario.run(user_dss_clients, project_key=TEST_PROJECT_KEY, scenario_id="SiteRootOverwrite")


def test_run_sharepoint_online_write_on_empty_root_path(user_dss_clients):
dss_scenario.run(user_dss_clients, project_key=TEST_PROJECT_KEY, scenario_id="WRITEONEMPTYROOTPATH")

def test_run_sharepoint_online_file_overwrite(user_dss_clients):
dss_scenario.run(user_dss_clients, project_key=TEST_PROJECT_KEY, scenario_id="FILEOVERWRITE")

0 comments on commit 90c1f30

Please sign in to comment.