Be more careful with null accounts

Extend the checks for null/empty account names to message authors
and the change screen.

Change-Id: Ia71d5dc8ce098c8d6dd60928ad2348a2eff98264
This commit is contained in:
James E. Blair 2014-09-18 08:09:30 -07:00
parent aedec159c7
commit 2e991f2d92
3 changed files with 31 additions and 13 deletions

View File

@ -266,6 +266,19 @@ class Change(object):
session.flush()
return l
@property
def owner_name(self):
owner_name = 'Anonymous Coward'
if self.owner:
if self.owner.name:
owner_name = self.owner.name
elif self.owner.username:
owner_name = self.owner.username
elif self.owner.email:
owner_name = self.owner.email
return owner_name
class Revision(object):
def __init__(self, change, number, message, commit, parent,
fetch_auth, fetch_ref, pending_message=False):
@ -328,6 +341,18 @@ class Message(object):
self.draft = draft
self.pending = pending
@property
def author_name(self):
author_name = 'Anonymous Coward'
if self.author:
if self.author.name:
author_name = self.author.name
elif self.author.username:
author_name = self.author.username
elif self.author.email:
author_name = self.author.email
return author_name
class Comment(object):
def __init__(self, revision, id, author, in_reply_to, created, file, parent, line, message, draft=False):
self.revision_key = revision.key

View File

@ -327,7 +327,7 @@ class ChangeMessageBox(mywid.HyperText):
if message.draft:
lines.insert(0, '')
lines.insert(0, 'Patch Set %s:' % (message.revision.number,))
text = [('change-message-name', message.author.name),
text = [('change-message-name', message.author_name),
('change-message-header', ': '+lines.pop(0)),
('change-message-header',
message.created.strftime(' (%Y-%m-%d %H:%M:%S%z)'))]
@ -501,7 +501,7 @@ class ChangeView(urwid.WidgetWrap):
self.change_rest_id = change.id
self.change_id_label.set_text(('change-data', change.change_id))
self.owner_label.set_text(('change-data', change.owner.name))
self.owner_label.set_text(('change-data', change.owner_name))
self.project_label.set_text(('change-data', change.project.name))
self.branch_label.set_text(('change-data', change.branch))
self.topic_label.set_text(('change-data', self.topic))
@ -588,7 +588,8 @@ class ChangeView(urwid.WidgetWrap):
display_messages = []
result_systems = {}
for message in change.messages:
if message.revision == change.revisions[-1]:
if (message.revision == change.revisions[-1] and
message.author and message.author.name):
for commentlink in self.app.config.commentlinks:
results = commentlink.getTestResults(self.app, message.message)
if results:
@ -596,7 +597,7 @@ class ChangeView(urwid.WidgetWrap):
result_systems[message.author.name] = result_system
result_system.update(results)
skip = False
if self.hide_comments:
if self.hide_comments and message.author and message.author.name:
for regex in self.app.config.hide_comments:
if regex.match(message.author.name):
skip = True

View File

@ -57,15 +57,7 @@ class ChangeRow(urwid.Button):
self.subject.set_text(change.subject)
self.number.set_text(str(change.number))
self.project.set_text(change.project.name.split('/')[-1])
owner_name = 'Anonymous Coward'
if change.owner:
if change.owner.name:
owner_name = change.owner.name
elif change.owner.username:
owner_name = change.owner.username
elif change.owner.email:
owner_name = change.owner.email
self.owner.set_text(owner_name)
self.owner.set_text(change.owner_name)
del self.columns.contents[self.num_columns:]
for category in categories:
v = change.getMaxForCategory(category)