Commit fe4816ad authored by Patrick Kimber's avatar Patrick Kimber

Workflow mapping for a group, must be a 'string'

parent a200540e
Pipeline #7456937 passed with stage
in 1 minute and 13 seconds
......@@ -188,7 +188,7 @@ def test_get_workflow_field_mapping_group():
)
assert [
{'name': 'userPk', 'value': 32},
{'name': 'musicGroupPk', 'value': 33},
{'name': 'musicGroupPk', 'value': '33'},
] == result
......
......@@ -32,6 +32,7 @@ HIDDEN_VARIABLE_NAMES = [
# e.g. for ``managerUserPk`` the ``manager`` is the primary key of a ``User``.
#
RESERVED_VARIABLE_NAMES = [
'documentTitle',
'editDocument',
'editMetadata',
'objectPk',
......@@ -217,14 +218,14 @@ class Mapping(TimedCreateModifyDeleteModel):
result = None
if self.is_valid():
if self.mapping_type == self.GROUP:
result = self.group
result = str(self.group.pk)
elif self.mapping_type == self.USER:
result = self.user
result = self.user.pk
else:
raise WorkflowError(
"Mapping '{}' has not been set-up".format(self.pk)
)
return result.pk
return result
reversion.register(Mapping)
......@@ -313,22 +314,27 @@ class ProcessDefinition(models.Model):
def parse_xml(self, xml):
"""Extract form variables from the workflow XML file.
Used for mapping a workflow to the users and groups on the user database.
Used for mapping a workflow to the users and groups on the user
database.
- We exclude date variables because there is no mapping to do.
- We exclude string variables (for now).
- We exclude reserved variables.
- We exclude fields which are set to require a comment.
"""
result = {}
exclude_data_types = ['date', 'enum', 'string']
exclude_data_types = ['date', 'enum']
root = ET.fromstring(xml.strip())
for x in root.findall('.//{http://activiti.org/bpmn}formProperty'):
name = x.attrib['id']
data_type = x.attrib['type']
exclude = data_type in exclude_data_types
if not exclude:
exclude = name in HIDDEN_VARIABLE_NAMES
if not exclude:
exclude = name in RESERVED_VARIABLE_NAMES
if not exclude:
exclude = name.endswith('Comment')
if exclude:
pass
else:
......@@ -645,7 +651,7 @@ class ScheduledWorkflowUser(TimedCreateModifyDeleteModel):
return self.deleted_process
def set_deleted_process(self, user):
if self.is_deleted:
if self.is_deleted_process:
raise WorkflowError(
"Cannot delete '{}', pk '{}'. It is already "
"deleted".format(self.__class__.__name__, self.pk)
......
......@@ -94,7 +94,8 @@ def test_map_url_user():
def test_map_value_group():
group = GroupFactory(pk=43)
mapping = MappingFactory(mapping_type=Mapping.GROUP, group=group)
assert 43 == mapping.map_value()
assert '43' == mapping.map_value()
assert isinstance(mapping.map_value(), str) is True
@pytest.mark.django_db
......@@ -128,6 +129,7 @@ def test_map_value_user():
user=UserFactory(pk=44),
)
assert 44 == mapping.map_value()
assert isinstance(mapping.map_value(), int) is True
@pytest.mark.django_db
def test_str():
......
......@@ -154,6 +154,7 @@ def test_parse_xml():
<activiti:formProperty id="auditDescription" name="Audit Description" type="string" expression="Time off requested" required="true"></activiti:formProperty>
<activiti:formProperty id="checkTaskPk" type="long" required="true"></activiti:formProperty>
<activiti:formProperty id="checkTaskText" type="string" required="true"></activiti:formProperty>
<activiti:formProperty id="documentTitle" type="string" required="true"></activiti:formProperty>
<activiti:formProperty id="editMetadata" type="boolean" expression="True"></activiti:formProperty>
<activiti:formProperty id="fromDate" type="date" datePattern="MM-dd-yyyy" required="true"></activiti:formProperty>
<modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler">false</modeler:initiator-can-complete>
......@@ -174,6 +175,7 @@ def test_parse_xml():
process_definition = ProcessDefinitionFactory()
assert {
'checkTaskPk': 'long',
'checkTaskText': 'string',
'userGroupPk': 'long',
'userManagerPk': 'long',
} == process_definition.parse_xml(xml)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment