From be6b2b248fdabb1928ee677e4d6b513ebf69a403 Mon Sep 17 00:00:00 2001 From: Clara Dantas Date: Mon, 20 Jul 2020 21:44:56 -0300 Subject: [PATCH] Error reporting emails: Indicate user role. Adds user role to the user's information in the error reporting emails, as some bugs are role-dependent. Fixes: #15344 --- zerver/lib/error_notify.py | 2 +- zerver/logging_handlers.py | 4 ++++ zerver/tests/test_logging_handlers.py | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/zerver/lib/error_notify.py b/zerver/lib/error_notify.py index d38e9a3009..f13bb2b1b3 100644 --- a/zerver/lib/error_notify.py +++ b/zerver/lib/error_notify.py @@ -24,7 +24,7 @@ def logger_repr(report: Dict[str, Any]) -> str: def user_info_str(report: Dict[str, Any]) -> str: if report.get('user') and report['user'].get('user_full_name'): - user_info = "{user[user_full_name]} <{user[user_email]}>".format(**report) + user_info = "{user[user_full_name]} <{user[user_email]}> ({user[user_role]})".format(**report) else: user_info = "Anonymous user (not logged in)" diff --git a/zerver/logging_handlers.py b/zerver/logging_handlers.py index 5b7960d3cd..b17b58302c 100644 --- a/zerver/logging_handlers.py +++ b/zerver/logging_handlers.py @@ -41,18 +41,22 @@ def add_request_metadata(report: Dict[str, Any], request: HttpRequest) -> None: if isinstance(user_profile, AnonymousUser): user_full_name = None user_email = None + user_role = None else: user_full_name = user_profile.full_name user_email = user_profile.email + user_role = user_profile.get_role_name() except Exception: # Unexpected exceptions here should be handled gracefully traceback.print_exc() user_full_name = None user_email = None + user_role = None report['user'] = { 'user_email': user_email, 'user_full_name': user_full_name, + 'user_role': user_role, } exception_filter = get_exception_reporter_filter(request) diff --git a/zerver/tests/test_logging_handlers.py b/zerver/tests/test_logging_handlers.py index e807cb0112..b020beb511 100644 --- a/zerver/tests/test_logging_handlers.py +++ b/zerver/tests/test_logging_handlers.py @@ -117,6 +117,7 @@ class AdminNotifyHandlerTest(ZulipTestCase): report = self.run_handler(record) self.assertIn("user", report) self.assertIn("user_email", report["user"]) + self.assertIn("user_role", report["user"]) self.assertIn("message", report) self.assertIn("stack_trace", report) self.assertEqual(report['stack_trace'], 'message\nmoremesssage\nmore') @@ -132,6 +133,7 @@ class AdminNotifyHandlerTest(ZulipTestCase): report = self.run_handler(record) self.assertIn("user", report) self.assertIn("user_email", report["user"]) + self.assertIn("user_role", report["user"]) self.assertIn("message", report) self.assertIn("stack_trace", report) @@ -150,6 +152,7 @@ class AdminNotifyHandlerTest(ZulipTestCase): self.assertIn("host", report) self.assertIn("user", report) self.assertIn("user_email", report["user"]) + self.assertIn("user_role", report["user"]) self.assertIn("message", report) self.assertIn("stack_trace", report) @@ -163,6 +166,7 @@ class AdminNotifyHandlerTest(ZulipTestCase): self.assertIn("host", report) self.assertIn("user", report) self.assertIn("user_email", report["user"]) + self.assertIn("user_role", report["user"]) self.assertIn("message", report) self.assertIn("stack_trace", report) @@ -175,6 +179,7 @@ class AdminNotifyHandlerTest(ZulipTestCase): self.assertIn("host", report) self.assertIn("user", report) self.assertIn("user_email", report["user"]) + self.assertIn("user_role", report["user"]) self.assertIn("message", report) self.assertIn("stack_trace", report) @@ -193,6 +198,7 @@ class AdminNotifyHandlerTest(ZulipTestCase): self.assertIn("host", report) self.assertIn("user", report) self.assertIn("user_email", report["user"]) + self.assertIn("user_role", report["user"]) self.assertIn("message", report) self.assertEqual(report["stack_trace"], 'No stack trace available') @@ -203,6 +209,7 @@ class AdminNotifyHandlerTest(ZulipTestCase): self.assertIn("host", report) self.assertIn("user", report) self.assertIn("user_email", report["user"]) + self.assertIn("user_role", report["user"]) self.assertIn("message", report) self.assertIn("stack_trace", report)