webhooks: In logger, pull user from request, rather than parameter.

request.user is set by validate_api_key, which is called by
webhook_view and authenticated_rest_api_view.
This commit is contained in:
Alex Vandiver
2020-09-03 15:29:11 -07:00
committed by Tim Abbott
parent d04db7c5fe
commit a1f5f6502c
2 changed files with 2 additions and 9 deletions

View File

@@ -265,7 +265,6 @@ def access_user_by_api_key(request: HttpRequest, api_key: str, email: Optional[s
def log_exception_to_webhook_logger( def log_exception_to_webhook_logger(
request: HttpRequest, request: HttpRequest,
user_profile: UserProfile,
summary: str, summary: str,
payload: str, payload: str,
unsupported_event: bool, unsupported_event: bool,
@@ -299,8 +298,8 @@ body:
{body} {body}
""".format( """.format(
summary=summary, summary=summary,
email=user_profile.delivery_email, email=request.user.delivery_email,
realm=user_profile.realm.string_id, realm=request.user.realm.string_id,
client_name=request.client.name, client_name=request.client.name,
body=payload, body=payload,
path_info=request.META.get('PATH_INFO', None), path_info=request.META.get('PATH_INFO', None),
@@ -352,7 +351,6 @@ def webhook_view(
err.webhook_name = webhook_client_name err.webhook_name = webhook_client_name
log_exception_to_webhook_logger( log_exception_to_webhook_logger(
request=request, request=request,
user_profile=user_profile,
summary=str(err), summary=str(err),
payload=request.body, payload=request.body,
unsupported_event=isinstance(err, UnsupportedWebhookEventType), unsupported_event=isinstance(err, UnsupportedWebhookEventType),
@@ -605,7 +603,6 @@ def authenticated_rest_api_view(
if request_body is not None: if request_body is not None:
log_exception_to_webhook_logger( log_exception_to_webhook_logger(
request=request, request=request,
user_profile=profile,
summary=str(err), summary=str(err),
payload=request_body, payload=request_body,
unsupported_event=isinstance(err, UnsupportedWebhookEventType), unsupported_event=isinstance(err, UnsupportedWebhookEventType),

View File

@@ -33,21 +33,18 @@ class Helper:
def __init__( def __init__(
self, self,
request: HttpRequest, request: HttpRequest,
user_profile: UserProfile,
payload: Dict[str, Any], payload: Dict[str, Any],
include_title: bool, include_title: bool,
) -> None: ) -> None:
self.payload = payload self.payload = payload
self.include_title = include_title self.include_title = include_title
self._request = request self._request = request
self._user_profile = user_profile
def log_unsupported(self, event: str) -> None: def log_unsupported(self, event: str) -> None:
summary = f"The '{event}' event isn't currently supported by the GitHub webhook" summary = f"The '{event}' event isn't currently supported by the GitHub webhook"
request = self._request request = self._request
log_exception_to_webhook_logger( log_exception_to_webhook_logger(
request=request, request=request,
user_profile=self._user_profile,
summary=summary, summary=summary,
payload=request.body, payload=request.body,
unsupported_event=True, unsupported_event=True,
@@ -635,7 +632,6 @@ def api_github_webhook(
helper = Helper( helper = Helper(
request=request, request=request,
user_profile=user_profile,
payload=payload, payload=payload,
include_title=user_specified_topic is not None, include_title=user_specified_topic is not None,
) )