do not allow deleting primary bpmn file and do not allow instantiating models without a primary bpmn file w/ burnettk

This commit is contained in:
jasquat 2023-01-24 15:15:48 -05:00
parent c2a4d8480b
commit d86c083dfe
6 changed files with 69 additions and 4 deletions

View File

@ -10,6 +10,11 @@ rst-directives = deprecated
per-file-ignores = per-file-ignores =
# More specific globs seem to overwrite the more generic ones so we have # More specific globs seem to overwrite the more generic ones so we have
# to split them out by directory # to split them out by directory
# So if you have a rule like:
# tests/*: D102,D103
# and a rule like:
# tests/test_hey.py: D102
# THEN, test_hey.py will NOT be excluding D103
# asserts are ok in tests # asserts are ok in tests
spiffworkflow-backend/tests/*:S101,D102,D103,D101 spiffworkflow-backend/tests/*:S101,D102,D103,D101
@ -37,4 +42,4 @@ per-file-ignores =
# TODO: fix the S issues: # TODO: fix the S issues:
# S607 Starting a process with a partial executable path # S607 Starting a process with a partial executable path
# S605 Starting a process with a shell: Seems safe, but may be changed in the future, consider rewriting without shell # S605 Starting a process with a shell: Seems safe, but may be changed in the future, consider rewriting without shell
spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py:S607,S101,D103,S605 spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py:S607,S101,S605,D102,D103,D101

View File

@ -10,6 +10,11 @@ rst-directives = deprecated
per-file-ignores = per-file-ignores =
# More specific globs seem to overwrite the more generic ones so we have # More specific globs seem to overwrite the more generic ones so we have
# to split them out by directory # to split them out by directory
# So if you have a rule like:
# tests/*: D102,D103
# and a rule like:
# tests/test_hey.py: D102
# THEN, test_hey.py will NOT be excluding D103
# asserts are ok in tests # asserts are ok in tests
tests/*:S101,D102,D103 tests/*:S101,D102,D103
@ -34,4 +39,4 @@ per-file-ignores =
# and ignore long comment line # and ignore long comment line
src/spiffworkflow_backend/services/logging_service.py:N802,B950 src/spiffworkflow_backend/services/logging_service.py:N802,B950
tests/spiffworkflow_backend/integration/test_process_api.py:S607,S101,D103,S605 tests/spiffworkflow_backend/integration/test_process_api.py:S607,S101,S605,D102,D103,D101

View File

@ -72,6 +72,18 @@ def process_instance_create(
process_model_identifier = _un_modify_modified_process_model_id( process_model_identifier = _un_modify_modified_process_model_id(
modified_process_model_identifier modified_process_model_identifier
) )
process_model = _get_process_model(process_model_identifier)
if process_model.primary_file_name is None:
raise ApiError(
error_code="process_model_missing_primary_bpmn_file",
message=(
f"Process Model '{process_model_identifier}' does not have a primary"
" bpmn file. One must be set in order to instantiate this model."
),
status_code=400,
)
process_instance = ( process_instance = (
ProcessInstanceService.create_process_instance_from_process_model_identifier( ProcessInstanceService.create_process_instance_from_process_model_identifier(
process_model_identifier, g.user process_model_identifier, g.user

View File

@ -277,6 +277,17 @@ def process_model_file_delete(
"""Process_model_file_delete.""" """Process_model_file_delete."""
process_model_identifier = modified_process_model_identifier.replace(":", "/") process_model_identifier = modified_process_model_identifier.replace(":", "/")
process_model = _get_process_model(process_model_identifier) process_model = _get_process_model(process_model_identifier)
if process_model.primary_file_name == file_name:
raise ApiError(
error_code="process_model_file_cannot_be_deleted",
message=(
f"'{file_name}' is the primary bpmn file for"
f" '{process_model_identifier}' and cannot be deleted. Please set"
" another file as the primary before attempting to delete this one."
),
status_code=400,
)
try: try:
SpecFileService.delete_file(process_model, file_name) SpecFileService.delete_file(process_model, file_name)
except FileNotFoundError as exception: except FileNotFoundError as exception:

View File

@ -922,6 +922,28 @@ class TestProcessApi(BaseTest):
assert response.json is not None assert response.json is not None
assert response.json["error_code"] == "process_model_file_cannot_be_found" assert response.json["error_code"] == "process_model_file_cannot_be_found"
def test_process_model_file_delete_when_primary_file(
self,
app: Flask,
client: FlaskClient,
with_db_and_bpmn_file_cleanup: None,
with_super_admin_user: UserModel,
) -> None:
process_model_identifier = self.create_group_and_model_with_bpmn(
client, with_super_admin_user
)
modified_process_model_identifier = process_model_identifier.replace("/", ":")
response = client.delete(
f"/v1.0/process-models/{modified_process_model_identifier}/files/random_fact.bpmn",
follow_redirects=True,
headers=self.logged_in_headers(with_super_admin_user),
)
assert response.status_code == 400
assert response.json is not None
assert response.json["error_code"] == "process_model_file_cannot_be_deleted"
def test_process_model_file_delete( def test_process_model_file_delete(
self, self,
app: Flask, app: Flask,
@ -935,8 +957,16 @@ class TestProcessApi(BaseTest):
) )
modified_process_model_identifier = process_model_identifier.replace("/", ":") modified_process_model_identifier = process_model_identifier.replace("/", ":")
self.create_spec_file(
client,
process_model_id=process_model_identifier,
file_name="second_file.json",
file_data=b"<h1>HEY</h1>",
user=with_super_admin_user,
)
response = client.delete( response = client.delete(
f"/v1.0/process-models/{modified_process_model_identifier}/files/random_fact.bpmn", f"/v1.0/process-models/{modified_process_model_identifier}/files/second_file.json",
follow_redirects=True, follow_redirects=True,
headers=self.logged_in_headers(with_super_admin_user), headers=self.logged_in_headers(with_super_admin_user),
) )
@ -946,7 +976,7 @@ class TestProcessApi(BaseTest):
assert response.json["ok"] assert response.json["ok"]
response = client.get( response = client.get(
f"/v1.0/process-models/{modified_process_model_identifier}/files/random_fact.svg", f"/v1.0/process-models/{modified_process_model_identifier}/files/second_file.json",
headers=self.logged_in_headers(with_super_admin_user), headers=self.logged_in_headers(with_super_admin_user),
) )
assert response.status_code == 404 assert response.status_code == 404

View File

@ -116,9 +116,11 @@ export default function ProcessInstanceRun({
}; };
const processInstanceCreateAndRun = () => { const processInstanceCreateAndRun = () => {
setErrorObject(null);
HttpService.makeCallToBackend({ HttpService.makeCallToBackend({
path: processInstanceCreatePath, path: processInstanceCreatePath,
successCallback: processModelRun, successCallback: processModelRun,
failureCallback: setErrorObject,
httpMethod: 'POST', httpMethod: 'POST',
}); });
}; };