Handle the multiple single file upload widget case (#195)

This commit is contained in:
jbirddog 2023-03-27 16:03:22 -04:00 committed by GitHub
parent a404a2378d
commit a986678869
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 2 deletions

View File

@ -278,6 +278,9 @@ class ProcessInstanceService:
for list_index, list_value in enumerate(value): for list_index, list_value in enumerate(value):
if isinstance(list_value, str): if isinstance(list_value, str):
yield (identifier, list_value, list_index) yield (identifier, list_value, list_index)
if isinstance(list_value, dict) and len(list_value) == 1:
for v in list_value.values():
yield (identifier, v, list_index)
@classmethod @classmethod
def file_data_models_for_data( def file_data_models_for_data(
@ -308,7 +311,11 @@ class ProcessInstanceService:
if model.list_index is None: if model.list_index is None:
data[model.identifier] = digest_reference data[model.identifier] = digest_reference
else: else:
data[model.identifier][model.list_index] = digest_reference old_value = data[model.identifier][model.list_index]
new_value: Any = digest_reference
if isinstance(old_value, dict) and len(old_value) == 1:
new_value = {k: digest_reference for k in old_value.keys()}
data[model.identifier][model.list_index] = new_value
@classmethod @classmethod
def save_file_data_and_replace_with_digest_references( def save_file_data_and_replace_with_digest_references(

View File

@ -89,7 +89,7 @@ class TestProcessInstanceService(BaseTest):
self._check_sample_file_data_model("uploaded_files", 0, models[0]) self._check_sample_file_data_model("uploaded_files", 0, models[0])
self._check_sample_file_data_model("uploaded_files", 1, models[1]) self._check_sample_file_data_model("uploaded_files", 1, models[1])
def test_can_create_file_data_models_for_fix_of_file_data_and_non_file_data_values( def test_can_create_file_data_models_for_mix_of_file_data_and_non_file_data_values(
self, self,
app: Flask, app: Flask,
with_db_and_bpmn_file_cleanup: None, with_db_and_bpmn_file_cleanup: None,
@ -122,6 +122,8 @@ class TestProcessInstanceService(BaseTest):
) -> None: ) -> None:
data = { data = {
"not_a_file": "just a value", "not_a_file": "just a value",
"also_no_files": ["not a file", "also not a file"],
"still_no_files": [{"key": "value"}],
} }
models = ProcessInstanceService.file_data_models_for_data(data, 111) models = ProcessInstanceService.file_data_models_for_data(data, 111)
@ -189,3 +191,25 @@ class TestProcessInstanceService(BaseTest):
], ],
"not_a_file3": "just a value3", "not_a_file3": "just a value3",
} }
def test_can_create_file_data_models_for_mulitple_single_file_data_values(
self,
app: Flask,
with_db_and_bpmn_file_cleanup: None,
with_super_admin_user: UserModel,
) -> None:
data = {
"File": [
{
"supporting_files": self.SAMPLE_FILE_DATA,
},
{
"supporting_files": self.SAMPLE_FILE_DATA,
},
],
}
models = ProcessInstanceService.file_data_models_for_data(data, 111)
assert len(models) == 2
self._check_sample_file_data_model("File", 0, models[0])
self._check_sample_file_data_model("File", 1, models[1])