Skip to content

Commit

Permalink
Prevent adding nodes or branches to published graphs archesproject#9864
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Aug 4, 2023
1 parent 2ec3ef4 commit 73f7a40
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
13 changes: 12 additions & 1 deletion arches/app/models/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,12 @@ def append_node(self, nodeid=None):
nodeToAppendTo = self.nodes[uuid.UUID(str(nodeid))] if nodeid else self.root
card = None

if self.publication:
raise GraphValidationError(
_("Please unpublish your graph before adding a node."),
1012,
)

if not settings.OVERRIDE_RESOURCE_MODEL_LOCK:
tile_count = models.TileModel.objects.filter(nodegroup_id=nodeToAppendTo.nodegroup_id).count()
if tile_count > 0:
Expand Down Expand Up @@ -1049,7 +1055,7 @@ def traverse_tree(tree):

def can_append(self, graphToAppend, nodeToAppendTo):
"""
can_append - test to see whether or not a graph can be appened to this graph at a specific location
can_append - test to see whether or not a graph can be appended to this graph at a specific location
returns true if the graph can be appended, false otherwise
Expand All @@ -1060,6 +1066,11 @@ def can_append(self, graphToAppend, nodeToAppendTo):
"""

found = False
if graphToAppend.publication:
raise GraphValidationError(
_("Please unpublish your graph before adding a branch."),
1012,
)
if self.ontology is not None and graphToAppend.ontology is None:
raise GraphValidationError(_("The graph you wish to append needs to define an ontology"))

Expand Down
14 changes: 14 additions & 0 deletions tests/models/graph_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"""

import os, json, uuid
from django.contrib.auth.models import User
from django.core import management
from tests import test_settings
from tests.base_test import ArchesTestCase
Expand Down Expand Up @@ -1067,3 +1068,16 @@ def test_appending_a_branch_with_an_invalid_ontology_class(self):

with self.assertRaises(GraphValidationError) as cm:
graph.save()

def test_appending_to_published_graph(self):
graph = Graph.objects.get(node=self.rootNode)
admin = User.objects.get(username="admin")
graph.publish(user=admin)
self.addCleanup(graph.unpublish)

with self.assertRaises(GraphValidationError) as cm:
graph.append_node()
self.assertEqual(cm.exception.code, 1012)
with self.assertRaises(GraphValidationError) as cm:
graph.append_branch("http://www.nasa.gov/", graphid=graph.graphid)
self.assertEqual(cm.exception.code, 1012)

0 comments on commit 73f7a40

Please sign in to comment.