Skip to content

Commit a133cf4

Browse files
jens-kuertenJens Kürten
andauthored
Run workflow action (#27)
--------- Co-authored-by: Jens Kürten <jens.kuerten@contact-software.com>
1 parent 848da7d commit a133cf4

File tree

7 files changed

+278
-6
lines changed

7 files changed

+278
-6
lines changed

csfunctions/actions/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
from .abort_and_show_error import AbortAndShowErrorAction
66
from .base import ActionNames
77
from .dummy import DummyAction
8+
from .start_workflow import StartWorkflowAction
89

9-
ActionUnion = Union[AbortAndShowErrorAction, DummyAction]
10+
ActionUnion = Union[AbortAndShowErrorAction, DummyAction, StartWorkflowAction]
1011
Action = Annotated[ActionUnion, Field(discriminator="name")]
1112

1213
__all__ = [
@@ -15,4 +16,5 @@
1516
"DummyAction",
1617
"AbortAndShowErrorAction",
1718
"ActionUnion",
19+
"StartWorkflowAction",
1820
]

csfunctions/actions/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
class ActionNames(str, Enum):
77
ABORT_AND_SHOW_ERROR = "abort_and_show_error"
88
DUMMY = "dummy"
9+
START_WORKFLOW = "start_workflow"
910

1011

1112
class BaseAction(BaseModel):
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from typing import Literal, Optional
2+
3+
from pydantic import BaseModel, Field
4+
5+
from .base import ActionNames, BaseAction
6+
7+
8+
class Subject(BaseModel):
9+
subject_id: str = Field(..., description="ID of the subject, eg. a role name or personalnummer")
10+
subject_type: Literal["Person", "PCS Role", "Common Role"] = Field(
11+
..., description="Type of the subject: Person, PCS Role or Common Role"
12+
)
13+
14+
15+
class TaskConfiguration(BaseModel):
16+
task_id: str = Field(..., description="Identifier for the task")
17+
responsible: Optional[Subject] = Field(default=None, description="Responsible subject for the task")
18+
recipients: list[Subject] = Field(
19+
default_factory=list,
20+
description="List of recipients for the task (only used by information tasks)",
21+
)
22+
description: str | None = Field(
23+
default=None,
24+
description="Description of the task. If not set, the existing description will be kept. "
25+
"(max. 1024 characters)",
26+
max_length=1024,
27+
)
28+
title: str | None = Field(
29+
default=None,
30+
description="Title of the task. If not set, the existing title will be kept. (max. 60 characters)",
31+
max_length=60,
32+
)
33+
34+
35+
class StartWorkflowAction(BaseAction):
36+
name: Literal[ActionNames.START_WORKFLOW] = ActionNames.START_WORKFLOW
37+
template_id: str = Field(..., description="ID of the workflow template to start")
38+
cdb_project_id: str | None = Field(
39+
default=None,
40+
description="ID of the project in which the workflow should be started",
41+
)
42+
title: str = Field(..., description="Title of the workflow (max. 255 characters)", max_length=255)
43+
attachment_ids: list[str] = Field(
44+
default_factory=list,
45+
description="List of cdb_object_ids to attach to the workflow",
46+
)
47+
global_briefcase_object_ids: list[str] = Field(
48+
default_factory=list,
49+
description="List of cdb_object_ids to attach to the global briefcase",
50+
)
51+
task_configurations: list[TaskConfiguration] = Field(
52+
default_factory=list, description="List of task configurations"
53+
)

docs/reference/actions.md

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,50 @@ def my_function(metadata, event, service):
1212
return AbortAndShowErrorAction(message="Custom error message.")
1313
```
1414

15-
## AbortAndShowErrorAction
15+
## AbortAndShowErrorAction (abort_and_show_error)
1616

1717
`csfunctions.actions.AbortAndShowErrorAction`
1818

1919
Aborts the current operation and shows an error message to the user.
2020

21+
**Attributes:**
2122

22-
**AbortAndShowErrorAction.name:** abort_and_show_error
23+
|Attribute|Type|Description|
24+
|-|-|-|
25+
|message|str|Error message that will be shown to the user|
2326

24-
**AbortAndShowErrorAction.message:** Error message that will be shown to the user
27+
## StartWorkflowAction (start_workflow)
28+
29+
`csfunctions.actions.StartWorkflowAction`
30+
31+
Creates a new workflow from a template and starts it.
32+
33+
34+
35+
**Attributes:**
36+
37+
|Attribute|Type|Description|
38+
|-|-|-|
39+
|template_id|str|ID of the workflow template|
40+
|cdb_project_id|str \| None|ID of the project in which the workflow should be started|
41+
|title|str|Title that the new workflow should have (max. 255 characters)|
42+
|attachment_ids|list[str]|List of cdb_object_ids to attach to the workflow|
43+
|global_briefcase_object_ids|list[str]|List of cdb_object_ids to attach to the global briefcase|
44+
|task_configurations|list[[TaskConfiguration](actions.md#TaskConfiguration)]|List of task configurations|
45+
46+
**TaskConfiguration:**
47+
48+
|Attribute|Type|Description|
49+
|-|-|-|
50+
|task_id|str|Identifier for the task|
51+
|responsible|[Subject](actions.md#Subject) \| None|Responsible Subject for the task|
52+
|recipients|list[[Subject](actions.md#Subject)]|List of recipients (only used by information tasks)|
53+
|description|str \| None|Description of the task. If not set, the existing description will be kept. (max. 1024 characters)|
54+
|title|str \| None|Title of the task. If not set, the existing title will be kept. (max. 60 characters)|
55+
56+
**Subject:**
57+
58+
|Attribute|Type|Description|
59+
|-|-|-|
60+
|subject_id|str|ID of the subject, e.g. a role name or "personalnummer"|
61+
|subject_type|str|Type of the subject. Can be "Person", "PCS Role" or "Common Role"|

docs/reference/events.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ Be aware that the document is not released yet and the release might still be ab
7272

7373
This event is fired **after** a document has been released. Raising an exception thus can not prevent the release.
7474

75+
**Supported actions:**
76+
77+
- [StartWorkflowAction](actions.md#StartWorkflowAction)
78+
7579
**DocumentReleasedEvent.name:** document_released
7680

7781
**DocumentReleasedEvent.data:**
@@ -136,6 +140,10 @@ Be aware that the engineering change is not released yet and the release might s
136140

137141
This event is fired **after** an engineering change has been released. Raising an exception thus can not prevent the release.
138142

143+
**Supported actions:**
144+
145+
- [StartWorkflowAction](actions.md#StartWorkflowAction)
146+
139147
**EngineeringChangeReleasedEvent.name:** engineering_change_released
140148

141149
**EngineeringChangeReleasedEvent.data:**
@@ -217,6 +225,10 @@ Be aware that the part is not released yet and the release might still be aborte
217225

218226
This event is fired **after** a part has been released. Raising an exception thus can not prevent the release.
219227

228+
**Supported actions:**
229+
230+
- [StartWorkflowAction](actions.md#StartWorkflowAction)
231+
220232
**PartReleasedEvent.name:** part_released
221233

222234
**PartReleasedEvent.data:**

json_schemas/workload_response.json

Lines changed: 168 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,169 @@
5454
},
5555
"title": "DummyAction",
5656
"type": "object"
57+
},
58+
"StartWorkflowAction": {
59+
"properties": {
60+
"name": {
61+
"const": "start_workflow",
62+
"default": "start_workflow",
63+
"title": "Name",
64+
"type": "string"
65+
},
66+
"id": {
67+
"anyOf": [
68+
{
69+
"type": "string"
70+
},
71+
{
72+
"type": "null"
73+
}
74+
],
75+
"default": null,
76+
"title": "Id"
77+
},
78+
"template_id": {
79+
"description": "ID of the workflow template to start",
80+
"title": "Template Id",
81+
"type": "string"
82+
},
83+
"cdb_project_id": {
84+
"anyOf": [
85+
{
86+
"type": "string"
87+
},
88+
{
89+
"type": "null"
90+
}
91+
],
92+
"default": null,
93+
"description": "ID of the project in which the workflow should be started",
94+
"title": "Cdb Project Id"
95+
},
96+
"title": {
97+
"description": "Title of the workflow (max. 255 characters)",
98+
"maxLength": 255,
99+
"title": "Title",
100+
"type": "string"
101+
},
102+
"attachment_ids": {
103+
"description": "List of cdb_object_ids to attach to the workflow",
104+
"items": {
105+
"type": "string"
106+
},
107+
"title": "Attachment Ids",
108+
"type": "array"
109+
},
110+
"global_briefcase_object_ids": {
111+
"description": "List of cdb_object_ids to attach to the global briefcase",
112+
"items": {
113+
"type": "string"
114+
},
115+
"title": "Global Briefcase Object Ids",
116+
"type": "array"
117+
},
118+
"task_configurations": {
119+
"description": "List of task configurations",
120+
"items": {
121+
"$ref": "#/$defs/TaskConfiguration"
122+
},
123+
"title": "Task Configurations",
124+
"type": "array"
125+
}
126+
},
127+
"required": [
128+
"template_id",
129+
"title"
130+
],
131+
"title": "StartWorkflowAction",
132+
"type": "object"
133+
},
134+
"Subject": {
135+
"properties": {
136+
"subject_id": {
137+
"description": "ID of the subject, eg. a role name or personalnummer",
138+
"title": "Subject Id",
139+
"type": "string"
140+
},
141+
"subject_type": {
142+
"description": "Type of the subject: Person, PCS Role or Common Role",
143+
"enum": [
144+
"Person",
145+
"PCS Role",
146+
"Common Role"
147+
],
148+
"title": "Subject Type",
149+
"type": "string"
150+
}
151+
},
152+
"required": [
153+
"subject_id",
154+
"subject_type"
155+
],
156+
"title": "Subject",
157+
"type": "object"
158+
},
159+
"TaskConfiguration": {
160+
"properties": {
161+
"task_id": {
162+
"description": "Identifier for the task",
163+
"title": "Task Id",
164+
"type": "string"
165+
},
166+
"responsible": {
167+
"anyOf": [
168+
{
169+
"$ref": "#/$defs/Subject"
170+
},
171+
{
172+
"type": "null"
173+
}
174+
],
175+
"default": null,
176+
"description": "Responsible subject for the task"
177+
},
178+
"recipients": {
179+
"description": "List of recipients for the task (only used by information tasks)",
180+
"items": {
181+
"$ref": "#/$defs/Subject"
182+
},
183+
"title": "Recipients",
184+
"type": "array"
185+
},
186+
"description": {
187+
"anyOf": [
188+
{
189+
"maxLength": 1024,
190+
"type": "string"
191+
},
192+
{
193+
"type": "null"
194+
}
195+
],
196+
"default": null,
197+
"description": "Description of the task. If not set, the existing description will be kept. (max. 1024 characters)",
198+
"title": "Description"
199+
},
200+
"title": {
201+
"anyOf": [
202+
{
203+
"maxLength": 60,
204+
"type": "string"
205+
},
206+
{
207+
"type": "null"
208+
}
209+
],
210+
"default": null,
211+
"description": "Title of the task. If not set, the existing title will be kept. (max. 60 characters)",
212+
"title": "Title"
213+
}
214+
},
215+
"required": [
216+
"task_id"
217+
],
218+
"title": "TaskConfiguration",
219+
"type": "object"
57220
}
58221
},
59222
"properties": {
@@ -73,7 +236,8 @@
73236
"discriminator": {
74237
"mapping": {
75238
"abort_and_show_error": "#/$defs/AbortAndShowErrorAction",
76-
"dummy": "#/$defs/DummyAction"
239+
"dummy": "#/$defs/DummyAction",
240+
"start_workflow": "#/$defs/StartWorkflowAction"
77241
},
78242
"propertyName": "name"
79243
},
@@ -83,6 +247,9 @@
83247
},
84248
{
85249
"$ref": "#/$defs/DummyAction"
250+
},
251+
{
252+
"$ref": "#/$defs/StartWorkflowAction"
86253
}
87254
]
88255
},

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "contactsoftware-functions"
3-
version = "0.13.1"
3+
version = "0.13.0.dev3"
44
readme = "README.md"
55

66
license = "MIT"

0 commit comments

Comments
 (0)