Commit 984f7f13 authored by Vincent Pelletier's avatar Vincent Pelletier

Products.CMFActivity: Fix user name in activity tracking log messages

This was broken by:
  commit f363ac65
  Author: Vincent Pelletier <vincent@nexedi.com>
  Date:   Wed Mar 23 15:55:46 2022 +0900

      Products.CMFActivity.ActivityTool: Store user object in activity.
as user_name becomes always None.
parent 34d50a78
...@@ -311,7 +311,7 @@ class Message(BaseMessage): ...@@ -311,7 +311,7 @@ class Message(BaseMessage):
pass pass
return 1 return 1
def changeUser(self, activity_tool): def changeUser(self, activity_tool, annotate_transaction=True):
"""restore the security context for the calling user.""" """restore the security context for the calling user."""
portal = activity_tool.getPortalObject() portal = activity_tool.getPortalObject()
user = self.user_object user = self.user_object
...@@ -346,7 +346,8 @@ class Message(BaseMessage): ...@@ -346,7 +346,8 @@ class Message(BaseMessage):
if user is not None: if user is not None:
user = user.__of__(user_folder) user = user.__of__(user_folder)
newSecurityManager(None, user) newSecurityManager(None, user)
transaction.get().setUser(user_name, '/'.join(user_folder.getPhysicalPath())) if annotate_transaction:
transaction.get().setUser(user_name, '/'.join(user_folder.getPhysicalPath()))
else : else :
LOG("CMFActivity", WARNING, LOG("CMFActivity", WARNING,
"Unable to find user %r in the portal" % user_name) "Unable to find user %r in the portal" % user_name)
...@@ -412,7 +413,6 @@ class Message(BaseMessage): ...@@ -412,7 +413,6 @@ class Message(BaseMessage):
else: else:
message = "Activity failed" message = "Activity failed"
path = '/'.join(self.object_path) path = '/'.join(self.object_path)
user = self.user_object
mail_text = """From: %s <%s> mail_text = """From: %s <%s>
To: %s To: %s
Subject: %s: %s/%s Subject: %s: %s/%s
...@@ -428,11 +428,7 @@ Named Parameters: %r ...@@ -428,11 +428,7 @@ Named Parameters: %r
""" % ( """ % (
email_from_name, activity_tool.email_from_address, user_email, message, email_from_name, activity_tool.email_from_address, user_email, message,
path, self.method_id, getCurrentNode(), fail_count, path, self.method_id, getCurrentNode(), fail_count,
( self.getUserId(),
self.user_name
if user is None else
user.getIdOrUserName()
),
self.line.uid, path, self.method_id, self.args, self.kw, self.line.uid, path, self.method_id, self.args, self.kw,
) )
if self.traceback: if self.traceback:
...@@ -445,6 +441,14 @@ Named Parameters: %r ...@@ -445,6 +441,14 @@ Named Parameters: %r
LOG('ActivityTool.notifyUser', WARNING, LOG('ActivityTool.notifyUser', WARNING,
'Mail containing failure information failed to be sent: %s' % message) 'Mail containing failure information failed to be sent: %s' % message)
def getUserId(self):
user = self.user_object
return (
self.user_name
if user is None else
user.getIdOrUserName()
)
def reactivate(self, activity_tool, activity=DEFAULT_ACTIVITY): def reactivate(self, activity_tool, activity=DEFAULT_ACTIVITY):
# Reactivate the original object. # Reactivate the original object.
obj = self._getObject(activity_tool) obj = self._getObject(activity_tool)
...@@ -583,7 +587,7 @@ class Method(object): ...@@ -583,7 +587,7 @@ class Method(object):
portal_activities.getActivityBuffer().deferredQueueMessage( portal_activities.getActivityBuffer().deferredQueueMessage(
portal_activities, activity_dict[self._activity], m) portal_activities, activity_dict[self._activity], m)
if portal_activities.activity_tracking and m.is_registered: if portal_activities.activity_tracking and m.is_registered:
activity_tracking_logger.info('queuing message: activity=%s, object_path=%s, method_id=%s, args=%s, kw=%s, activity_kw=%s, user_name=%s' % (self._activity, '/'.join(m.object_path), m.method_id, m.args, m.kw, m.activity_kw, m.user_name)) activity_tracking_logger.info('queuing message: activity=%s, object_path=%s, method_id=%s, args=%s, kw=%s, activity_kw=%s, user_name=%s' % (self._activity, '/'.join(m.object_path), m.method_id, m.args, m.kw, m.activity_kw, m.getUserId()))
allow_class(Method) allow_class(Method)
...@@ -1530,7 +1534,7 @@ class ActivityTool (BaseTool): ...@@ -1530,7 +1534,7 @@ class ActivityTool (BaseTool):
def invoke(self, message): def invoke(self, message):
if self.activity_tracking: if self.activity_tracking:
activity_tracking_logger.info('invoking message: object_path=%s, method_id=%s, args=%r, kw=%r, activity_kw=%r, user_name=%s' % ('/'.join(message.object_path), message.method_id, message.args, message.kw, message.activity_kw, message.user_name)) activity_tracking_logger.info('invoking message: object_path=%s, method_id=%s, args=%r, kw=%r, activity_kw=%r, user_name=%s' % ('/'.join(message.object_path), message.method_id, message.args, message.kw, message.activity_kw, message.getUserId()))
if getattr(self, 'aq_chain', None) is not None: if getattr(self, 'aq_chain', None) is not None:
# Grab existing acquisition chain and extrach base objects. # Grab existing acquisition chain and extrach base objects.
base_chain = [aq_base(x) for x in self.aq_chain] base_chain = [aq_base(x) for x in self.aq_chain]
...@@ -1694,7 +1698,8 @@ class ActivityTool (BaseTool): ...@@ -1694,7 +1698,8 @@ class ActivityTool (BaseTool):
try: try:
for m in message_list: for m in message_list:
message = m._message message = m._message
if user_name != message.user_name: message_user_id = message.getUserId()
if message.user_object or user_name != message.user_name:
user_name = message.user_name user_name = message.user_name
message.changeUser(m.object) message.changeUser(m.object)
m.result = getattr(m.object, method_id)(*m.args, **m.kw) m.result = getattr(m.object, method_id)(*m.args, **m.kw)
......
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