diff --git a/csfunctions/events/__init__.py b/csfunctions/events/__init__.py index a2f91b4..6a2e725 100644 --- a/csfunctions/events/__init__.py +++ b/csfunctions/events/__init__.py @@ -3,12 +3,16 @@ from pydantic import Field from .dialog_data import DocumentReleaseDialogData, PartReleaseDialogData +from .document_create_check import DocumentCreateCheckData, DocumentCreateCheckEvent +from .document_modify_check import DocumentModifyCheckData, DocumentModifyCheckEvent from .document_release import DocumentReleaseData, DocumentReleaseEvent from .document_release_check import DocumentReleaseCheckData, DocumentReleaseCheckEvent from .dummy import DummyEvent, DummyEventData from .engineering_change_release import EngineeringChangeRelease, EngineeringChangeReleaseData from .engineering_change_release_check import EngineeringChangeReleaseCheck, EngineeringChangeReleaseCheckData from .field_value_calculation import FieldValueCalculationData, FieldValueCalculationEvent +from .part_create_check import PartCreateCheckData, PartCreateCheckEvent +from .part_modify_check import PartModifyCheckData, PartModifyCheckEvent from .part_release import PartReleaseData, PartReleaseEvent from .part_release_check import PartReleaseCheckData, PartReleaseCheckEvent from .workflow_task_trigger import WorkflowTaskTriggerEvent, WorkflowTaskTriggerEventData @@ -24,6 +28,10 @@ EngineeringChangeRelease, EngineeringChangeReleaseCheck, WorkflowTaskTriggerEvent, + DocumentCreateCheckEvent, + DocumentModifyCheckEvent, + PartCreateCheckEvent, + PartModifyCheckEvent, ], Field(discriminator="name"), ] @@ -37,6 +45,10 @@ EngineeringChangeReleaseData, EngineeringChangeReleaseCheckData, WorkflowTaskTriggerEventData, + DocumentCreateCheckData, + DocumentModifyCheckData, + PartCreateCheckData, + PartModifyCheckData, ] __all__ = [ @@ -60,4 +72,12 @@ "WorkflowTaskTriggerEventData", "DocumentReleaseDialogData", "PartReleaseDialogData", + "DocumentCreateCheckData", + "DocumentCreateCheckEvent", + "DocumentModifyCheckData", + "DocumentModifyCheckEvent", + "PartCreateCheckData", + "PartCreateCheckEvent", + "PartModifyCheckData", + "PartModifyCheckEvent", ] diff --git a/csfunctions/events/base.py b/csfunctions/events/base.py index 282c256..fbfe50c 100644 --- a/csfunctions/events/base.py +++ b/csfunctions/events/base.py @@ -13,6 +13,10 @@ class EventNames(str, Enum): ENGINEERING_CHANGE_RELEASE_CHECK = "engineering_change_release_check" FIELD_VALUE_CALCULATION = "field_value_calculation" WORKFLOW_TASK_TRIGGER = "workflow_task_trigger" + DOCUMENT_CREATE_CHECK = "document_create_check" + DOCUMENT_MODIFY_CHECK = "document_modify_check" + PART_CREATE_CHECK = "part_create_check" + PART_MODIFY_CHECK = "part_modify_check" class BaseEvent(BaseModel): diff --git a/csfunctions/events/document_create_check.py b/csfunctions/events/document_create_check.py new file mode 100644 index 0000000..4af0468 --- /dev/null +++ b/csfunctions/events/document_create_check.py @@ -0,0 +1,17 @@ +from typing import Literal + +from pydantic import BaseModel, Field + +from csfunctions.objects import Document, Part + +from .base import BaseEvent, EventNames + + +class DocumentCreateCheckData(BaseModel): + documents: list[Document] = Field(..., description="List of documents that are about to be created") + linked_parts: list[Part] = Field(..., description="List of parts that belong to the documents") + + +class DocumentCreateCheckEvent(BaseEvent): + name: Literal[EventNames.DOCUMENT_CREATE_CHECK] = EventNames.DOCUMENT_CREATE_CHECK + data: DocumentCreateCheckData diff --git a/csfunctions/events/document_modify_check.py b/csfunctions/events/document_modify_check.py new file mode 100644 index 0000000..1581869 --- /dev/null +++ b/csfunctions/events/document_modify_check.py @@ -0,0 +1,17 @@ +from typing import Literal + +from pydantic import BaseModel, Field + +from csfunctions.objects import Document, Part + +from .base import BaseEvent, EventNames + + +class DocumentModifyCheckData(BaseModel): + documents: list[Document] = Field(..., description="List of documents that are about to be modified") + linked_parts: list[Part] = Field(..., description="List of parts that belong to the documents") + + +class DocumentModifyCheckEvent(BaseEvent): + name: Literal[EventNames.DOCUMENT_MODIFY_CHECK] = EventNames.DOCUMENT_MODIFY_CHECK + data: DocumentModifyCheckData diff --git a/csfunctions/events/part_create_check.py b/csfunctions/events/part_create_check.py new file mode 100644 index 0000000..3cef96e --- /dev/null +++ b/csfunctions/events/part_create_check.py @@ -0,0 +1,17 @@ +from typing import Literal + +from pydantic import BaseModel, Field + +from csfunctions.objects import Document, Part + +from .base import BaseEvent, EventNames + + +class PartCreateCheckData(BaseModel): + parts: list[Part] = Field(..., description="List of parts that are about to be created") + linked_documents: list[Document] = Field(..., description="List of documents that are referenced by the parts.") + + +class PartCreateCheckEvent(BaseEvent): + name: Literal[EventNames.PART_CREATE_CHECK] = EventNames.PART_CREATE_CHECK + data: PartCreateCheckData diff --git a/csfunctions/events/part_modify_check.py b/csfunctions/events/part_modify_check.py new file mode 100644 index 0000000..a52ad4a --- /dev/null +++ b/csfunctions/events/part_modify_check.py @@ -0,0 +1,17 @@ +from typing import Literal + +from pydantic import BaseModel, Field + +from csfunctions.objects import Document, Part + +from .base import BaseEvent, EventNames + + +class PartModifyCheckData(BaseModel): + parts: list[Part] = Field(..., description="List of parts that are about to be modified") + linked_documents: list[Document] = Field(..., description="List of documents that are referenced by the parts.") + + +class PartModifyCheckEvent(BaseEvent): + name: Literal[EventNames.PART_MODIFY_CHECK] = EventNames.PART_MODIFY_CHECK + data: PartModifyCheckData diff --git a/docs/reference/events.md b/docs/reference/events.md index f7fba6a..f1351a0 100644 --- a/docs/reference/events.md +++ b/docs/reference/events.md @@ -1,5 +1,45 @@ Events always have a `name` and a `data` attribute. The contents of those attributes depend on the type of the event. + +## DocumentCreateCheckEvent +`csfunctions.events.DocumentCreateCheckEvent` + +This event is fired when a user tries to create or copy a document. Raising an exception will prevent the creation. +The event is triggered before any field calculations are performed. + +**Supported actions:** + +- [AbortAndShowErrorAction](actions.md#AbortAndShowErrorAction) + +**DocumentCreateCheckEvent.name:** document_create_check + +**DocumentCreateCheckEvent.data:** + +|Attribute|Type|Description| +|-|-|-| +|documents| list[[Document](objects.md#document)]|List of documents that are about to be created.| +|linked_parts| list[[Part](objects.md#part)]|List of parts that belong to the documents.| + +## DocumentModifyCheckEvent +`csfunctions.events.DocumentModifyCheckEvent` + +This event is fired when a user tries to modify a document. Raising an exception will prevent the modification. +The event is triggered before any field calculations are performed. + +**Supported actions:** + +- [AbortAndShowErrorAction](actions.md#AbortAndShowErrorAction) + +**DocumentModifyCheckEvent.name:** document_modify_check + +**DocumentModifyCheckEvent.data:** + +|Attribute|Type|Description| +|-|-|-| +|documents| list[[Document](objects.md#document)]|List of documents that are about to be modified.| +|linked_parts| list[[Part](objects.md#part)]|List of parts that belong to the documents.| + + ## DocumentReleaseCheckEvent `csfunctions.events.DocumentReleaseCheckEvent` @@ -86,6 +126,43 @@ This event is fired **after** an engineering change has been released. Raising a |documents| list[[Document](objects.md#document)]|List of included documents.| |parts| list[[Part](objects.md#part)]|List of included parts.| +## PartCreateCheckEvent +`csfunctions.events.PartCreateCheckEvent` + +This event is fired when a user tries to create or copy a part. Raising an exception will prevent the creation. +The event is triggered before any field calculations are performed. + +**Supported actions:** + +- [AbortAndShowErrorAction](actions.md#AbortAndShowErrorAction) + +**PartCreateCheckEvent.name:** part_create_check + +**PartCreateCheckEvent.data:** + +|Attribute|Type|Description| +|-|-|-| +|parts| list[[Part](objects.md#part)]|List of parts that are about to be created.| +|linked_documents| list[[Document](objects.md#document)]|List of documents that are referenced by the parts.| + +## PartModifyCheckEvent +`csfunctions.events.PartModifyCheckEvent` + +This event is fired when a user tries to modify a part. Raising an exception will prevent the modification. +The event is triggered before any field calculations are performed. + +**Supported actions:** + +- [AbortAndShowErrorAction](actions.md#AbortAndShowErrorAction) + +**PartModifyCheckEvent.name:** part_modify_check + +**PartModifyCheckEvent.data:** + +|Attribute|Type|Description| +|-|-|-| +|parts| list[[Part](objects.md#part)]|List of parts that are about to be modified.| +|linked_documents| list[[Document](objects.md#document)]|List of documents that are referenced by the parts.| ## PartReleaseCheckEvent `csfunctions.events.PartReleaseCheckEvent` diff --git a/json_schemas/request.json b/json_schemas/request.json index 00f5090..d30b574 100644 --- a/json_schemas/request.json +++ b/json_schemas/request.json @@ -731,6 +731,106 @@ "title": "Document", "type": "object" }, + "DocumentCreateCheckData": { + "properties": { + "documents": { + "description": "List of documents that are about to be created", + "items": { + "$ref": "#/$defs/Document" + }, + "title": "Documents", + "type": "array" + }, + "linked_parts": { + "description": "List of parts that belong to the documents", + "items": { + "$ref": "#/$defs/Part" + }, + "title": "Linked Parts", + "type": "array" + } + }, + "required": [ + "documents", + "linked_parts" + ], + "title": "DocumentCreateCheckData", + "type": "object" + }, + "DocumentCreateCheckEvent": { + "properties": { + "name": { + "const": "document_create_check", + "default": "document_create_check", + "title": "Name", + "type": "string" + }, + "event_id": { + "description": "unique identifier", + "title": "Event Id", + "type": "string" + }, + "data": { + "$ref": "#/$defs/DocumentCreateCheckData" + } + }, + "required": [ + "event_id", + "data" + ], + "title": "DocumentCreateCheckEvent", + "type": "object" + }, + "DocumentModifyCheckData": { + "properties": { + "documents": { + "description": "List of documents that are about to be modified", + "items": { + "$ref": "#/$defs/Document" + }, + "title": "Documents", + "type": "array" + }, + "linked_parts": { + "description": "List of parts that belong to the documents", + "items": { + "$ref": "#/$defs/Part" + }, + "title": "Linked Parts", + "type": "array" + } + }, + "required": [ + "documents", + "linked_parts" + ], + "title": "DocumentModifyCheckData", + "type": "object" + }, + "DocumentModifyCheckEvent": { + "properties": { + "name": { + "const": "document_modify_check", + "default": "document_modify_check", + "title": "Name", + "type": "string" + }, + "event_id": { + "description": "unique identifier", + "title": "Event Id", + "type": "string" + }, + "data": { + "$ref": "#/$defs/DocumentModifyCheckData" + } + }, + "required": [ + "event_id", + "data" + ], + "title": "DocumentModifyCheckEvent", + "type": "object" + }, "DocumentReleaseCheckData": { "properties": { "documents": { @@ -2423,6 +2523,106 @@ "title": "Part", "type": "object" }, + "PartCreateCheckData": { + "properties": { + "parts": { + "description": "List of parts that are about to be created", + "items": { + "$ref": "#/$defs/Part" + }, + "title": "Parts", + "type": "array" + }, + "linked_documents": { + "description": "List of documents that are referenced by the parts.", + "items": { + "$ref": "#/$defs/Document" + }, + "title": "Linked Documents", + "type": "array" + } + }, + "required": [ + "parts", + "linked_documents" + ], + "title": "PartCreateCheckData", + "type": "object" + }, + "PartCreateCheckEvent": { + "properties": { + "name": { + "const": "part_create_check", + "default": "part_create_check", + "title": "Name", + "type": "string" + }, + "event_id": { + "description": "unique identifier", + "title": "Event Id", + "type": "string" + }, + "data": { + "$ref": "#/$defs/PartCreateCheckData" + } + }, + "required": [ + "event_id", + "data" + ], + "title": "PartCreateCheckEvent", + "type": "object" + }, + "PartModifyCheckData": { + "properties": { + "parts": { + "description": "List of parts that are about to be modified", + "items": { + "$ref": "#/$defs/Part" + }, + "title": "Parts", + "type": "array" + }, + "linked_documents": { + "description": "List of documents that are referenced by the parts.", + "items": { + "$ref": "#/$defs/Document" + }, + "title": "Linked Documents", + "type": "array" + } + }, + "required": [ + "parts", + "linked_documents" + ], + "title": "PartModifyCheckData", + "type": "object" + }, + "PartModifyCheckEvent": { + "properties": { + "name": { + "const": "part_modify_check", + "default": "part_modify_check", + "title": "Name", + "type": "string" + }, + "event_id": { + "description": "unique identifier", + "title": "Event Id", + "type": "string" + }, + "data": { + "$ref": "#/$defs/PartModifyCheckData" + } + }, + "required": [ + "event_id", + "data" + ], + "title": "PartModifyCheckEvent", + "type": "object" + }, "PartReleaseCheckData": { "properties": { "parts": { @@ -2749,12 +2949,16 @@ "event": { "discriminator": { "mapping": { + "document_create_check": "#/$defs/DocumentCreateCheckEvent", + "document_modify_check": "#/$defs/DocumentModifyCheckEvent", "document_release": "#/$defs/DocumentReleaseEvent", "document_release_check": "#/$defs/DocumentReleaseCheckEvent", "dummy": "#/$defs/DummyEvent", "engineering_change_release": "#/$defs/EngineeringChangeRelease", "engineering_change_release_check": "#/$defs/EngineeringChangeReleaseCheck", "field_value_calculation": "#/$defs/FieldValueCalculationEvent", + "part_create_check": "#/$defs/PartCreateCheckEvent", + "part_modify_check": "#/$defs/PartModifyCheckEvent", "part_release": "#/$defs/PartReleaseEvent", "part_release_check": "#/$defs/PartReleaseCheckEvent", "workflow_task_trigger": "#/$defs/WorkflowTaskTriggerEvent" @@ -2788,6 +2992,18 @@ }, { "$ref": "#/$defs/WorkflowTaskTriggerEvent" + }, + { + "$ref": "#/$defs/DocumentCreateCheckEvent" + }, + { + "$ref": "#/$defs/DocumentModifyCheckEvent" + }, + { + "$ref": "#/$defs/PartCreateCheckEvent" + }, + { + "$ref": "#/$defs/PartModifyCheckEvent" } ], "title": "Event"