[Erp5-report] r38369 romain - /erp5/trunk/products/ERP5/Document/Person.py

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Sep 14 16:27:45 CEST 2010


Author: romain
Date: Tue Sep 14 16:27:42 2010
New Revision: 38369

URL: http://svn.erp5.org?rev=38369&view=rev
Log:
Prevent that the same person's reference to be set on 2 different persons:
 - in the same transaction
 - when one of the person is not indexed yet
 - in 2 concurrent transactions

Modified:
    erp5/trunk/products/ERP5/Document/Person.py

Modified: erp5/trunk/products/ERP5/Document/Person.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/Person.py?rev=38369&r1=38368&r2=38369&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/Person.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/Person.py [utf8] Tue Sep 14 16:27:42 2010
@@ -36,6 +36,7 @@ from Products.CMFCore.utils import getTo
 from Products.ERP5Type import Permissions, PropertySheet, interfaces
 from Products.ERP5Type.XMLObject import XMLObject
 from Products.ERP5.mixin.encrypted_password import EncryptedPasswordMixin
+from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
 
 try:
   from Products import PluggableAuthService
@@ -170,6 +171,10 @@ class Person(EncryptedPasswordMixin, XML
           PAS _AND_ ERP5UserManager are used
       """
       if value:
+        # Encode reference to hex to prevent uppercase/lowercase conflict in
+        # activity table (when calling countMessageWithTag)
+        tag = 'Person_setReference_%s' % value.encode('hex')
+        # Check that there no existing user
         acl_users = getToolByName(self, 'acl_users')
         if PluggableAuthService is not None and isinstance(acl_users,
               PluggableAuthService.PluggableAuthService.PluggableAuthService):
@@ -182,8 +187,27 @@ class Person(EncryptedPasswordMixin, XML
               if len(user_list) > 0:
                 raise RuntimeError, 'user id %s already exist' % (value,)
               break
+        # Check that there is no reindexation related to reference indexation
+        portal_activities = getToolByName(self, 'portal_activities')
+        if portal_activities.countMessageWithTag(tag):
+          raise RuntimeError, 'user id %s already exist' % (value,)
+
+        parent_value = self.getParentValue()
+        # Prevent concurrent transaction to set the same reference on 2
+        # different persons
+        parent_value.serialize()
+        # Prevent to set the same reference on 2 different persons during the
+        # same transaction
+        transactional_variable = getTransactionalVariable(None)
+        if tag in transactional_variable:
+          raise RuntimeError, 'user id %s already exist' % (value,)
+        else:
+          transactional_variable[tag] = None
+      else:
+        tag = None
+
       self._setReference(value)
-      self.reindexObject()
+      self.reindexObject(activate_kw={'tag': tag})
       # invalid the cache for ERP5Security
       portal_caches = getToolByName(self.getPortalObject(), 'portal_caches')
       portal_caches.clearCache(cache_factory_list=('erp5_content_short', ))




More information about the Erp5-report mailing list