From 6985120c650d8a63f12f060e4eed1259554462e0 Mon Sep 17 00:00:00 2001 From: Alexandre Bourret Date: Tue, 28 May 2024 14:44:57 +0200 Subject: [PATCH 1/7] [sc-169288] fix path creation containing ro elements --- .../fs-provider.py | 2 +- python-lib/sharepoint_client.py | 16 ++++++++++++++-- python-lib/sharepoint_items.py | 9 --------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/python-fs-providers/sharepoint-online_shared-documents/fs-provider.py b/python-fs-providers/sharepoint-online_shared-documents/fs-provider.py index 1dfb134..4b25278 100644 --- a/python-fs-providers/sharepoint-online_shared-documents/fs-provider.py +++ b/python-fs-providers/sharepoint-online_shared-documents/fs-provider.py @@ -229,7 +229,7 @@ def write(self, path, stream): shutil.copyfileobj(stream, bio) bio.seek(0) data = bio.read() - create_path(self.client, full_path) + self.client.create_path(full_path) response = self.client.write_file_content(full_path, data) logger.info("write:response={}".format(response)) self.client.check_in_file(full_path) diff --git a/python-lib/sharepoint_client.py b/python-lib/sharepoint_client.py index 3c92c50..2302969 100644 --- a/python-lib/sharepoint_client.py +++ b/python-lib/sharepoint_client.py @@ -17,7 +17,7 @@ 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 + is_empty_path, merge_paths, get_lnt_path ) from safe_logger import SafeLogger @@ -262,9 +262,21 @@ def create_folder(self, full_path): response = self.session.post( self.get_add_folder_url(full_path) ) - self.assert_response_ok(response, calling_method="create_folder") return response + def create_path(self, file_full_path): + full_path, filename = os.path.split(file_full_path) + tokens = full_path.split("/") + path = "" + previous_status = None + for token in tokens: + previous_path = path + path = get_lnt_path(path + "/" + token) + response = self.create_folder(path) + status_code = response.status_code + if previous_status == 403 and status_code == 404: + logger.error("Could not create folder for '{}'. Check your write permission for the folder {}.".format(path, previous_path)) + def move_file(self, full_from_path, full_to_path): get_move_url = self.get_move_url( full_from_path, diff --git a/python-lib/sharepoint_items.py b/python-lib/sharepoint_items.py index 0170655..9b32c34 100644 --- a/python-lib/sharepoint_items.py +++ b/python-lib/sharepoint_items.py @@ -62,12 +62,3 @@ def assert_path_is_not_root(path): path = get_rel_path(path) if path == "" or path == "/": raise ValueError("Cannot delete root path") - - -def create_path(client, file_full_path): - full_path, filename = os.path.split(file_full_path) - tokens = full_path.split("/") - path = "" - for token in tokens: - path = get_lnt_path(path + "/" + token) - client.create_folder(path) From 5edcb43f0348ce61aad1b0b8dae8e6ceb255f348 Mon Sep 17 00:00:00 2001 From: Alexandre Bourret Date: Tue, 28 May 2024 14:45:16 +0200 Subject: [PATCH 2/7] Adding integration test --- tests/python/integration/test_scenario.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/python/integration/test_scenario.py b/tests/python/integration/test_scenario.py index 011af71..4c7eb0d 100644 --- a/tests/python/integration/test_scenario.py +++ b/tests/python/integration/test_scenario.py @@ -37,3 +37,7 @@ def test_run_sharepoint_online_file_overwrite(user_dss_clients): def test_run_sharepoint_online_append_to_list_recipe(user_dss_clients): dss_scenario.run(user_dss_clients, project_key=TEST_PROJECT_KEY, scenario_id="APPENDTOLISTRECIPE") + + +def test_run_sharepoint_online_write_file_in_path_w_ro_parent(user_dss_clients): + dss_scenario.run(user_dss_clients, project_key=TEST_PROJECT_KEY, scenario_id="SC169288_WRITE_FILE_WITH_RO_PARENT_FOLDER") From 1f48da3d1286d1847025e49a140f5a8ed728e9a6 Mon Sep 17 00:00:00 2001 From: Alexandre Bourret Date: Tue, 28 May 2024 14:45:37 +0200 Subject: [PATCH 3/7] Version 1.1.2-beta.1 --- plugin.json | 2 +- python-lib/dss_constants.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin.json b/plugin.json index bb07df6..6fa43d2 100644 --- a/plugin.json +++ b/plugin.json @@ -1,6 +1,6 @@ { "id": "sharepoint-online", - "version": "1.1.1", + "version": "1.1.2", "meta": { "label": "SharePoint Online", "description": "Read and write data from/to your SharePoint Online account", diff --git a/python-lib/dss_constants.py b/python-lib/dss_constants.py index 919870b..e69bd48 100644 --- a/python-lib/dss_constants.py +++ b/python-lib/dss_constants.py @@ -28,7 +28,7 @@ class DSSConstants(object): "sharepoint_oauth": "The access token is missing" } PATH = 'path' - PLUGIN_VERSION = "1.1.1" + PLUGIN_VERSION = "1.1.2-beta.1" SECRET_PARAMETERS_KEYS = ["Authorization", "sharepoint_username", "sharepoint_password", "client_secret"] SITE_APP_DETAILS = { "sharepoint_tenant": "The tenant name is missing", From 252a6442bb36cfb125c09c2a5f98c7669fb59547 Mon Sep 17 00:00:00 2001 From: Alexandre Bourret Date: Tue, 28 May 2024 14:45:49 +0200 Subject: [PATCH 4/7] Updating changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d036f26..27bebf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [Version 1.1.2](https://github.com/dataiku/dss-plugin-sharepoint-online/releases/tag/v1.1.2) - Bugfix release - 2024-05-28 + +- Fix path creation inside read-only parent directory + ## [Version 1.1.1](https://github.com/dataiku/dss-plugin-sharepoint-online/releases/tag/v1.1.1) - Bugfix release - 2024-01-24 - Fix file creation when using username / password authentication From 2567bea0cb12487e5014383f3b55530684a9d430 Mon Sep 17 00:00:00 2001 From: Alexandre Bourret Date: Tue, 28 May 2024 15:02:22 +0200 Subject: [PATCH 5/7] removing old import --- .../sharepoint-online_shared-documents/fs-provider.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python-fs-providers/sharepoint-online_shared-documents/fs-provider.py b/python-fs-providers/sharepoint-online_shared-documents/fs-provider.py index 4b25278..8174609 100644 --- a/python-fs-providers/sharepoint-online_shared-documents/fs-provider.py +++ b/python-fs-providers/sharepoint-online_shared-documents/fs-provider.py @@ -6,7 +6,6 @@ from sharepoint_client import SharePointClient from dss_constants import DSSConstants from sharepoint_items import loop_sharepoint_items, has_sharepoint_items, extract_item_from, get_size, get_last_modified, get_name, assert_path_is_not_root -from sharepoint_items import create_path from common import get_rel_path, get_lnt_path from safe_logger import SafeLogger From 1128562f474b1829a074c59069bfdf9cf04c46ab Mon Sep 17 00:00:00 2001 From: Alexandre Bourret Date: Tue, 28 May 2024 16:51:11 +0200 Subject: [PATCH 6/7] removing beta marker --- python-lib/dss_constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python-lib/dss_constants.py b/python-lib/dss_constants.py index e69bd48..1be729e 100644 --- a/python-lib/dss_constants.py +++ b/python-lib/dss_constants.py @@ -28,7 +28,7 @@ class DSSConstants(object): "sharepoint_oauth": "The access token is missing" } PATH = 'path' - PLUGIN_VERSION = "1.1.2-beta.1" + PLUGIN_VERSION = "1.1.2" SECRET_PARAMETERS_KEYS = ["Authorization", "sharepoint_username", "sharepoint_password", "client_secret"] SITE_APP_DETAILS = { "sharepoint_tenant": "The tenant name is missing", From d26005cc098fcb3f7abe722aa5217a457b91e06d Mon Sep 17 00:00:00 2001 From: Alexandre Bourret Date: Fri, 31 May 2024 15:41:01 +0200 Subject: [PATCH 7/7] Adding docstring to create_path --- python-lib/sharepoint_client.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/python-lib/sharepoint_client.py b/python-lib/sharepoint_client.py index 2302969..c107a93 100644 --- a/python-lib/sharepoint_client.py +++ b/python-lib/sharepoint_client.py @@ -265,6 +265,12 @@ def create_folder(self, full_path): return response def create_path(self, file_full_path): + """ + Ensure the path of folders that will contain the file specified in file_full_path exists. + I.e. create all missing folders along the path. + Does not create the last element in the end of the path as that is the file we will add later + (unless it ends in / in which case a folder will be created for that also). + """ full_path, filename = os.path.split(file_full_path) tokens = full_path.split("/") path = ""