hooks/email.py
changeset 3293 69c0ba095536
parent 3248 db09803df8b2
parent 2847 c2ee28f4d4b1
child 3376 f5c69485381f
--- a/hooks/email.py	Tue Sep 15 15:01:41 2009 +0200
+++ b/hooks/email.py	Thu Sep 17 15:16:53 2009 +0200
@@ -8,6 +8,7 @@
 __docformat__ = "restructuredtext en"
 
 from cubicweb.server import hook
+from cubicweb.server.repository import ensure_card_respected
 
 class SetUseEmailRelationOp(hook.Operation):
     """delay this operation to commit to avoid conflict with a late rql query
@@ -23,7 +24,12 @@
 
     def precommit_event(self):
         if self.condition():
-            self.session.unsafe_execute(
+            # we've to handle cardinaly by ourselves since we're using unsafe_execute
+            # but use session.execute and not session.unsafe_execute to check we
+            # can change the relation
+            ensure_card_respected(session.execute, session,
+                                  self.fromeid, self.rtype, self.toeid)
+            session.unsafe_execute(
                 'SET X %s Y WHERE X eid %%(x)s, Y eid %%(y)s' % self.rtype,
                 {'x': self.entity.eid, 'y': self.email.eid}, 'x')