From c635be7308d9d9c78b226819237442a4d3d2d386 Mon Sep 17 00:00:00 2001 From: Dennis Scheiba Date: Fri, 22 Sep 2023 11:36:59 +0200 Subject: [PATCH 1/8] do not allow to delete entry node in backend --- caster-back/gencaster/schema.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/caster-back/gencaster/schema.py b/caster-back/gencaster/schema.py index e13f7d59..1a48997a 100644 --- a/caster-back/gencaster/schema.py +++ b/caster-back/gencaster/schema.py @@ -294,7 +294,15 @@ async def delete_edge(self, info, edge_uuid: uuid.UUID) -> None: async def delete_node(self, info, node_uuid: uuid.UUID) -> None: """Deletes a given :class:`~story_graph.models.Node`.""" await graphql_check_authenticated(info) - await story_graph_models.Node.objects.filter(uuid=node_uuid).adelete() + node = await story_graph_models.Node.objects.aget(uuid=node_uuid) + if node is None: + raise Exception(f"Could not find node {node_uuid}") + if node.is_entry_node: + raise Exception( + f"Node {node_uuid} is an entry node which can not be deleted" + ) + await node.adelete() + return None @strawberry.mutation async def create_script_cells( From 549f6ede93e4a74f9b1aa00c4fae97d34842cf35 Mon Sep 17 00:00:00 2001 From: Vinzenz Aubry Date: Fri, 22 Sep 2023 21:01:49 -0400 Subject: [PATCH 2/8] Prevent delete entry node with editor --- caster-editor/src/components/MenuTabEdit.vue | 24 ++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/caster-editor/src/components/MenuTabEdit.vue b/caster-editor/src/components/MenuTabEdit.vue index 0b143931..3d71c7cf 100644 --- a/caster-editor/src/components/MenuTabEdit.vue +++ b/caster-editor/src/components/MenuTabEdit.vue @@ -28,10 +28,11 @@ import { ElMessage } from "element-plus"; import { storeToRefs } from "pinia"; import { ref, type Ref } from "vue"; import DialogAddNode from "./DialogAddNode.vue"; +import { el } from "element-plus/es/locale"; -export type GraphEdit = Pick; +export type GraphEdit = Pick; -defineProps<{ +const props = defineProps<{ graph: GraphEdit; }>(); @@ -44,6 +45,19 @@ const showAddNodeDialog: Ref = ref(false); const deleteNodeMutation = useDeleteNodeMutation(); const deleteEdgeMutation = useDeleteEdgeMutation(); +const checkIfNodeEntry = (nodeUuid: string) => { + for (let i = 0; i < props.graph.nodes.length; i++) { + if ( + props.graph.nodes[i].uuid === nodeUuid && + props.graph.nodes[i].isEntryNode + ) { + return true; + } else { + return false; + } + } +}; + const removeSelection = async () => { console.log("Removing selection"); @@ -60,6 +74,12 @@ const removeSelection = async () => { }); selectedNodeUUIDs.value.forEach(async (nodeUuid) => { + // compare if to props.graph.nodes and find isEntryNode + if (checkIfNodeEntry(nodeUuid)) { + ElMessage.error(`Cannot delete entry node.`); + return; + } + const { error } = await deleteNodeMutation.executeMutation({ nodeUuid, }); From ee5e01356a07bec9c85436da33b0b78bc31a5929 Mon Sep 17 00:00:00 2001 From: Vinzenz Aubry Date: Fri, 22 Sep 2023 21:02:49 -0400 Subject: [PATCH 3/8] fixed btn coloring for addnode dialog --- caster-editor/src/components/DialogAddNode.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/caster-editor/src/components/DialogAddNode.vue b/caster-editor/src/components/DialogAddNode.vue index 16af314b..bd064dfc 100644 --- a/caster-editor/src/components/DialogAddNode.vue +++ b/caster-editor/src/components/DialogAddNode.vue @@ -71,7 +71,7 @@ const createNode = async () => {