Skip to content

Run workflow action #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion csfunctions/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = [
Expand All @@ -15,4 +16,5 @@
"DummyAction",
"AbortAndShowErrorAction",
"ActionUnion",
"StartWorkflowAction",
]
1 change: 1 addition & 0 deletions csfunctions/actions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
53 changes: 53 additions & 0 deletions csfunctions/actions/start_workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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. "
"(max. 1024 characters)",
max_length=1024,
)
title: str | None = Field(
default=None,
description="Title of the task. If not set, the existing title will be kept. (max. 60 characters)",
max_length=60,
)


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 (max. 255 characters)", max_length=255)
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"
)
43 changes: 40 additions & 3 deletions docs/reference/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (max. 255 characters)|
|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. (max. 1024 characters)|
|title|str \| None|Title of the task. If not set, the existing title will be kept. (max. 60 characters)|

**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"|
12 changes: 12 additions & 0 deletions docs/reference/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:**
Expand Down Expand Up @@ -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:**
Expand Down Expand Up @@ -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:**
Expand Down
169 changes: 168 additions & 1 deletion json_schemas/workload_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,169 @@
},
"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 (max. 255 characters)",
"maxLength": 255,
"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": [
{
"maxLength": 1024,
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Description of the task. If not set, the existing description will be kept. (max. 1024 characters)",
"title": "Description"
},
"title": {
"anyOf": [
{
"maxLength": 60,
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Title of the task. If not set, the existing title will be kept. (max. 60 characters)",
"title": "Title"
}
},
"required": [
"task_id"
],
"title": "TaskConfiguration",
"type": "object"
}
},
"properties": {
Expand All @@ -73,7 +236,8 @@
"discriminator": {
"mapping": {
"abort_and_show_error": "#/$defs/AbortAndShowErrorAction",
"dummy": "#/$defs/DummyAction"
"dummy": "#/$defs/DummyAction",
"start_workflow": "#/$defs/StartWorkflowAction"
},
"propertyName": "name"
},
Expand All @@ -83,6 +247,9 @@
},
{
"$ref": "#/$defs/DummyAction"
},
{
"$ref": "#/$defs/StartWorkflowAction"
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "contactsoftware-functions"
version = "0.13.1"
version = "0.13.0.dev3"
readme = "README.md"

license = "MIT"
Expand Down
Loading