diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_models_controller.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_models_controller.py index 48a15be5d..eebddc6fb 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_models_controller.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_models_controller.py @@ -28,6 +28,7 @@ from spiffworkflow_backend.routes.process_api_blueprint import _commit_and_push_ from spiffworkflow_backend.routes.process_api_blueprint import _find_process_instance_by_id_or_raise from spiffworkflow_backend.routes.process_api_blueprint import _get_process_model from spiffworkflow_backend.routes.process_api_blueprint import _un_modify_modified_process_model_id +from spiffworkflow_backend.services.data_setup_service import DataSetupService from spiffworkflow_backend.services.file_system_service import FileSystemService from spiffworkflow_backend.services.git_service import GitCommandError from spiffworkflow_backend.services.git_service import GitService @@ -565,7 +566,9 @@ def _create_or_update_process_model_file( status_code=400, ) - if file_contents_hash is not None: + is_new_file = file_contents_hash is None + + if not is_new_file: current_file_contents_bytes = SpecFileService.get_data(process_model, request_file.filename) if current_file_contents_bytes and file_contents_hash: current_file_contents_hash = sha256(current_file_contents_bytes).hexdigest() @@ -598,4 +601,7 @@ def _create_or_update_process_model_file( file.file_contents_hash = file_contents_hash _commit_and_push_to_git(f"{message_for_git_commit} {process_model_identifier}/{file.name}") + if is_new_file: + DataSetupService.save_all_process_models() + return make_response(jsonify(file), http_status_to_return) diff --git a/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_callers.py b/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_callers.py index 5c595ea0d..90bd85c8b 100644 --- a/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_callers.py +++ b/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_callers.py @@ -1,3 +1,5 @@ +import os + from flask.app import Flask from flask.testing import FlaskClient from spiffworkflow_backend.models.task import TaskModel # noqa: F401 @@ -125,3 +127,97 @@ class TestProcessCallers(BaseTest): assert response.json is not None assert isinstance(response.json, list) assert len(response.json) == 0 + + def test_references_after_process_file_delete( + self, + app: Flask, + client: FlaskClient, + with_db_and_bpmn_file_cleanup: None, + with_super_admin_user: UserModel, + ) -> None: + self.create_group_and_model_with_bpmn( + client=client, + user=with_super_admin_user, + process_group_id="test_group_two", + process_model_id="call_activity_nested", + bpmn_file_location="call_activity_nested", + ) + + response = client.delete( + "/v1.0/process-models/test_group_two:call_activity_nested/files/call_activity_level_2.bpmn", + headers=self.logged_in_headers(with_super_admin_user), + ) + + assert response.status_code == 200 + + response = client.get( + "/v1.0/processes", + headers=self.logged_in_headers(with_super_admin_user), + ) + + assert response.status_code == 200 + assert response.json is not None + assert isinstance(response.json, list) + assert len(response.json) == 3 + + response = client.get( + "/v1.0/processes/callers/Level2", + headers=self.logged_in_headers(with_super_admin_user), + ) + + assert response.status_code == 200 + assert response.json is not None + assert isinstance(response.json, list) + assert len(response.json) == 0 + + def test_references_after_process_file_delete_and_upload( + self, + app: Flask, + client: FlaskClient, + with_db_and_bpmn_file_cleanup: None, + with_super_admin_user: UserModel, + ) -> None: + process_model = self.create_group_and_model_with_bpmn( + client=client, + user=with_super_admin_user, + process_group_id="test_group_two", + process_model_id="call_activity_nested", + bpmn_file_location="call_activity_nested", + ) + + response = client.delete( + "/v1.0/process-models/test_group_two:call_activity_nested/files/call_activity_level_2.bpmn", + headers=self.logged_in_headers(with_super_admin_user), + ) + + assert response.status_code == 200 + + with open(f"{os.getcwd()}/tests/data/call_activity_nested/call_activity_level_2.bpmn", "rb") as f: + file_data = f.read() + + bpmn_file_name = "call_activity_level_2.bpmn" + bpmn_file_location = "call_activity_level_2" + + response = self.create_spec_file( + client, + process_model_id=process_model.id, + process_model=process_model, + process_model_location=bpmn_file_location, + file_name=bpmn_file_name, + file_data=file_data, + user=with_super_admin_user, + ) + + assert response["process_model_id"] == process_model.id + assert response["name"] == bpmn_file_name + assert bytes(str(response["file_contents"]), "utf-8") == file_data + + response = client.get( + "/v1.0/processes/callers/Level2", + headers=self.logged_in_headers(with_super_admin_user), + ) + + assert response.status_code == 200 + assert response.json is not None + assert isinstance(response.json, list) + assert len(response.json) == 1