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..1b238d4 --- /dev/null +++ b/csfunctions/actions/start_workflow.py @@ -0,0 +1,48 @@ +from typing import Literal, Optional + +from pydantic import BaseModel, Field + +from .base import ActionNames, BaseAction + + +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)", + ) + 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): + 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_configurations: list[TaskConfiguration] = Field( + default_factory=list, description="List of task configurations" + ) diff --git a/docs/reference/actions.md b/docs/reference/actions.md index 685b401..f873ec2 100644 --- a/docs/reference/actions.md +++ b/docs/reference/actions.md @@ -12,13 +12,50 @@ 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)| +|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:** + +|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"| diff --git a/docs/reference/events.md b/docs/reference/events.md index bef3748..ba79eae 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:** diff --git a/json_schemas/workload_response.json b/json_schemas/workload_response.json index 938c3fd..abb553e 100644 --- a/json_schemas/workload_response.json +++ b/json_schemas/workload_response.json @@ -54,6 +54,166 @@ }, "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" + }, + "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": [ + "task_id" + ], + "title": "TaskConfiguration", + "type": "object" } }, "properties": { @@ -73,7 +233,8 @@ "discriminator": { "mapping": { "abort_and_show_error": "#/$defs/AbortAndShowErrorAction", - "dummy": "#/$defs/DummyAction" + "dummy": "#/$defs/DummyAction", + "start_workflow": "#/$defs/StartWorkflowAction" }, "propertyName": "name" }, @@ -83,6 +244,9 @@ }, { "$ref": "#/$defs/DummyAction" + }, + { + "$ref": "#/$defs/StartWorkflowAction" } ] }, diff --git a/pyproject.toml b/pyproject.toml index 657916e..cedbeeb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "contactsoftware-functions" -version = "0.13.1" +version = "0.13.0.dev3" readme = "README.md" license = "MIT"