From 24ba1506f8ee8134c5527081c7e1245f00585b90 Mon Sep 17 00:00:00 2001
From: Julien Muchembled <jm@nexedi.com>
Date: Sun, 31 Oct 2010 15:07:35 +0000
Subject: [PATCH] Fix removal of reference on persons

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39724 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Document/Person.py                | 7 +++----
 product/ERP5Security/tests/testERP5Security.py | 4 ++--
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/product/ERP5/Document/Person.py b/product/ERP5/Document/Person.py
index efe3abf9e0b..3cef1129d4f 100644
--- a/product/ERP5/Document/Person.py
+++ b/product/ERP5/Document/Person.py
@@ -170,10 +170,11 @@ class Person(EncryptedPasswordMixin, XMLObject):
         - we want to prevent duplicated user ids, but only when
           PAS _AND_ ERP5UserManager are used
       """
+      activate_kw = {}
       if value:
         # Encode reference to hex to prevent uppercase/lowercase conflict in
         # activity table (when calling countMessageWithTag)
-        tag = 'Person_setReference_%s' % value.encode('hex')
+        activate_kw['tag'] = tag = 'Person_setReference_' + value.encode('hex')
         # Check that there no existing user
         acl_users = getToolByName(self, 'acl_users')
         if PluggableAuthService is not None and isinstance(acl_users,
@@ -203,11 +204,9 @@ class Person(EncryptedPasswordMixin, XMLObject):
           raise RuntimeError, 'user id %s already exist' % (value,)
         else:
           transactional_variable[tag] = None
-      else:
-        tag = None
 
       self._setReference(value)
-      self.reindexObject(activate_kw={'tag': tag})
+      self.reindexObject(activate_kw=activate_kw)
       # invalid the cache for ERP5Security
       portal_caches = getToolByName(self.getPortalObject(), 'portal_caches')
       portal_caches.clearCache(cache_factory_list=('erp5_content_short', ))
diff --git a/product/ERP5Security/tests/testERP5Security.py b/product/ERP5Security/tests/testERP5Security.py
index 8f9e9dbdc47..31a711d65d3 100644
--- a/product/ERP5Security/tests/testERP5Security.py
+++ b/product/ERP5Security/tests/testERP5Security.py
@@ -404,8 +404,8 @@ class TestUserManagement(ERP5TypeTestCase):
 
   def test_PersonLoginIsPossibleToUnset(self):
     """Make sure that it is possible to remove reference"""
-    p = self._makePerson(reference='foo', password='secret',)
-    p.setReference(None)
+    person = self._makePerson(reference='foo', password='secret',)
+    person.setReference(None)
     transaction.commit()
     self.tic()
     self.assertEqual(None, person.getReference())
-- 
2.30.9