Sfoglia il codice sorgente

Fix permissions in model_move (+ test)

Yentl Van Tendeloo 7 anni fa
parent
commit
1184ca24f2
3 ha cambiato i file con 44 aggiunte e 21 eliminazioni
  1. 28 21
      bootstrap/core_algorithm.alc
  2. 14 0
      unit/test_all.py
  3. 2 0
      wrappers/modelverse_SCCD.py

+ 28 - 21
bootstrap/core_algorithm.alc

@@ -1132,28 +1132,35 @@ String function cmd_model_move(source : String, target : String):
 	String source_id
 	String source_id
 	source_id = get_entry_id(source)
 	source_id = get_entry_id(source)
 	if (source_id != ""):
 	if (source_id != ""):
-		if (get_entry_id(target) == ""):
-			// Create folders on path to the target
-			create_folders(current_user_id, get_foldername(target))
-
-			// Change location, first the name
-			instantiate_attribute(core, source_id, "name", target)
-
-			// Now the folder links
-			Element links
-			links = allIncomingAssociationInstances(core, source_id, "contains")
-			while (set_len(links) > 0):
-				model_delete_element(core, set_pop(links))
-			instantiate_link(core, "contains", "", get_entry_id(get_foldername(target)), source_id)
-
-			// Flush caches
-			dict_add(caches["models"], target, caches["models"][source])
-			dict_delete(caches["models"], source)
-
-			// Done
-			return "Success"!
+		if (allow_write(current_user_id, source_id)):
+			if (get_entry_id(target) == ""):
+				// Create folders on path to the target
+				if (element_neq(create_folders(current_user_id, get_foldername(target)), read_root())):
+					if (allow_write(current_user_id, get_entry_id(get_foldername(target)))):
+						// Change location, first the name
+						instantiate_attribute(core, source_id, "name", target)
+
+						// Now the folder links
+						Element links
+						links = allIncomingAssociationInstances(core, source_id, "contains")
+						while (set_len(links) > 0):
+							model_delete_element(core, set_pop(links))
+						instantiate_link(core, "contains", "", get_entry_id(get_foldername(target)), source_id)
+
+						// Flush caches
+						dict_add(caches["models"], target, caches["models"][source])
+						dict_delete(caches["models"], source)
+
+						// Done
+						return "Success"!
+					else:
+						return "Write permission denied to: " + target!
+				else:
+					return "Write permission denied to: " + target!
+			else:
+				return "Model exists: " + target!
 		else:
 		else:
-			return "Model exists: " + target!
+			return "Write permission denied to: " + source!
 	else:
 	else:
 		return "Location not found: " + source!
 		return "Location not found: " + source!
 
 

+ 14 - 0
unit/test_all.py

@@ -344,6 +344,20 @@ class TestModelverse(unittest.TestCase):
         except UnknownLocation:
         except UnknownLocation:
             pass
             pass
 
 
+        # Test if we can move a model we can't write to (i.e., not allowed to remove it)
+        try:
+            model_move("formalisms/ProcessModel", "users/user/test/x")
+            self.fail()
+        except WritePermissionDenied:
+            pass
+
+        # Test if we can move a model to a place we can't write to
+        try:
+            model_move("users/user/test/a", "administration/ProcessModel2")
+            self.fail()
+        except WritePermissionDenied:
+            pass
+
     def test_op_model_delete(self):
     def test_op_model_delete(self):
         # Test basic delete
         # Test basic delete
         model_add("users/user/test/a", "formalisms/SimpleClassDiagrams")
         model_add("users/user/test/a", "formalisms/SimpleClassDiagrams")

+ 2 - 0
wrappers/modelverse_SCCD.py

@@ -1,6 +1,8 @@
 """
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
 
+Date:   Mon Jun 11 09:14:38 2018
+
 Model author: Yentl Van Tendeloo
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server
 Model name:   MvK Server
 Model description:
 Model description: