diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/api.yml b/spiffworkflow-backend/src/spiffworkflow_backend/api.yml index f7218003..d314c090 100755 --- a/spiffworkflow-backend/src/spiffworkflow_backend/api.yml +++ b/spiffworkflow-backend/src/spiffworkflow_backend/api.yml @@ -399,6 +399,34 @@ paths: schema: $ref: "#/components/schemas/OkTrue" + /process-models/{modified_process_model_identifier}/move: + parameters: + - name: modified_process_model_identifier + in: path + required: true + description: the modified process model id + schema: + type: string + - name: new_location + in: query + required: true + description: the new location for the process model, as a process group id + schema: + type: string + put: + operationId: spiffworkflow_backend.routes.process_api_blueprint.process_model_move + summary: returns the new model + tags: + - Process Models + responses: + "200": + description: Process Model + content: + application/json: + schema: + $ref: "#/components/schemas/ProcessModel" + + /processes: get: operationId: spiffworkflow_backend.routes.process_api_blueprint.process_list 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 65509856..f9920fba 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py @@ -328,6 +328,14 @@ def process_model_show(modified_process_model_identifier: str) -> Any: return process_model_json +def process_model_move( + modified_process_model_identifier: str, new_location: str +) -> flask.wrappers.Response: + original_process_model_id = un_modify_modified_process_model_id(modified_process_model_identifier) + new_process_model = ProcessModelService().process_model_move(original_process_model_id, new_location) + return make_response(jsonify(new_process_model), 201) + + def process_model_list( process_group_identifier: Optional[str] = None, page: int = 1, per_page: int = 100 ) -> flask.wrappers.Response: 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 44c765d7..91f9372c 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_model_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_model_service.py @@ -115,6 +115,17 @@ class ProcessModelService(FileSystemService): path = f"{FileSystemService.root_path()}/{process_model_id}" shutil.rmtree(path) + def process_model_move(self, original_process_model_id: str, new_location: str) -> ProcessModelInfo: + original_model_path = os.path.abspath(os.path.join(FileSystemService.root_path(), original_process_model_id)) + _, model_id = os.path.split(original_model_path) + new_relative_path = f"{new_location}/{model_id}" + new_model_path = os.path.abspath(os.path.join( + FileSystemService.root_path(), new_relative_path + )) + shutil.move(original_model_path, new_model_path) + new_process_model = self.get_process_model(new_relative_path) + return new_process_model + @classmethod def get_process_model_from_relative_path( cls, relative_path: str