From 0bb3af1b9d1e1bd8f292fb82b92f6f23ecc87ff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20K=C3=BCrten?= Date: Fri, 4 Apr 2025 10:04:31 +0200 Subject: [PATCH 1/9] Add StartWorkflowAction to ActionUnion and update ActionNames --- csfunctions/actions/__init__.py | 4 +++- csfunctions/actions/base.py | 1 + csfunctions/actions/start_workflow.py | 27 +++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 csfunctions/actions/start_workflow.py diff --git a/csfunctions/actions/__init__.py b/csfunctions/actions/__init__.py index c770c34..66de078 100644 --- a/csfunctions/actions/__init__.py +++ b/csfunctions/actions/__init__.py @@ -5,8 +5,9 @@ from .abort_and_show_error import AbortAndShowErrorAction from .base import ActionNames from .dummy import DummyAction +from .start_workflow import StartWorkflowAction -ActionUnion = Union[AbortAndShowErrorAction, DummyAction] +ActionUnion = Union[AbortAndShowErrorAction, DummyAction, StartWorkflowAction] Action = Annotated[ActionUnion, Field(discriminator="name")] __all__ = [ @@ -15,4 +16,5 @@ "DummyAction", "AbortAndShowErrorAction", "ActionUnion", + "StartWorkflowAction", ] diff --git a/csfunctions/actions/base.py b/csfunctions/actions/base.py index 19fbc9e..9b40784 100644 --- a/csfunctions/actions/base.py +++ b/csfunctions/actions/base.py @@ -6,6 +6,7 @@ class ActionNames(str, Enum): ABORT_AND_SHOW_ERROR = "abort_and_show_error" DUMMY = "dummy" + START_WORKFLOW = "start_workflow" class BaseAction(BaseModel): diff --git a/csfunctions/actions/start_workflow.py b/csfunctions/actions/start_workflow.py new file mode 100644 index 0000000..53f641f --- /dev/null +++ b/csfunctions/actions/start_workflow.py @@ -0,0 +1,27 @@ +from typing import Literal + +from pydantic import BaseModel, Field + +from .base import ActionNames, BaseAction + + +class TaskParameter(BaseModel): + task_id: str = Field(..., description="Identifier for the task this parameter belongs to") + name: str = Field(..., description="Name of the parameter") + value: str = Field(..., description="Value of the parameter") + + +class StartWorkflowAction(BaseAction): + name: Literal[ActionNames.START_WORKFLOW] = ActionNames.START_WORKFLOW + template_id: str = Field(..., description="ID of the workflow template to start") + cdb_project_id: str | None = Field( + default=None, description="ID of the project in which the workflow should be started" + ) + title: str = Field(..., description="Title of the workflow") + attachment_ids: list[str] = Field( + default_factory=list, description="List of cdb_object_ids to attach to the workflow" + ) + global_briefcase_object_ids: list[str] = Field( + default_factory=list, description="List of cdb_object_ids to attach to the global briefcase" + ) + task_parameters: list[TaskParameter] = Field(default_factory=list, description="List of task parameters") From 286d3786cc4fddc4fcd33e80aafd32bcf3e560da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20K=C3=BCrten?= Date: Thu, 10 Apr 2025 13:32:58 +0200 Subject: [PATCH 2/9] Enhance StartWorkflowAction with task configurations and subject handling --- csfunctions/actions/start_workflow.py | 33 +++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/csfunctions/actions/start_workflow.py b/csfunctions/actions/start_workflow.py index 53f641f..fb64c64 100644 --- a/csfunctions/actions/start_workflow.py +++ b/csfunctions/actions/start_workflow.py @@ -1,27 +1,42 @@ -from typing import Literal +from typing import Literal, Optional from pydantic import BaseModel, Field from .base import ActionNames, BaseAction -class TaskParameter(BaseModel): - task_id: str = Field(..., description="Identifier for the task this parameter belongs to") - name: str = Field(..., description="Name of the parameter") - value: str = Field(..., description="Value of the parameter") +class Subject(BaseModel): + subject_id: str = Field(..., description="ID of the subject, eg. a role name or personalnummer") + subject_type: Literal["Person", "PCS Role", "Common Role"] = Field( + ..., description="Type of the subject: Person, PCS Role or Common Role" + ) + + +class TaskConfiguration(BaseModel): + task_id: str = Field(..., description="Identifier for the task") + responsible: Optional[Subject] = Field(default=None, description="Responsible subject for the task") + recipients: list[Subject] = Field( + default_factory=list, + description="List of recipients for the task (only used by information tasks)", + ) class StartWorkflowAction(BaseAction): name: Literal[ActionNames.START_WORKFLOW] = ActionNames.START_WORKFLOW template_id: str = Field(..., description="ID of the workflow template to start") cdb_project_id: str | None = Field( - default=None, description="ID of the project in which the workflow should be started" + default=None, + description="ID of the project in which the workflow should be started", ) title: str = Field(..., description="Title of the workflow") attachment_ids: list[str] = Field( - default_factory=list, description="List of cdb_object_ids to attach to the workflow" + default_factory=list, + description="List of cdb_object_ids to attach to the workflow", ) global_briefcase_object_ids: list[str] = Field( - default_factory=list, description="List of cdb_object_ids to attach to the global briefcase" + default_factory=list, + description="List of cdb_object_ids to attach to the global briefcase", + ) + task_configurations: list[TaskConfiguration] = Field( + default_factory=list, description="List of task configurations" ) - task_parameters: list[TaskParameter] = Field(default_factory=list, description="List of task parameters") From 4a4d6c7143e2975a43f11a2653c9c7ed61271da9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20K=C3=BCrten?= Date: Thu, 10 Apr 2025 13:49:34 +0200 Subject: [PATCH 3/9] add docs --- docs/reference/actions.md | 41 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/docs/reference/actions.md b/docs/reference/actions.md index 685b401..70ab28a 100644 --- a/docs/reference/actions.md +++ b/docs/reference/actions.md @@ -12,13 +12,48 @@ def my_function(metadata, event, service): return AbortAndShowErrorAction(message="Custom error message.") ``` -## AbortAndShowErrorAction +## AbortAndShowErrorAction (abort_and_show_error) `csfunctions.actions.AbortAndShowErrorAction` Aborts the current operation and shows an error message to the user. +**Attributes:** -**AbortAndShowErrorAction.name:** abort_and_show_error +|Attribute|Type|Description| +|-|-|-| +|message|str|Error message that will be shown to the user| -**AbortAndShowErrorAction.message:** Error message that will be shown to the user +## StartWorkflowAction (start_workflow) + +`csfunctions.actions.StartWorkflowAction` + +Creates a new workflow from a template and starts it. + + + +**Attributes:** + +|Attribute|Type|Description| +|-|-|-| +|template_id|str|ID of the workflow template| +|cdb_project_id|str \| None|ID of the project in which the workflow should be started| +|title|str|Title that the new workflow should have| +|attachment_ids|list[str]|List of cdb_object_ids to attach to the workflow| +|global_briefcase_object_ids|list[str]|List of cdb_object_ids to attach to the global briefcase| +|task_configurations|list[[TaskConfiguration](actions.md#TaskConfiguration)]|List of task configurations| + +**TaskConfiguration:** + +|Attribute|Type|Description| +|-|-|-| +|task_id|str|Identifier for the task| +|responsible|[Subject](actions.md#Subject) \| None|Responsible Subject for the task| +|recipients|list[[Subject](actions.md#Subject)]|List of recipients (only used by information tasks)| + +**Subject:** + +|Attribute|Type|Description| +|-|-|-| +|subject_id|str|ID of the subject, e.g. a role name or "personalnummer"| +|subject_type|str|Type of the subject. Can be "Person", "PCS Role" or "Common Role"| From 4d9f1d433c6ff19bb362407d050385aecf4f35a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20K=C3=BCrten?= Date: Thu, 10 Apr 2025 14:23:28 +0200 Subject: [PATCH 4/9] Update event documentation to include supported actions for DocumentReleasedEvent, EngineeringChangeReleasedEvent, and PartReleasedEvent. --- docs/reference/events.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/reference/events.md b/docs/reference/events.md index 392fd4a..ab738ff 100644 --- a/docs/reference/events.md +++ b/docs/reference/events.md @@ -72,6 +72,10 @@ Be aware that the document is not released yet and the release might still be ab This event is fired **after** a document has been released. Raising an exception thus can not prevent the release. +**Supported actions:** + +- [StartWorkflowAction](actions.md#StartWorkflowAction) + **DocumentReleasedEvent.name:** document_released **DocumentReleasedEvent.data:** @@ -136,6 +140,10 @@ Be aware that the engineering change is not released yet and the release might s This event is fired **after** an engineering change has been released. Raising an exception thus can not prevent the release. +**Supported actions:** + +- [StartWorkflowAction](actions.md#StartWorkflowAction) + **EngineeringChangeReleasedEvent.name:** engineering_change_released **EngineeringChangeReleasedEvent.data:** @@ -217,6 +225,10 @@ Be aware that the part is not released yet and the release might still be aborte This event is fired **after** a part has been released. Raising an exception thus can not prevent the release. +**Supported actions:** + +- [StartWorkflowAction](actions.md#StartWorkflowAction) + **PartReleasedEvent.name:** part_released **PartReleasedEvent.data:** From 0d77417b9b4597278534777ad27ebc80ebec697a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20K=C3=BCrten?= Date: Thu, 10 Apr 2025 14:23:43 +0200 Subject: [PATCH 5/9] update schema --- json_schemas/workload_response.json | 140 +++++++++++++++++++++++++++- 1 file changed, 139 insertions(+), 1 deletion(-) diff --git a/json_schemas/workload_response.json b/json_schemas/workload_response.json index 938c3fd..badad7d 100644 --- a/json_schemas/workload_response.json +++ b/json_schemas/workload_response.json @@ -54,6 +54,140 @@ }, "title": "DummyAction", "type": "object" + }, + "StartWorkflowAction": { + "properties": { + "name": { + "const": "start_workflow", + "default": "start_workflow", + "title": "Name", + "type": "string" + }, + "id": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Id" + }, + "template_id": { + "description": "ID of the workflow template to start", + "title": "Template Id", + "type": "string" + }, + "cdb_project_id": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "ID of the project in which the workflow should be started", + "title": "Cdb Project Id" + }, + "title": { + "description": "Title of the workflow", + "title": "Title", + "type": "string" + }, + "attachment_ids": { + "description": "List of cdb_object_ids to attach to the workflow", + "items": { + "type": "string" + }, + "title": "Attachment Ids", + "type": "array" + }, + "global_briefcase_object_ids": { + "description": "List of cdb_object_ids to attach to the global briefcase", + "items": { + "type": "string" + }, + "title": "Global Briefcase Object Ids", + "type": "array" + }, + "task_configurations": { + "description": "List of task configurations", + "items": { + "$ref": "#/$defs/TaskConfiguration" + }, + "title": "Task Configurations", + "type": "array" + } + }, + "required": [ + "template_id", + "title" + ], + "title": "StartWorkflowAction", + "type": "object" + }, + "Subject": { + "properties": { + "subject_id": { + "description": "ID of the subject, eg. a role name or personalnummer", + "title": "Subject Id", + "type": "string" + }, + "subject_type": { + "description": "Type of the subject: Person, PCS Role or Common Role", + "enum": [ + "Person", + "PCS Role", + "Common Role" + ], + "title": "Subject Type", + "type": "string" + } + }, + "required": [ + "subject_id", + "subject_type" + ], + "title": "Subject", + "type": "object" + }, + "TaskConfiguration": { + "properties": { + "task_id": { + "description": "Identifier for the task", + "title": "Task Id", + "type": "string" + }, + "responsible": { + "anyOf": [ + { + "$ref": "#/$defs/Subject" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Responsible subject for the task" + }, + "recipients": { + "description": "List of recipients for the task (only used by information tasks)", + "items": { + "$ref": "#/$defs/Subject" + }, + "title": "Recipients", + "type": "array" + } + }, + "required": [ + "task_id" + ], + "title": "TaskConfiguration", + "type": "object" } }, "properties": { @@ -73,7 +207,8 @@ "discriminator": { "mapping": { "abort_and_show_error": "#/$defs/AbortAndShowErrorAction", - "dummy": "#/$defs/DummyAction" + "dummy": "#/$defs/DummyAction", + "start_workflow": "#/$defs/StartWorkflowAction" }, "propertyName": "name" }, @@ -83,6 +218,9 @@ }, { "$ref": "#/$defs/DummyAction" + }, + { + "$ref": "#/$defs/StartWorkflowAction" } ] }, From a43e9710fa82aac5da85a4bc11e9c3f0637c05a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20K=C3=BCrten?= Date: Thu, 10 Apr 2025 14:23:50 +0200 Subject: [PATCH 6/9] dev1 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 4db1db9..2287b2d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "contactsoftware-functions" -version = "0.12.0" +version = "0.13.0.dev1" readme = "README.md" license = "MIT" From 16e3fe858c2349fbcd94c9ce1cb1a3242bc70161 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20K=C3=BCrten?= Date: Tue, 15 Apr 2025 14:34:36 +0200 Subject: [PATCH 7/9] add title and description to task configuration --- csfunctions/actions/start_workflow.py | 6 ++++++ docs/reference/actions.md | 2 ++ json_schemas/workload_response.json | 26 ++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/csfunctions/actions/start_workflow.py b/csfunctions/actions/start_workflow.py index fb64c64..1b238d4 100644 --- a/csfunctions/actions/start_workflow.py +++ b/csfunctions/actions/start_workflow.py @@ -19,6 +19,12 @@ class TaskConfiguration(BaseModel): default_factory=list, description="List of recipients for the task (only used by information tasks)", ) + description: str | None = Field( + default=None, description="Description of the task. If not set, the existing description will be kept." + ) + title: str | None = Field( + default=None, description="Title of the task. If not set, the existing title will be kept." + ) class StartWorkflowAction(BaseAction): diff --git a/docs/reference/actions.md b/docs/reference/actions.md index 70ab28a..f873ec2 100644 --- a/docs/reference/actions.md +++ b/docs/reference/actions.md @@ -50,6 +50,8 @@ Creates a new workflow from a template and starts it. |task_id|str|Identifier for the task| |responsible|[Subject](actions.md#Subject) \| None|Responsible Subject for the task| |recipients|list[[Subject](actions.md#Subject)]|List of recipients (only used by information tasks)| +|description|str \| None|Description of the task. If not set, the existing description will be kept.| +|title|str \| None|Title of the task. If not set, the existing title will be kept.| **Subject:** diff --git a/json_schemas/workload_response.json b/json_schemas/workload_response.json index badad7d..abb553e 100644 --- a/json_schemas/workload_response.json +++ b/json_schemas/workload_response.json @@ -181,6 +181,32 @@ }, "title": "Recipients", "type": "array" + }, + "description": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Description of the task. If not set, the existing description will be kept.", + "title": "Description" + }, + "title": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Title of the task. If not set, the existing title will be kept.", + "title": "Title" } }, "required": [ From f7db8980afb81bf83122ca9a3675e6096a320690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20K=C3=BCrten?= Date: Tue, 15 Apr 2025 14:53:42 +0200 Subject: [PATCH 8/9] dev3 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 2287b2d..cedbeeb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "contactsoftware-functions" -version = "0.13.0.dev1" +version = "0.13.0.dev3" readme = "README.md" license = "MIT" From 1de90b02cdd7a4e05c6e32e03a99279420fbe030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20K=C3=BCrten?= Date: Thu, 17 Apr 2025 15:26:07 +0200 Subject: [PATCH 9/9] fix: link_objects function to handle individual BaseObject fields, not only lists --- csfunctions/handler.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/csfunctions/handler.py b/csfunctions/handler.py index 8ef8a10..a1e7266 100644 --- a/csfunctions/handler.py +++ b/csfunctions/handler.py @@ -77,6 +77,10 @@ def link_objects(event: Event): # the list might contain entries that are not objects, so we check first if isinstance(obj, BaseObject): obj.link_objects(data) + elif isinstance(field, BaseObject): + # if the field is not a list, we check if it is an object and link it + field.link_objects(data) + # if the field is not a list or an object, we ignore it def execute(function_name: str, request_body: str, function_dir: str = "src") -> str: