Allow updating task data via a dictionary (#1414)

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
jbirddog 2024-04-17 14:20:51 -04:00 committed by GitHub
parent 8ad9e9c8fc
commit 823bdd170b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,23 @@
from typing import Any
from spiffworkflow_backend.models.script_attributes_context import ScriptAttributesContext
from spiffworkflow_backend.scripts.script import Script
class UpdateTaskDataWithDictionary(Script):
@staticmethod
def requires_privileged_permissions() -> bool:
"""We have deemed this function safe to run without elevated permissions."""
return False
def get_description(self) -> str:
return "Updates task data, creating or updating variables named 'key' with 'value' from the given dictionary."
def run(self, script_attributes_context: ScriptAttributesContext, *args: Any, **kwargs: Any) -> Any:
if not args or not isinstance(args[0], dict):
raise ValueError("Expected a dictionary as the first argument.")
updates = args[0]
spiff_task = script_attributes_context.task
if spiff_task:
spiff_task.data.update(updates)