workflows: don't allow python expression as choice label (#55813)

This commit is contained in:
Frédéric Péters 2021-07-27 10:00:06 +02:00
parent d2496c3973
commit a0ba32d37a
2 changed files with 13 additions and 5 deletions

View File

@ -2732,13 +2732,15 @@ class ComputedExpressionWidget(CompositeWidget):
value = WorkflowStatusItem.get_expression(value)
value_placeholder = kwargs.pop('value_placeholder', None)
allow_python = kwargs.pop('allow_python', True)
CompositeWidget.__init__(self, name, value, **kwargs)
options = [
('text', _('Text'), 'text'),
('template', _('Template'), 'template'),
('python', _('Python Expression'), 'python'),
]
if allow_python:
options.append(('python', _('Python Expression'), 'python'))
self.add(
StringWidget,
@ -2824,7 +2826,7 @@ class ComputedExpressionWidget(CompositeWidget):
return
from wcs.workflows import WorkflowStatusItem
expression = WorkflowStatusItem.get_expression(expression)
expression = WorkflowStatusItem.get_expression(expression, allow_python=False)
if expression['type'] == 'python':
if '{{' in expression['value']:
raise ValidationError(_('invalid usage, Python expression cannot contain {{'))

View File

@ -2168,7 +2168,7 @@ class WorkflowStatusItem(XmlSerialisable):
setattr(self, f, value)
@classmethod
def get_expression(cls, var):
def get_expression(cls, var, allow_python=True):
if not var:
expression_type = 'text'
expression_value = ''
@ -2719,7 +2719,7 @@ class ChoiceWorkflowStatusItem(WorkflowStatusJumpItem):
ignore_form_errors = False
def get_label(self):
expression = self.get_expression(self.label)
expression = self.get_expression(self.label, allow_python=False)
if expression['type'] == 'text':
return expression['value']
return _('computed label')
@ -2781,7 +2781,13 @@ class ChoiceWorkflowStatusItem(WorkflowStatusJumpItem):
def add_parameters_widgets(self, form, parameters, prefix='', formdef=None, **kwargs):
super().add_parameters_widgets(form, parameters, prefix=prefix, formdef=formdef, **kwargs)
if 'label' in parameters:
form.add(ComputedExpressionWidget, '%slabel' % prefix, title=_('Label'), value=self.label)
form.add(
ComputedExpressionWidget,
'%slabel' % prefix,
title=_('Label'),
value=self.label,
allow_python=False,
)
if 'by' in parameters:
form.add(
WidgetList,