propagation hooks cleanup
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 09 Feb 2010 16:20:17 +0100
changeset 4522 271f201e3735
parent 4521 32402dd2504d
child 4523 d8127c2bd6b5
propagation hooks cleanup
server/hook.py
--- a/server/hook.py	Tue Feb 09 16:20:01 2010 +0100
+++ b/server/hook.py	Tue Feb 09 16:20:17 2010 +0100
@@ -238,7 +238,13 @@
 # base classes for relation propagation ########################################
 
 class PropagateSubjectRelationHook(Hook):
-    """propagate permissions and nosy list when new entity are added"""
+    """propagate some `main_rtype` relation on entities linked as object of
+    `subject_relations` or as subject of `object_relations` (the watched
+    relations).
+
+    This hook ensure that when one of the watched relation is added, the
+    `main_rtype` relation is added to the target entity of the relation.
+    """
     events = ('after_add_relation',)
 
     # to set in concrete class
@@ -247,9 +253,10 @@
     object_relations = None
 
     def __call__(self):
+        assert self.main_rtype
         for eid in (self.eidfrom, self.eidto):
             etype = self._cw.describe(eid)[0]
-            if not self._cw.vreg.schema.eschema(etype).has_subject_relation(self.main_rtype):
+            if self.main_rtype not in self._cw.vreg.schema.eschema(etype).subjrels:
                 return
         if self.rtype in self.subject_relations:
             meid, seid = self.eidfrom, self.eidto
@@ -263,11 +270,12 @@
 
 
 class PropagateSubjectRelationAddHook(Hook):
-    """propagate on existing entities when a permission or nosy list is added"""
+    """propagate to entities at the end of watched relations when a `main_rtype`
+    relation is added
+    """
     events = ('after_add_relation',)
 
     # to set in concrete class
-    main_rtype = None
     subject_relations = None
     object_relations = None
 
@@ -287,11 +295,12 @@
 
 
 class PropagateSubjectRelationDelHook(Hook):
-    """propagate on existing entities when a permission is deleted"""
+    """propagate to entities at the end of watched relations when a `main_rtype`
+    relation is deleted
+    """
     events = ('after_delete_relation',)
 
     # to set in concrete class
-    main_rtype = None
     subject_relations = None
     object_relations = None