Skip to content

Commit 5d153b6

Browse files
committed
Extracted method to get real name from notify method.
1 parent bd36c70 commit 5d153b6

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

code_comments/notification.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,18 @@ def get_recipients(self, comment):
138138

139139
return (torcpts, ccrcpts)
140140

141-
def notify(self, comment):
142-
from_name = comment.author
143-
144-
# See if we can get a real name for the comment author
141+
def _get_name(self, comment):
142+
"""
143+
Get the real name of the user who made the comment. If it cannot be
144+
determined, return their username.
145+
"""
145146
for username, name, email in self.env.get_known_users():
146147
if username == comment.author and name:
147-
from_name = name
148+
return name
149+
150+
return comment.author
151+
152+
def notify(self, comment):
148153

149154
self.data.update({
150155
"comment": comment,
@@ -156,6 +161,7 @@ def notify(self, comment):
156161
# Temporarily switch the smtp_from_name setting so we can pretend
157162
# the mail came from the author of the comment
158163
try:
164+
from_name = self._get_name(comment)
159165
self.env.log.debug("Changing smtp_from_name to %s" % from_name)
160166
old_setting = self.config['notification'].get('smtp_from_name')
161167
self.config.set('notification', 'smtp_from_name', from_name)

0 commit comments

Comments
 (0)