Browse Source

First patches towards actual permission management

Yentl Van Tendeloo 7 years ago
parent
commit
81a0880fbb
4 changed files with 109 additions and 126 deletions
  1. 45 81
      bootstrap/99_core.mvc
  2. 24 19
      bootstrap/core_algorithm.alc
  3. 39 25
      unit/test_all.py
  4. 1 1
      wrappers/modelverse_SCCD.py

+ 45 - 81
bootstrap/99_core.mvc

@@ -79,84 +79,58 @@ CF core {
             name = "type mappings"
             name = "type mappings"
             permissions = "221"
             permissions = "221"
 
 
-            Folder tm_formalisms {
-                name = "type mappings/formalisms"
-                permissions = "110"
-
-                TypeMapping TM_SimpleClassDiagrams {
-                    name = "type mappings/formalisms/SimpleClassDiagrams"
-                    location = "models/SimpleClassDiagrams/types"
-                    permissions = "221"
-                }
-
-                TypeMapping TM_TypeMapping {
-                    name = "type mappings/formalisms/TypeMapping"
-                    location = "models/TypeMapping/types"
-                    permissions = "221"
-                }
-
-                TypeMapping TM_Tracability{
-                    name = "type mappings/formalisms/Tracability"
-                    location = "models/Tracability/types"
-                    permissions = "221"
-                }
-
-                TypeMapping TM_ProcessModel {
-                    name = "type mappings/formalisms/ProcessModel"
-                    location = "models/ProcessModel/types"
-                    permissions = "221"
-                }
-
-                TypeMapping TM_ActionLanguage {
-                    name = "type mappings/formalisms/ActionLanguage"
-                    location = "models/ActionLanguage/types"
-                    permissions = "221"
-                }
-
-                TypeMapping TM_ManualOperation {
-                    name = "type mappings/formalisms/ManualOperation"
-                    location = "models/ManualOperation/types"
-                    permissions = "221"
-                }
-
-                TypeMapping TM_Bottom {
-                    name = "type mappings/formalisms/Bottom"
-                    location = "models/Bottom/types"
-                    permissions = "221"
-                }
+            TypeMapping TM_SimpleClassDiagrams {
+                name = "type mappings/1"
+                location = "models/SimpleClassDiagrams/types"
+                permissions = "221"
+            }
+
+            TypeMapping TM_TypeMapping {
+                name = "type mappings/2"
+                location = "models/TypeMapping/types"
+                permissions = "221"
+            }
+
+            TypeMapping TM_Tracability{
+                name = "type mappings/3"
+                location = "models/Tracability/types"
+                permissions = "221"
+            }
+
+            TypeMapping TM_ProcessModel {
+                name = "type mappings/4"
+                location = "models/ProcessModel/types"
+                permissions = "221"
+            }
 
 
+            TypeMapping TM_ActionLanguage {
+                name = "type mappings/5"
+                location = "models/ActionLanguage/types"
+                permissions = "221"
             }
             }
 
 
-            Folder tm_models {
-                name = "type mappings/models"
-                permissions = "110"
+            TypeMapping TM_ManualOperation {
+                name = "type mappings/6"
+                location = "models/ManualOperation/types"
+                permissions = "221"
             }
             }
 
 
-            Folder tm_administration {
-                name = "type mappings/administration"
-                permissions = "100"
-
-                TypeMapping TM_Core {
-                    name = "type mappings/administration/core"
-                    location = "models/core/types"
-                    permissions = "220"
-                }
-
-                TypeMapping TM_CoreFormalism {
-                    name = "type mappings/administration/CoreFormalism"
-                    location = "models/CoreFormalism/types"
-                    permissions = "221"
-                }
+            TypeMapping TM_Bottom {
+                name = "type mappings/7"
+                location = "models/Bottom/types"
+                permissions = "221"
             }
             }
 
 
-            Folder tm_users {
-                name = "type mapping/users"
-                permissions = "110"
+            TypeMapping TM_Core {
+                name = "type mappings/8"
+                location = "models/core/types"
+                permissions = "220"
+            }
 
 
-                Folder tm_users_admin {
-                    name = "type mapping/users/admin"
-                    permissions = "100"
-                }
+            TypeMapping TM_CoreFormalism {
+                name = "type mappings/9"
+                location = "models/CoreFormalism/types"
+                permissions = "221"
             }
             }
         }
         }
 
 
@@ -172,7 +146,7 @@ CF core {
 
 
         Folder administration {
         Folder administration {
             name = "administration"
             name = "administration"
-            permissions = "110"
+            permissions = "221"
 
 
             Model CoreFormalism {
             Model CoreFormalism {
                 name = "administration/CoreFormalism"
                 name = "administration/CoreFormalism"
@@ -205,7 +179,6 @@ CF core {
     group (users_admin, nobody) {}
     group (users_admin, nobody) {}
 
 
     group (typemappings, admin_group) {}
     group (typemappings, admin_group) {}
-    group (tm_formalisms, admin_group) {}
     group (TM_SimpleClassDiagrams, admin_group) {}
     group (TM_SimpleClassDiagrams, admin_group) {}
     group (TM_TypeMapping, admin_group) {}
     group (TM_TypeMapping, admin_group) {}
     group (TM_Tracability, admin_group) {}
     group (TM_Tracability, admin_group) {}
@@ -213,12 +186,8 @@ CF core {
     group (TM_ActionLanguage, admin_group) {}
     group (TM_ActionLanguage, admin_group) {}
     group (TM_Bottom, admin_group) {}
     group (TM_Bottom, admin_group) {}
     group (TM_ManualOperation, admin_group) {}
     group (TM_ManualOperation, admin_group) {}
-    group (tm_models, admin_group) {}
-    group (tm_administration, admin_group) {}
     group (TM_CoreFormalism, admin_group) {}
     group (TM_CoreFormalism, admin_group) {}
     group (TM_Core, admin_group) {}
     group (TM_Core, admin_group) {}
-    group (tm_users, admin_group) {}
-    group (tm_users_admin, admin_group) {}
 
 
     owner (root, admin_user) {}
     owner (root, admin_user) {}
     owner (formalisms, admin_user) {}
     owner (formalisms, admin_user) {}
@@ -237,7 +206,6 @@ CF core {
     owner (users_admin, admin_user) {}
     owner (users_admin, admin_user) {}
 
 
     owner (typemappings, admin_user) {}
     owner (typemappings, admin_user) {}
-    owner (tm_formalisms, admin_user) {}
     owner (TM_SimpleClassDiagrams, admin_user) {}
     owner (TM_SimpleClassDiagrams, admin_user) {}
     owner (TM_TypeMapping, admin_user) {}
     owner (TM_TypeMapping, admin_user) {}
     owner (TM_Tracability, admin_user) {}
     owner (TM_Tracability, admin_user) {}
@@ -245,12 +213,8 @@ CF core {
     owner (TM_ActionLanguage, admin_user) {}
     owner (TM_ActionLanguage, admin_user) {}
     owner (TM_ManualOperation, admin_user) {}
     owner (TM_ManualOperation, admin_user) {}
     owner (TM_Bottom, admin_user) {}
     owner (TM_Bottom, admin_user) {}
-    owner (tm_models, admin_user) {}
-    owner (tm_administration, admin_user) {}
     owner (TM_CoreFormalism, admin_user) {}
     owner (TM_CoreFormalism, admin_user) {}
     owner (TM_Core, admin_user) {}
     owner (TM_Core, admin_user) {}
-    owner (tm_users, admin_user) {}
-    owner (tm_users_admin, admin_user) {}
 
 
     instanceOf inst_SCD (SimpleClassDiagrams, SimpleClassDiagrams) {}
     instanceOf inst_SCD (SimpleClassDiagrams, SimpleClassDiagrams) {}
     instanceOf inst_TM (TypeMapping, SimpleClassDiagrams) {}
     instanceOf inst_TM (TypeMapping, SimpleClassDiagrams) {}

+ 24 - 19
bootstrap/core_algorithm.alc

@@ -228,6 +228,22 @@ Void function new_task():
 	// Load in a hard-reference to the previously created model
 	// Load in a hard-reference to the previously created model
 	core = import_node(core_model_location)
 	core = import_node(core_model_location)
 
 
+	caches = dict_create()
+	dict_add_fast(caches, "models", dict_create())
+	dict_add_fast(caches, "users", dict_create())
+	dict_add_fast(caches, "full_name", dict_create())
+
+	// Find root element
+	Element elems
+	String elem
+	elems = allInstances(core, "Folder")
+	while (set_len(elems) > 0):
+		elem = set_pop(elems)
+		if (value_eq(read_attribute(core, elem, "name"), "")):
+			if (set_len(allIncomingAssociationInstances(core, elem, "contains")) == 0):
+				dict_add_fast(caches, "root", elem)
+				break!
+
 	while (True):
 	while (True):
 		output("Log on as which user?")
 		output("Log on as which user?")
 		username = input()
 		username = input()
@@ -247,6 +263,11 @@ Void function new_task():
 			if (password == hash(input())):
 			if (password == hash(input())):
 				output("Passwords match!")
 				output("Passwords match!")
 				instantiate_attribute(core, user_id, "password", password)
 				instantiate_attribute(core, user_id, "password", password)
+
+				// Now create a folder for this user's models!
+				current_user_id = get_user_id("admin")
+				create_folders(user_id, "users/" + username)
+				current_user_id = user_id
 				break!
 				break!
 			else:
 			else:
 				output("Not the same password!")
 				output("Not the same password!")
@@ -361,7 +382,7 @@ String function create_folders(user_id : String, folder_name : String):
 			cummul = string_join(cummul + "/", elem)
 			cummul = string_join(cummul + "/", elem)
 
 
 		if (get_entry_id(cummul) == ""):
 		if (get_entry_id(cummul) == ""):
-			if (allow_write(user_id, prev)):
+			if (allow_write(current_user_id, prev)):
 				// Element does not exist yet!
 				// Element does not exist yet!
 				new_entry = instantiate_node(core, "Folder", "")
 				new_entry = instantiate_node(core, "Folder", "")
 				instantiate_attribute(core, new_entry, "name", cummul)
 				instantiate_attribute(core, new_entry, "name", cummul)
@@ -391,15 +412,15 @@ String function store_entry(model_id : String, full_name : String, user_id : Str
 String function export_typing(model : Element, name : String):
 String function export_typing(model : Element, name : String):
 	String result
 	String result
 	result = instantiate_node(core, "TypeMapping", "")
 	result = instantiate_node(core, "TypeMapping", "")
-	name = "type mappings/" + name
 
 
 	// Create type mapping model
 	// Create type mapping model
 	String location
 	String location
 	location = "type mappings/" + cast_id(get_type_mapping(model))
 	location = "type mappings/" + cast_id(get_type_mapping(model))
 	export_node(location, get_type_mapping(model))
 	export_node(location, get_type_mapping(model))
+	name = location
 
 
 	String instance_of
 	String instance_of
-	name = store_entry(result, name, get_user_id("admin"))
+	name = store_entry(result, name, current_user_id)
 	instantiate_attribute(core, result, "name", name)
 	instantiate_attribute(core, result, "name", name)
 	instantiate_attribute(core, result, "location", location)
 	instantiate_attribute(core, result, "location", location)
 	instantiate_attribute(core, result, "permissions", "200")
 	instantiate_attribute(core, result, "permissions", "200")
@@ -2387,22 +2408,6 @@ Void function user_function_skip_init(user_id : String):
 
 
 	current_user_id = user_id
 	current_user_id = user_id
 
 
-	caches = dict_create()
-	dict_add_fast(caches, "models", dict_create())
-	dict_add_fast(caches, "users", dict_create())
-	dict_add_fast(caches, "full_name", dict_create())
-
-	// Find root element
-	Element elems
-	String elem
-	elems = allInstances(core, "Folder")
-	while (set_len(elems) > 0):
-		elem = set_pop(elems)
-		if (value_eq(read_attribute(core, elem, "name"), "")):
-			if (set_len(allIncomingAssociationInstances(core, elem, "contains")) == 0):
-				dict_add_fast(caches, "root", elem)
-				break!
-
 	output("Welcome to the Model Management Interface v2.0!")
 	output("Welcome to the Model Management Interface v2.0!")
 	output("Use the 'help' command for a list of possible commands")
 	output("Use the 'help' command for a list of possible commands")
 
 

+ 39 - 25
unit/test_all.py

@@ -26,22 +26,23 @@ model_hierarchy = \
             "administration/": {"core": {},
             "administration/": {"core": {},
                                 "CoreFormalism": {},
                                 "CoreFormalism": {},
                                },
                                },
-            "users/": {"admin/": {}
+            "users/": {"admin/": {},
+                       "LoLA/": {},
+                       "HUTN/": {},
+                       "files/": {},
+                       "DEVS/": {},
+                       "DEVS_batch/": {},
+                       "JSON/": {},
                       },
                       },
-            "type mappings/": {"formalisms/": {"SimpleClassDiagrams": {},
-                                               "TypeMapping": {},
-                                               "Tracability": {},
-                                               "ProcessModel": {},
-                                               "ActionLanguage": {},
-                                               "ManualOperation": {},
-                                               "Bottom": {},
-                                              },
-                               "models/": {},
-                               "administration/": {"core": {},
-                                                   "CoreFormalism": {},
-                                                  },
-                               "users/": {"admin/": {}
-                                         },
+            "type mappings/": {"1": {},
+                               "2": {},
+                               "3": {},
+                               "4": {},
+                               "5": {},
+                               "6": {},
+                               "7": {},
+                               "8": {},
+                               "9": {},
                               },
                               },
             }
             }
 
 
@@ -51,9 +52,6 @@ def verify_clean():
     compare_locations("formalisms", set())
     compare_locations("formalisms", set())
     compare_locations("administration", set())
     compare_locations("administration", set())
     compare_locations("type mappings", set())
     compare_locations("type mappings", set())
-    compare_locations("type mappings/models", set())
-    compare_locations("type mappings/formalisms", set())
-    compare_locations("type mappings/administration", set())
 
 
 def get_model_list(location):
 def get_model_list(location):
     try:
     try:
@@ -87,7 +85,7 @@ class TestModelverse(unittest.TestCase):
     def setUpClass(self):
     def setUpClass(self):
         TestModelverse.proc, address = start_mvc()
         TestModelverse.proc, address = start_mvc()
         init(address)
         init(address)
-        login("admin", "admin")
+        login("user", "user")
 
 
     @classmethod
     @classmethod
     def tearDownClass(self):
     def tearDownClass(self):
@@ -98,16 +96,13 @@ class TestModelverse(unittest.TestCase):
 
 
     def setUp(self):
     def setUp(self):
         verify_clean()
         verify_clean()
-        folder_create("test")
-        folder_create("type mappings/test")
+        folder_create("users/user/test")
 
 
     def tearDown(self):
     def tearDown(self):
-        model_delete("test")
-        model_delete("type mappings/test")
+        model_delete("users/user/test")
         verify_clean()
         verify_clean()
         pass
         pass
 
 
-    """
     def test_op_model_list(self):
     def test_op_model_list(self):
         assert model_list("") == set(["formalisms/",
         assert model_list("") == set(["formalisms/",
                                       "models/",
                                       "models/",
@@ -195,7 +190,7 @@ class TestModelverse(unittest.TestCase):
                                                      ("ManualOperation", "admin", "admin", "221"),
                                                      ("ManualOperation", "admin", "admin", "221"),
                                                      ("Bottom", "admin", "admin", "221"),
                                                      ("Bottom", "admin", "admin", "221"),
                                                     ])
                                                     ])
-        permission_modify("formalisms/SimpleClassDiagrams", "000")
+        assert permission_modify("formalisms/SimpleClassDiagrams", "000") == None
         assert model_list_full("formalisms") == set([("SimpleClassDiagrams", "admin", "admin", "000"),
         assert model_list_full("formalisms") == set([("SimpleClassDiagrams", "admin", "admin", "000"),
                                                      ("ActionLanguage", "admin", "admin", "221"),
                                                      ("ActionLanguage", "admin", "admin", "221"),
                                                      ("TypeMapping", "admin", "admin", "221"),
                                                      ("TypeMapping", "admin", "admin", "221"),
@@ -204,7 +199,26 @@ class TestModelverse(unittest.TestCase):
                                                      ("ManualOperation", "admin", "admin", "221"),
                                                      ("ManualOperation", "admin", "admin", "221"),
                                                      ("Bottom", "admin", "admin", "221"),
                                                      ("Bottom", "admin", "admin", "221"),
                                                     ])
                                                     ])
+        assert permission_modify("formalisms/SimpleClassDiagrams", "222") == None
+        assert model_list_full("formalisms") == set([("SimpleClassDiagrams", "admin", "admin", "222"),
+                                                     ("ActionLanguage", "admin", "admin", "221"),
+                                                     ("TypeMapping", "admin", "admin", "221"),
+                                                     ("Tracability", "admin", "admin", "221"),
+                                                     ("ProcessModel", "admin", "admin", "221"),
+                                                     ("ManualOperation", "admin", "admin", "221"),
+                                                     ("Bottom", "admin", "admin", "221"),
+                                                    ])
+        assert permission_modify("formalisms/", "000") == None
+        assert model_list_full("formalisms") == set([("SimpleClassDiagrams", "admin", "admin", "222"),
+                                                     ("ActionLanguage", "admin", "admin", "221"),
+                                                     ("TypeMapping", "admin", "admin", "221"),
+                                                     ("Tracability", "admin", "admin", "221"),
+                                                     ("ProcessModel", "admin", "admin", "221"),
+                                                     ("ManualOperation", "admin", "admin", "221"),
+                                                     ("Bottom", "admin", "admin", "221"),
+                                                    ])
 
 
+    """
     def test_op_model_add(self):
     def test_op_model_add(self):
     def test_op_model_move(self):
     def test_op_model_move(self):
     def test_op_model_delete(self):
     def test_op_model_delete(self):

+ 1 - 1
wrappers/modelverse_SCCD.py

@@ -1,7 +1,7 @@
 """
 """
 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:   Wed Jun  6 14:55:24 2018
+Date:   Wed Jun  6 16:47:12 2018
 
 
 Model author: Yentl Van Tendeloo
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server
 Model name:   MvK Server