1919 ReadAutomationNodeOperationType ,
2020 UpdateAutomationNodeOperationType ,
2121)
22- from baserow .contrib .automation .nodes .registries import automation_node_type_registry
22+ from baserow .contrib .automation .nodes .registries import (
23+ ReplaceAutomationNodeTrashOperationType ,
24+ automation_node_type_registry ,
25+ )
2326from baserow .contrib .automation .nodes .signals import (
2427 automation_node_created ,
2528 automation_node_deleted ,
29+ automation_node_replaced ,
2630 automation_node_updated ,
2731 automation_nodes_reordered ,
2832)
@@ -186,12 +190,20 @@ def update_node(
186190
187191 return updated_node
188192
189- def delete_node (self , user : AbstractUser , node_id : int ) -> AutomationNode :
193+ def delete_node (
194+ self ,
195+ user : AbstractUser ,
196+ node_id : int ,
197+ trash_operation_type : Optional [str ] = None ,
198+ ) -> AutomationNode :
190199 """
191200 Deletes the specified automation node.
192201
193202 :param user: The user trying to delete the node.
194203 :param node_id: The ID of the node to delete.
204+ :param trash_operation_type: The trash operation type to use when trashing
205+ the node.
206+ :return: The deleted node.
195207 :raises AutomationTriggerModificationDisallowed: If the node is a trigger.
196208 """
197209
@@ -205,15 +217,22 @@ def delete_node(self, user: AbstractUser, node_id: int) -> AutomationNode:
205217 )
206218
207219 automation = node .workflow .automation
208- TrashHandler .trash (user , automation .workspace , automation , node )
209-
210- automation_node_deleted .send (
211- self ,
212- workflow = node .workflow ,
213- node_id = node .id ,
214- user = user ,
220+ trash_entry = TrashHandler .trash (
221+ user ,
222+ automation .workspace ,
223+ automation ,
224+ node ,
225+ trash_operation_type = trash_operation_type ,
215226 )
216227
228+ if trash_entry .get_operation_type ().send_post_trash_deleted_signal :
229+ automation_node_deleted .send (
230+ self ,
231+ workflow = node .workflow ,
232+ node_id = node .id ,
233+ user = user ,
234+ )
235+
217236 return node
218237
219238 def order_nodes (
@@ -331,6 +350,7 @@ def replace_node(
331350 workflow = node .workflow ,
332351 before = node ,
333352 order = node .order ,
353+ previous_node_id = node .previous_node_id ,
334354 previous_node_output = node .previous_node_output ,
335355 ** prepared_values ,
336356 )
@@ -339,8 +359,24 @@ def replace_node(
339359 # After the node creation, the replaced node has changed
340360 node .refresh_from_db ()
341361
362+ # Trash the old node, assigning it a specific trash operation
363+ # type so that we know it was replaced when restoring it.
342364 automation = node .workflow .automation
343- TrashHandler .trash (user , automation .workspace , automation , node )
365+ TrashHandler .trash (
366+ user ,
367+ automation .workspace ,
368+ automation ,
369+ node ,
370+ trash_operation_type = ReplaceAutomationNodeTrashOperationType .type ,
371+ )
372+
373+ automation_node_replaced .send (
374+ self ,
375+ workflow = new_node .workflow ,
376+ restored_node = new_node ,
377+ deleted_node = node ,
378+ user = user ,
379+ )
344380
345381 return ReplacedAutomationNode (
346382 node = new_node ,
0 commit comments