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):
pass
return 1
def changeUser(self, activity_tool):
def changeUser(self, activity_tool, annotate_transaction=True):
"""restore the security context for the calling user."""
portal = activity_tool.getPortalObject()
user = self.user_object
......@@ -346,6 +346,7 @@ class Message(BaseMessage):
if user is not None:
user = user.__of__(user_folder)
newSecurityManager(None, user)
if annotate_transaction:
transaction.get().setUser(user_name, '/'.join(user_folder.getPhysicalPath()))
else :
LOG("CMFActivity", WARNING,
......@@ -412,7 +413,6 @@ class Message(BaseMessage):
else:
message = "Activity failed"
path = '/'.join(self.object_path)
user = self.user_object
mail_text = """From: %s <%s>
To: %s
Subject: %s: %s/%s
......@@ -428,11 +428,7 @@ Named Parameters: %r
""" % (
email_from_name, activity_tool.email_from_address, user_email, message,
path, self.method_id, getCurrentNode(), fail_count,
(
self.user_name
if user is None else
user.getIdOrUserName()
),
self.getUserId(),
self.line.uid, path, self.method_id, self.args, self.kw,
)
if self.traceback:
......@@ -445,6 +441,14 @@ Named Parameters: %r
LOG('ActivityTool.notifyUser', WARNING,
'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):
# Reactivate the original object.
obj = self._getObject(activity_tool)
......@@ -583,7 +587,7 @@ class Method(object):
portal_activities.getActivityBuffer().deferredQueueMessage(
portal_activities, activity_dict[self._activity], m)
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)
......@@ -1530,7 +1534,7 @@ class ActivityTool (BaseTool):
def invoke(self, message):
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:
# Grab existing acquisition chain and extrach base objects.
base_chain = [aq_base(x) for x in self.aq_chain]
......@@ -1694,7 +1698,8 @@ class ActivityTool (BaseTool):
try:
for m in message_list:
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
message.changeUser(m.object)
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