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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
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
48 changes: 48 additions & 0 deletions csfunctions/actions/start_workflow.py
Original file line number Diff line number Diff line change
@@ -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"
)
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|
|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"|
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
166 changes: 165 additions & 1 deletion json_schemas/workload_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -73,7 +233,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 +244,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