Skip to content
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
32 changes: 26 additions & 6 deletions backend/src/baserow/contrib/automation/api/nodes/errors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from rest_framework.status import HTTP_400_BAD_REQUEST, HTTP_404_NOT_FOUND

ERROR_AUTOMATION_NODE_BEFORE_INVALID = (
"ERROR_AUTOMATION_NODE_BEFORE_INVALID",
ERROR_AUTOMATION_UNEXPECTED_ERROR = (
"ERROR_AUTOMATION_UNEXPECTED_ERROR",
HTTP_400_BAD_REQUEST,
"{e}",
)

ERROR_AUTOMATION_NODE_REFERENCE_NODE_INVALID = (
"ERROR_AUTOMATION_NODE_REFERENCE_NODE_INVALID",
HTTP_400_BAD_REQUEST,
"{e}",
)
Expand All @@ -24,11 +30,25 @@
"{e}",
)

ERROR_AUTOMATION_TRIGGER_NODE_MODIFICATION_DISALLOWED = (
"ERROR_AUTOMATION_TRIGGER_NODE_MODIFICATION_DISALLOWED",

ERROR_AUTOMATION_TRIGGER_MUST_BE_FIRST_NODE = (
"ERROR_AUTOMATION_TRIGGER_MUST_BE_FIRST_NODE",
HTTP_400_BAD_REQUEST,
"This operation is disallowed because a trigger must be the first node of "
"the workflow",
)

ERROR_AUTOMATION_FIRST_NODE_MUST_BE_TRIGGER = (
"ERROR_AUTOMATION_FIRST_NODE_MUST_BE_TRIGGER",
HTTP_400_BAD_REQUEST,
"This operation is disallowed because an action can't be the first node of "
"the workflow",
)

ERROR_AUTOMATION_TRIGGER_ALREADY_EXISTS = (
"ERROR_AUTOMATION_TRIGGER_ALREADY_EXISTS",
HTTP_400_BAD_REQUEST,
"Triggers can not be created, deleted or duplicated, "
"they can only be replaced with a different type.",
"This workflow already has a trigger",
)

ERROR_AUTOMATION_NODE_NOT_DELETABLE = (
Expand Down
62 changes: 27 additions & 35 deletions backend/src/baserow/contrib/automation/api/nodes/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
)
from baserow.contrib.automation.nodes.models import AutomationNode
from baserow.contrib.automation.nodes.registries import automation_node_type_registry
from baserow.contrib.automation.nodes.types import NodePosition


class AutomationNodeSerializer(serializers.ModelSerializer):
Expand All @@ -19,42 +20,25 @@ class AutomationNodeSerializer(serializers.ModelSerializer):
service = PolymorphicServiceSerializer(
help_text="The service associated with this automation node."
)
simulate_until_node = serializers.SerializerMethodField(
help_text="Whether to simulate the dispatching of the node."
)

@extend_schema_field(OpenApiTypes.STR)
def get_type(self, instance):
return automation_node_type_registry.get_by_model(instance.specific_class).type

@extend_schema_field(OpenApiTypes.BOOL)
def get_simulate_until_node(self, instance):
if not instance.workflow.simulate_until_node:
return False

return instance == instance.workflow.simulate_until_node.specific

class Meta:
model = AutomationNode
fields = (
"id",
"label",
"order",
"service",
"workflow",
"type",
"previous_node_id",
"previous_node_output",
"simulate_until_node",
)

extra_kwargs = {
"id": {"read_only": True},
"workflow_id": {"read_only": True},
"type": {"read_only": True},
"previous_node_id": {"read_only": True},
"order": {"read_only": True, "help_text": "Lowest first."},
"simulate_until_node": {"read_only": True},
}


Expand All @@ -64,23 +48,33 @@ class CreateAutomationNodeSerializer(serializers.ModelSerializer):
required=True,
help_text="The type of the automation node",
)
before_id = serializers.IntegerField(
reference_node_id = serializers.IntegerField(
required=False,
help_text="If provided, creates the node before the node with the given id.",
allow_null=True,
help_text="If provided, creates the node relative to the node with the "
"given id.",
)
previous_node_id = serializers.IntegerField(
position = serializers.ChoiceField(
choices=NodePosition.choices,
required=False,
help_text="If provided, creates the node after this given id.",
allow_blank=True,
help_text="The position of the new node relative to the reference node.",
)
previous_node_output = serializers.CharField(
output = serializers.CharField(
required=False,
allow_blank=True,
help_text="The unique ID of the branch this node is an output for.",
)

class Meta:
model = AutomationNode
fields = ("id", "type", "before_id", "previous_node_id", "previous_node_output")
fields = (
"id",
"type",
"reference_node_id",
"position",
"output",
)


class UpdateAutomationNodeSerializer(serializers.ModelSerializer):
Expand All @@ -93,17 +87,9 @@ class Meta:
fields = (
"label",
"service",
"previous_node_output",
)


class OrderAutomationNodesSerializer(serializers.Serializer):
node_ids = serializers.ListField(
child=serializers.IntegerField(),
help_text=("The ids of the nodes in the order they are supposed to be set in."),
)


class ReplaceAutomationNodeSerializer(serializers.Serializer):
new_type = serializers.ChoiceField(
choices=lazy(automation_node_type_registry.get_types, list)(),
Expand All @@ -113,12 +99,18 @@ class ReplaceAutomationNodeSerializer(serializers.Serializer):


class MoveAutomationNodeSerializer(serializers.Serializer):
previous_node_id = serializers.IntegerField(
reference_node_id = serializers.IntegerField(
required=False,
help_text="The ID of the node that should be before the moved node.",
help_text="The reference node.",
)
position = serializers.ChoiceField(
choices=NodePosition.choices,
required=False,
allow_blank=True,
help_text="The new position relative to the reference node.",
)
previous_node_output = serializers.CharField(
output = serializers.CharField(
required=False,
allow_blank=True,
help_text="The output UID of the destination.",
help_text="The new output.",
)
6 changes: 0 additions & 6 deletions backend/src/baserow/contrib/automation/api/nodes/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
AutomationNodeView,
DuplicateAutomationNodeView,
MoveAutomationNodeView,
OrderAutomationNodesView,
ReplaceAutomationNodeView,
SimulateDispatchAutomationNodeView,
)
Expand All @@ -23,11 +22,6 @@
AutomationNodeView.as_view(),
name="item",
),
re_path(
r"workflow/(?P<workflow_id>[0-9]+)/order/$",
OrderAutomationNodesView.as_view(),
name="order",
),
re_path(
r"node/(?P<node_id>[0-9]+)/duplicate/$",
DuplicateAutomationNodeView.as_view(),
Expand Down
Loading
Loading