From 10d2fc3a4de584d3677c2ac4e40684bb5701a6b6 Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Wed, 9 Nov 2022 15:45:12 -0500 Subject: [PATCH] Fixes for adding nested groups. We pass modified ids to the api, and need to clean them up before calling services. --- .../src/spiffworkflow_backend/api.yml | 4 ++-- .../spiffworkflow_backend/models/process_group.py | 3 +++ .../routes/process_api_blueprint.py | 14 ++++++++++---- .../src/spiffworkflow_backend/routes/user.py | 2 +- .../services/process_model_service.py | 9 ++++++++- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/api.yml b/spiffworkflow-backend/src/spiffworkflow_backend/api.yml index 7f2fbc91..2bfa117e 100755 --- a/spiffworkflow-backend/src/spiffworkflow_backend/api.yml +++ b/spiffworkflow-backend/src/spiffworkflow_backend/api.yml @@ -185,9 +185,9 @@ paths: schema: $ref: "#/components/schemas/ProcessModelCategory" - /process-groups/{process_group_id}: + /process-groups/{modified_process_group_id}: parameters: - - name: process_group_id + - name: modified_process_group_id in: path required: true description: The unique id of an existing process group. diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/models/process_group.py b/spiffworkflow-backend/src/spiffworkflow_backend/models/process_group.py index 381f8f63..9efc8cf5 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/models/process_group.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/models/process_group.py @@ -27,6 +27,9 @@ class ProcessGroup: process_models: list[ProcessModelInfo] = field( default_factory=list[ProcessModelInfo] ) + process_groups: list[ProcessGroup] = field( + default_factory=list['ProcessGroup'] + ) def __post_init__(self) -> None: """__post_init__.""" diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py index 1081494b..68cabd8e 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py @@ -153,13 +153,14 @@ def process_group_add(body: dict) -> flask.wrappers.Response: return make_response(jsonify(process_group), 201) -def process_group_delete(process_group_id: str) -> flask.wrappers.Response: +def process_group_delete(modified_process_group_id: str) -> flask.wrappers.Response: """Process_group_delete.""" + process_group_id = un_modify_modified_process_model_id(modified_process_group_id) ProcessModelService().process_group_delete(process_group_id) return Response(json.dumps({"ok": True}), status=200, mimetype="application/json") -def process_group_update(process_group_id: str, body: dict) -> flask.wrappers.Response: +def process_group_update(modified_process_group_id: str, body: dict) -> flask.wrappers.Response: """Process Group Update.""" body_include_list = ["display_name", "description"] body_filtered = { @@ -168,6 +169,7 @@ def process_group_update(process_group_id: str, body: dict) -> flask.wrappers.Re if include_item in body } + process_group_id = un_modify_modified_process_model_id(modified_process_group_id) process_group = ProcessGroup(id=process_group_id, **body_filtered) ProcessModelService().update_process_group(process_group) return make_response(jsonify(process_group), 200) @@ -196,9 +198,10 @@ def process_groups_list(page: int = 1, per_page: int = 100) -> flask.wrappers.Re def process_group_show( - process_group_id: str, + modified_process_group_id: str, ) -> Any: """Process_group_show.""" + process_group_id = un_modify_modified_process_model_id(modified_process_group_id) try: process_group = ProcessModelService().get_process_group(process_group_id) except ProcessEntityNotFoundError as exception: @@ -224,10 +227,13 @@ def process_model_add( status_code=400, ) + modified_process_model_id = process_model_info.id + unmodified_process_model_id = un_modify_modified_process_model_id(modified_process_model_id) + process_model_info.id = unmodified_process_model_id process_group_id, _ = os.path.split(process_model_info.id) process_model_service = ProcessModelService() process_group = process_model_service.get_process_group( - process_group_id + un_modify_modified_process_model_id(process_group_id) ) if process_group is None: raise ApiError( diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/user.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/user.py index 5bf4e48b..4a2f19b1 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/user.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/user.py @@ -125,7 +125,7 @@ def verify_token( # no user_info else: raise ApiError( - error_code="no_user_info", message="Cannot retrieve user info" + error_code="no_user_info", message="Cannot retrieve user info", status_code=401 ) else: 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 b91459e4..aaa8ded6 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_model_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_model_service.py @@ -168,6 +168,7 @@ class ProcessModelService(FileSystemService): def get_process_group(self, process_group_id: str) -> ProcessGroup: """Look for a given process_group, and return it.""" if os.path.exists(FileSystemService.root_path()): + process_group_path = os.path.join(FileSystemService.root_path(), process_group_id) if self.is_group(process_group_path): return self.__scan_process_group(process_group_path) @@ -264,12 +265,17 @@ class ProcessModelService(FileSystemService): json.dump(self.GROUP_SCHEMA.dump(process_group), wf_json, indent=4) with os.scandir(dir_path) as nested_items: process_group.process_models = [] + process_group.process_groups = [] for nested_item in nested_items: if nested_item.is_dir(): # TODO: check whether this is a group or model if self.is_group(nested_item.path): # This is a nested group - ... + process_group.process_groups.append( + self.__scan_process_group( + nested_item.path + ) + ) elif self.is_model(nested_item.path): process_group.process_models.append( self.__scan_spec( @@ -277,6 +283,7 @@ class ProcessModelService(FileSystemService): ) ) process_group.process_models.sort() + # process_group.process_groups.sort() return process_group def __scan_spec(