Skip to content

Commit

Permalink
Merge pull request #58 from dataiku/bug/sc-169288-create-path-with-ro…
Browse files Browse the repository at this point in the history
…-segments

Bug/sc 169288 create path with ro segments
  • Loading branch information
alexbourret authored Jun 3, 2024
2 parents 730760e + d26005c commit bbc6169
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
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.1.1",
"version": "1.1.2",
"meta": {
"label": "SharePoint Online",
"description": "Read and write data from/to your SharePoint Online account",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -229,7 +228,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)
2 changes: 1 addition & 1 deletion python-lib/dss_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
SECRET_PARAMETERS_KEYS = ["Authorization", "sharepoint_username", "sharepoint_password", "client_secret"]
SITE_APP_DETAILS = {
"sharepoint_tenant": "The tenant name is missing",
Expand Down
22 changes: 20 additions & 2 deletions python-lib/sharepoint_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -262,9 +262,27 @@ 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):
"""
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 = ""
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,
Expand Down
9 changes: 0 additions & 9 deletions python-lib/sharepoint_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 4 additions & 0 deletions tests/python/integration/test_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit bbc6169

Please sign in to comment.