Browse Source

Add folder test in model_add

Yentl Van Tendeloo 7 years ago
parent
commit
2caa45ca0a
1 changed files with 20 additions and 17 deletions
  1. 20 17
      bootstrap/core_algorithm.alc

+ 20 - 17
bootstrap/core_algorithm.alc

@@ -1100,28 +1100,31 @@ String function cmd_model_add(type : String, name : String, code : String):
 	if (type_id != ""):
 		// Type exists
 		if (allow_read(current_user_id, type_id)):
-			// And is readable
-			mm = get_full_model(type_id, get_entry_id("formalisms/SimpleClassDiagrams"))
-			if (element_neq(mm, read_root())):
-				if (element_neq(create_folders(current_user_id, get_foldername(name)), read_root())):
-					if (allow_write(current_user_id, get_entry_id(get_foldername(name)))):
-						if (get_entry_id(name) == ""):
-							// Model doesn't exist yet
-							new_model = compile_model(code, mm)
-
-							if (is_physical_string(new_model)):
-								return "Compilation error: " + cast_string(new_model)!
-
-							model_create(new_model, name, type_id, "Model")
-							return "Success"!
+			if (read_type(core, type_id) != "Folder"):
+				// And is readable
+				mm = get_full_model(type_id, get_entry_id("formalisms/SimpleClassDiagrams"))
+				if (element_neq(mm, read_root())):
+					if (element_neq(create_folders(current_user_id, get_foldername(name)), read_root())):
+						if (allow_write(current_user_id, get_entry_id(get_foldername(name)))):
+							if (get_entry_id(name) == ""):
+								// Model doesn't exist yet
+								new_model = compile_model(code, mm)
+
+								if (is_physical_string(new_model)):
+									return "Compilation error: " + cast_string(new_model)!
+
+								model_create(new_model, name, type_id, "Model")
+								return "Success"!
+							else:
+								return "Model exists: " + name!
 						else:
-							return "Model exists: " + name!
+							return "Write permission denied to: " + name!
 					else:
 						return "Write permission denied to: " + name!
 				else:
-					return "Write permission denied to: " + name!
+					return "Type cannot be typed as formalisms/SimpleClassDiagrams: " + type!
 			else:
-				return "Type cannot be typed as formalisms/SimpleClassDiagrams: " + type!
+				return "Not a model: " + type!
 		else:
 			return "Read permission denied to: " + type!
 	else: