瀏覽代碼

Added "read_permissions" operation to retrieve actual permissions of a user

Yentl Van Tendeloo 7 年之前
父節點
當前提交
ba5fb571d4
共有 5 個文件被更改,包括 263 次插入186 次删除
  1. 14 0
      bootstrap/core_algorithm.alc
  2. 12 7
      unit/test_all.py
  3. 24 0
      wrappers/classes/modelverse.xml
  4. 4 4
      wrappers/modelverse.py
  5. 209 175
      wrappers/modelverse_SCCD.py

+ 14 - 0
bootstrap/core_algorithm.alc

@@ -1724,6 +1724,18 @@ String function cmd_model_delete(model_name : String):
 	else:
 		return "Model not found: " + model_name!
 
+String function cmd_read_permissions(location : String):
+	if (get_entry_id(location) != ""):
+		String result
+		result = "Success: "
+		if (allow_read(current_user_id, get_entry_id(location))):
+			result = result + "R"
+		if (allow_write(current_user_id, get_entry_id(location))):
+			result = result + "W"
+		return result!
+	else:
+		return "Location not found: " + location!
+
 String function cmd_model_list(location : String):
 	// List all models
 	if (get_entry_id(location) != ""):
@@ -2463,6 +2475,8 @@ Void function user_function_skip_init(user_id : String):
 			output(cmd_model_list(single_input("Location?")))
 		elif (cmd == "model_list_full"):
 			output(cmd_model_list_full(single_input("Location?")))
+		elif (cmd == "read_permissions"):
+			output(cmd_read_permissions(single_input("Location?")))
 		elif (cmd == "transformation_add_MANUAL"):
 			output(cmd_transformation_add_MANUAL(dict_input("Source models?"), dict_input("Target models?"), single_input("Operation name?")))
 		elif (cmd == "transformation_add_AL"):

+ 12 - 7
unit/test_all.py

@@ -2569,21 +2569,25 @@ class TestModelverse(unittest.TestCase):
         except UnknownGroup:
             pass
 
-    """
+        # Delete all groups again
+        self.do_as_user("admin", group_delete, [group_name_1])
+        self.do_as_user("admin", group_delete, [group_name_2])
+        self.do_as_user("admin", group_delete, [group_name_3])
+
     def do_create_user(self, name):
-        user_logout()
-        login(name, name)
-        user_logout()
-        login("user", "user")
+        self.do_as_user(name, lambda : 1, [])
 
     def do_test_permission(self, model, expected_permissions):
         for user, permission in expected_permissions.items():
             read = permission != "N"
             write = permission == "W"
 
-            assert can_read(model, user) == read
-            assert can_write(model, user) == write
+            actual = self.do_as_user(user, read_permissions, [model])
 
+            assert ("R" in actual) == read
+            assert ("W" in actual) == write
+
+    """
     def test_op_permission_owner(self):
         model_add("users/user/test/a", "formalisms/SimpleClassDiagrams")
         group_create("users")
@@ -2614,6 +2618,7 @@ class TestModelverse(unittest.TestCase):
     def test_op_group_owner_add(self):
     def test_op_group_owner_delete(self):
     def test_op_group_kick(self):
+    def test_op_read_permissions(self):
     def test_op_conformance_delete(self):
     def test_op_conformance_add(self):
     """

+ 24 - 0
wrappers/classes/modelverse.xml

@@ -317,6 +317,24 @@
                         </transition>
                     </state>
 
+                    <state id="read_permissions">
+                        <onentry>
+                            <raise event="request">
+                                <parameter expr="['read_permissions', self.parameters[0]]"/>
+                            </raise>
+                        </onentry>
+
+                        <transition cond="self.expect_response_partial('Success: ', pop=False)" target="../../wait_for_action/history">
+                            <script>
+                                print("Got: " + str(self.responses[0]))
+                                print("Split: " + str(self.split_response(self.responses[0])))
+                            </script>
+                            <raise event="result">
+                                <parameter expr="self.split_response(self.responses.pop(0))[0]"/>
+                            </raise>
+                        </transition>
+                    </state>
+
                     <state id="model_add" initial="send_metadata">
                         <state id="send_metadata">
                             <onentry>
@@ -1613,6 +1631,12 @@
                             </script>
                         </transition>
 
+                        <transition cond="self.expect_action('read_permissions')" target="../../operations/read_permissions">
+                            <script>
+                                self.load_action()
+                            </script>
+                        </transition>
+
                         <transition cond="self.expect_action('model_move')" target="../../operations/model_move">
                             <script>
                                 self.load_action()

+ 4 - 4
wrappers/modelverse.py

@@ -441,10 +441,6 @@ def types(model_name):
     INPUT("types", [model_name])
     return OUTPUT()
 
-def types_full(model_name):
-    INPUT("types_full", [model_name])
-    return OUTPUT()
-
 def read_info(model_name, ID):
     INPUT("read_info", [model_name, ID])
     return OUTPUT()
@@ -525,6 +521,10 @@ def all_instances(model_name, type_name):
     INPUT("all_instances", [model_name, type_name])
     return OUTPUT()
 
+def read_permissions(model_name):
+    INPUT("read_permissions", [model_name])
+    return OUTPUT()
+
 def process_execute(process_name, model_mapping, callbacks={}):
     # for all callbacks to SCs, start up the output port already
     sc_ports = {}

文件差異過大導致無法顯示
+ 209 - 175
wrappers/modelverse_SCCD.py