fix(136521333): Handle None email_or_id in avatar code

Fixes https://www.pivotaltracker.com/story/show/136521333
This commit is contained in:
Joseph Schorr 2016-12-21 15:00:55 -05:00
parent 732ab67b57
commit ef80471a39
3 changed files with 39 additions and 12 deletions

View file

@ -77,7 +77,11 @@ class BaseAvatar(object):
}
"""
colors = self.colors
hash_value = hashlib.md5(email_or_id.strip().lower()).hexdigest()
# Note: email_or_id may be None if gotten from external auth when email is disabled,
# so use the username in that case.
username_email_or_id = email_or_id or name
hash_value = hashlib.md5(username_email_or_id.strip().lower()).hexdigest()
byte_count = int(math.ceil(math.log(len(colors), 16)))
byte_data = hash_value[0:byte_count]