Commit f4a9ac04 authored by Julien Muchembled's avatar Julien Muchembled Committed by Cédric Le Ninivin

ERP5Type: remove buggy/useless cache for the owner of temp objects

Caching the current user during the transaction breaks code that changes user.
getSecurityManager().getUser().getId() is anyway already so fast, and it is
here called so rarely, that it's not worth caching the result.
parent 7ec151a4
...@@ -38,7 +38,6 @@ from Products.ERP5Type.XMLObject import XMLObject ...@@ -38,7 +38,6 @@ from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5Type.Cache import CachingMethod from Products.ERP5Type.Cache import CachingMethod
from Products.ERP5Type.dynamic.accessor_holder import getPropertySheetValueList, \ from Products.ERP5Type.dynamic.accessor_holder import getPropertySheetValueList, \
getAccessorHolderList getAccessorHolderList
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
ERP5TYPE_SECURITY_GROUP_ID_GENERATION_SCRIPT = 'ERP5Type_asSecurityGroupId' ERP5TYPE_SECURITY_GROUP_ID_GENERATION_SCRIPT = 'ERP5Type_asSecurityGroupId'
...@@ -49,24 +48,6 @@ from sys import exc_info ...@@ -49,24 +48,6 @@ from sys import exc_info
from zLOG import LOG, ERROR from zLOG import LOG, ERROR
from Products.CMFCore.exceptions import zExceptions_Unauthorized from Products.CMFCore.exceptions import zExceptions_Unauthorized
def getCurrentUserIdOrAnonymousToken():
"""Return connected user_id or simple token for
Anonymous users in scope of transaction.
"""
tv = getTransactionalVariable()
USER_ID_KEY = '_user_id'
ANONYMOUS_OWNER_ROLE_VALUE = 'Anonymous Owner'
try:
return tv[USER_ID_KEY]
except KeyError:
user = getSecurityManager().getUser()
if user is not None:
user_id = user.getId()
else:
user_id = ANONYMOUS_OWNER_ROLE_VALUE
tv[USER_ID_KEY] = user_id
return user_id
class LocalRoleAssignorMixIn(object): class LocalRoleAssignorMixIn(object):
"""Mixin class used by type informations to compute and update local roles """Mixin class used by type informations to compute and update local roles
""" """
...@@ -392,7 +373,11 @@ class ERP5TypeInformation(XMLObject, ...@@ -392,7 +373,11 @@ class ERP5TypeInformation(XMLObject,
if temp_object: if temp_object:
# Setup only Owner local role on Document like # Setup only Owner local role on Document like
# container._setObject(set_owner=True) does. # container._setObject(set_owner=True) does.
user_id = getCurrentUserIdOrAnonymousToken() user = getSecurityManager().getUser()
if user is not None:
user_id = user.getId()
else:
user_id = 'Anonymous Owner'
ob.manage_setLocalRoles(user_id, ['Owner']) ob.manage_setLocalRoles(user_id, ['Owner'])
else: else:
if activate_kw is not None: if activate_kw is not None:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment