Commit 6ded2571 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

py2/py3: str.encode('hex') does not work in Python 3.

parent 6488f71d
...@@ -27,11 +27,13 @@ ...@@ -27,11 +27,13 @@
# #
############################################################################## ##############################################################################
import binascii
import zope.interface import zope.interface
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, interfaces from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5.Document.Node import Node from Products.ERP5.Document.Node import Node
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
from Products.ERP5Type.Utils import bytes2str, str2bytes
from erp5.component.mixin.EncryptedPasswordMixin import EncryptedPasswordMixin from erp5.component.mixin.EncryptedPasswordMixin import EncryptedPasswordMixin
from erp5.component.mixin.LoginAccountProviderMixin import LoginAccountProviderMixin from erp5.component.mixin.LoginAccountProviderMixin import LoginAccountProviderMixin
from erp5.component.mixin.ERP5UserMixin import ERP5UserMixin from erp5.component.mixin.ERP5UserMixin import ERP5UserMixin
...@@ -143,9 +145,9 @@ class Person(EncryptedPasswordMixin, Node, LoginAccountProviderMixin, ERP5UserMi ...@@ -143,9 +145,9 @@ class Person(EncryptedPasswordMixin, Node, LoginAccountProviderMixin, ERP5UserMi
# Encode reference to hex to prevent uppercase/lowercase conflict in # Encode reference to hex to prevent uppercase/lowercase conflict in
# activity table (when calling countMessageWithTag) # activity table (when calling countMessageWithTag)
if user_id: if user_id:
tag = 'set_userid_' + user_id.encode('hex') tag = 'set_userid_' + bytes2str(binascii.hexlify(str2bytes(user_id)))
else: else:
tag = 'set_login_' + login.encode('hex') tag = 'set_userid_' + bytes2str(binascii.hexlify(str2bytes(login)))
# Check that there no existing user # Check that there no existing user
acl_users = getattr(self, 'acl_users', None) acl_users = getattr(self, 'acl_users', None)
if PluggableAuthService is not None and isinstance(acl_users, if PluggableAuthService is not None and isinstance(acl_users,
......
...@@ -2,14 +2,16 @@ ...@@ -2,14 +2,16 @@
Parameters: Parameters:
value -- field value (string) value -- field value (string)
REQUEST -- standard REQUEST variable""" REQUEST -- standard REQUEST variable"""
import binascii
from Products.ERP5Type.Utils import bytes2str, str2bytes
portal = context.getPortalObject() portal = context.getPortalObject()
if value: if value:
# Same tag is used as in ERP5 Login _setReference, in order to protect against # Same tag is used as in ERP5 Login _setReference, in order to protect against
# concurrency between Credential Request and ERP5 Login object too # concurrency between Credential Request and ERP5 Login object too
# #
# XXX: value.encode('hex') may exceed 'tag' column length (255)... # XXX: hex encoded value may exceed 'tag' column length (255)...
if context.getPortalObject().portal_activities.countMessageWithTag('set_login_' + value.encode('hex')): if context.getPortalObject().portal_activities.countMessageWithTag('set_login_' + bytes2str(binascii.hexlify(str2bytes2(value)))):
return False return False
def getRealContext(): def getRealContext():
......
...@@ -3,6 +3,8 @@ Paramameter list : ...@@ -3,6 +3,8 @@ Paramameter list :
reference -- User login is mandatory (String) reference -- User login is mandatory (String)
default_email_text -- Email is mandatory (String)""" default_email_text -- Email is mandatory (String)"""
# create the credential request # create the credential request
import binascii
from Products.ERP5Type.Utils import bytes2str, str2bytes
portal = context.getPortalObject() portal = context.getPortalObject()
module = portal.getDefaultModule(portal_type='Credential Request') module = portal.getDefaultModule(portal_type='Credential Request')
portal_preferences = portal.portal_preferences portal_preferences = portal.portal_preferences
...@@ -39,7 +41,7 @@ credential_request = module.newContent( ...@@ -39,7 +41,7 @@ credential_request = module.newContent(
credential_request.setCategoryList(category_list) credential_request.setCategoryList(category_list)
# Same tag is used as in ERP5 Login._setReference, in order to protect against # Same tag is used as in ERP5 Login._setReference, in order to protect against
# concurrency between Credential Request and Person object too # concurrency between Credential Request and Person object too
tag = 'set_login_%s' % reference.encode('hex') tag = 'set_login_%s' % bytes2str(binascii.hexlify(str2bytes2(reference)))
credential_request.reindexObject(activate_kw={'tag': tag}) credential_request.reindexObject(activate_kw={'tag': tag})
#We attach the current user to the credential request if not anonymous #We attach the current user to the credential request if not anonymous
......
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