Update process callers when a file is uploaded (#1571)

This commit is contained in:
jbirddog 2024-05-20 19:52:31 -04:00 committed by GitHub
parent 6c54265793
commit 5840db56cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 103 additions and 1 deletions

View File

@ -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)

View File

@ -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