refactor: Create a user object in report.

To make it easier to check if there is user information to be used
in the error report emails, we create a user object inside report.
Now, to check if we have the user's full name, email, etc, we just
need to do report['user']['user_full_name'] rather than check
each information one by one, because if the value of one key in
the report is different than None, all the others will be as well.
This commit is contained in:
Clara Dantas
2020-07-20 21:08:10 -03:00
committed by Alex Vandiver
parent ed7a6d5e4d
commit b4dd118aa1
3 changed files with 26 additions and 15 deletions

View File

@@ -23,8 +23,8 @@ def logger_repr(report: Dict[str, Any]) -> str:
return "Logger {logger_name}, from module {log_module} line {log_lineno}:".format(**report)
def user_info_str(report: Dict[str, Any]) -> str:
if report['user_full_name'] and report['user_email']:
user_info = "{user_full_name} ({user_email})".format(**report)
if report.get('user') and report['user'].get('user_full_name'):
user_info = "{user[user_full_name]} <{user[user_email]}>".format(**report)
else:
user_info = "Anonymous user (not logged in)"
@@ -44,10 +44,11 @@ def notify_browser_error(report: Dict[str, Any]) -> None:
email_browser_error(report)
def email_browser_error(report: Dict[str, Any]) -> None:
email_subject = f"Browser error for {user_info_str(report)}"
user_info = user_info_str(report)
email_subject = f"Browser error for {user_info}"
body = f"User: {user_info}"
body = """\
User: {user_full_name} <{user_email}> on {deployment}
body += """\
Message:
{message}