server/session.py
branch3.5
changeset 2940 db2fb2907389
parent 2874 acdd8d8c2cff
child 2968 0e3460341023
child 3084 096d680c9da2
--- a/server/session.py	Thu Aug 20 19:03:24 2009 +0200
+++ b/server/session.py	Fri Aug 21 08:29:15 2009 +0200
@@ -78,16 +78,43 @@
     def schema(self):
         return self.repo.schema
 
-    def add_relation(self, fromeid, rtype, toeid):
+    def _change_relation(self, cb, fromeid, rtype, toeid):
         if self.is_super_session:
-            self.repo.glob_add_relation(self, fromeid, rtype, toeid)
+            cb(self, fromeid, rtype, toeid)
             return
         self.is_super_session = True
         try:
-            self.repo.glob_add_relation(self, fromeid, rtype, toeid)
+            cb(self, fromeid, rtype, toeid)
         finally:
             self.is_super_session = False
 
+    def add_relation(self, fromeid, rtype, toeid):
+        """provide direct access to the repository method to add a relation.
+
+        This is equivalent to the following rql query:
+
+          SET X rtype Y WHERE X eid  fromeid, T eid toeid
+
+        without read security check but also all the burden of rql execution.
+        You may use this in hooks when you know both eids of the relation you
+        want to add.
+        """
+        self._change_relation(self.repo.glob_add_relation,
+                              fromeid, rtype, toeid)
+    def delete_relation(self, fromeid, rtype, toeid):
+        """provide direct access to the repository method to delete a relation.
+
+        This is equivalent to the following rql query:
+
+          DELETE X rtype Y WHERE X eid  fromeid, T eid toeid
+
+        without read security check but also all the burden of rql execution.
+        You may use this in hooks when you know both eids of the relation you
+        want to delete.
+        """
+        self._change_relation(self.repo.glob_delete_relation,
+                              fromeid, rtype, toeid)
+
     def update_rel_cache_add(self, subject, rtype, object, symetric=False):
         self._update_entity_rel_cache_add(subject, rtype, 'subject', object)
         if symetric: