BusinessTemplate: improve parser for paths
Description of the problem
I recently noticed an inconsistency when exporting a Business Template: some paths which were considered as valid in the template_path_list
were however discarded when inside the template_keep_last_workflow_history_only_path_list
. For instance, let's say a Person object named test_abc
has an ERP5 Login with reference 1
. If the two objects are to be exported inside of the Business Template, one can add the following lines to the template_path_list
:
person_module/test_*
person_module/test_*/**
These lines shall target all objects inside of person_module
whose name begins with test_
, and all the corresponding subobjects. Now if the workflow history is to be exported along with the objects, I expect adding the same two lines to template_keep_workflow_path_list
or template_keep_last_workflow_history_only_path_list
to do the job. Unfortunately, that will lead to history being exported only for test_abc
, not it's subobjects. To export the subobjects, one can use person_module/test_**
.
Current implementation
The current behaviour when exporting is the following: template_path_list
is used to gather objects, making unrestricted traverses as needed. template_keep_workflow_path_list
and template_keep_last_workflow_history_only_path_list
, however, do not use traversal: they are based on the result of processing the template_path_list
, and use a simple matcher to detect if objects' histories should be included or not.
The implementation for traversal and path checking resides in BusinessTemplate.py#L968
while matching paths for workflow history is based on BusinessTemplate.py#L5676
. As one can see, implementer for the latter is quite simple, and indeed too simple.
Rewriting the parser
The MR does not aim at changing anything about the traversal, but rewrites the path checker completely to get a behaviour which looks exactly like the one used for traversing objects, while keeping compatibility with the current implementation. In other words, both person_module/test_**
and:
person_module/test_*
person_module/test_*/**
should now export history for the objects and all subobjects.
I tested my parser with a working instance, and no breaking changes are to be reported; the new behaviour also works as expected. Tests are fine, but Gitlab shows a red cross... You can test the following paths to check implementation:
# Should be True
print(_isInKeepList(['person_module/test_abc/test_*'], 'person_module/test_abc/test_2'))
print(_isInKeepList(['person_module/test_**'], 'person_module/test_abc/test_2'))
print(_isInKeepList(['person_module/test_**'], 'person_module/test_abc'))
print(_isInKeepList(['person_module/test_*'], 'person_module/test_abc'))
print(_isInKeepList(['person_module/test_*/**'], 'person_module/test_abc/2'))
print(_isInKeepList(['person_module/test_*/**'], 'person_module/test_abc/long/path/2'))
# Should be False
print(_isInKeepList(['person_module/test_*'], 'person_module/test_abc/long/path/2'))
print(_isInKeepList(['person_module/test_*/**'], 'person_module/test_abc'))