From cd0acd9706a2200c05c7cb9749a0780ff46fd225 Mon Sep 17 00:00:00 2001 From: jasquat Date: Mon, 9 Jan 2023 17:18:54 -0500 Subject: [PATCH] attempting to use correct ids vs paths for windows w/ burnettk --- .../services/process_model_service.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_model_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_model_service.py index 8fa25bc0..d5eb97a5 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_model_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_model_service.py @@ -39,6 +39,11 @@ class ProcessModelService(FileSystemService): GROUP_SCHEMA = ProcessGroupSchema() PROCESS_MODEL_SCHEMA = ProcessModelInfoSchema() + @classmethod + def path_to_id(cls, path: str) -> str: + """Replace the os path separator for the standard id separator.""" + return path.replace(os.sep, '/') + @classmethod def is_group(cls, path: str) -> bool: """Is_group.""" @@ -228,7 +233,8 @@ class ProcessModelService(FileSystemService): user = UserService.current_user() new_process_model_list = [] for process_model in process_models: - uri = f"/v1.0/process-instances/{process_model.id.replace('/', ':')}" + modified_process_model_id = ProcessModelInfo.modify_process_identifier_for_path_param(process_model.id) + uri = f"/v1.0/process-instances/{modified_process_model_id}" has_permission = AuthorizationService.user_has_permission( user=user, permission="create", target_uri=uri ) @@ -410,7 +416,7 @@ class ProcessModelService(FileSystemService): data = json.load(cat_json) # we don't store `id` in the json files, so we add it back in here relative_path = os.path.relpath(dir_path, FileSystemService.root_path()) - data["id"] = relative_path + data["id"] = cls.path_to_id(relative_path) process_group = ProcessGroup(**data) if process_group is None: raise ApiError( @@ -421,7 +427,7 @@ class ProcessModelService(FileSystemService): ), ) else: - process_group_id = dir_path.replace(FileSystemService.root_path(), "") + process_group_id = cls.path_to_id(dir_path.replace(FileSystemService.root_path(), "")) process_group = ProcessGroup( id="", display_name=process_group_id, @@ -474,11 +480,7 @@ class ProcessModelService(FileSystemService): data.pop("process_group_id") # we don't save `id` in the json file, so we add it back in here. relative_path = os.path.relpath(path, FileSystemService.root_path()) - - # even on windows, use forward slashes for ids - relative_path = relative_path.replace("\\", "/") - - data["id"] = relative_path + data["id"] = cls.path_to_id(relative_path) process_model_info = ProcessModelInfo(**data) if process_model_info is None: raise ApiError(