mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
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:
committed by
Tim Abbott
parent
d04db7c5fe
commit
a1f5f6502c
@@ -265,7 +265,6 @@ def access_user_by_api_key(request: HttpRequest, api_key: str, email: Optional[s
|
||||
|
||||
def log_exception_to_webhook_logger(
|
||||
request: HttpRequest,
|
||||
user_profile: UserProfile,
|
||||
summary: str,
|
||||
payload: str,
|
||||
unsupported_event: bool,
|
||||
@@ -299,8 +298,8 @@ body:
|
||||
{body}
|
||||
""".format(
|
||||
summary=summary,
|
||||
email=user_profile.delivery_email,
|
||||
realm=user_profile.realm.string_id,
|
||||
email=request.user.delivery_email,
|
||||
realm=request.user.realm.string_id,
|
||||
client_name=request.client.name,
|
||||
body=payload,
|
||||
path_info=request.META.get('PATH_INFO', None),
|
||||
@@ -352,7 +351,6 @@ def webhook_view(
|
||||
err.webhook_name = webhook_client_name
|
||||
log_exception_to_webhook_logger(
|
||||
request=request,
|
||||
user_profile=user_profile,
|
||||
summary=str(err),
|
||||
payload=request.body,
|
||||
unsupported_event=isinstance(err, UnsupportedWebhookEventType),
|
||||
@@ -605,7 +603,6 @@ def authenticated_rest_api_view(
|
||||
if request_body is not None:
|
||||
log_exception_to_webhook_logger(
|
||||
request=request,
|
||||
user_profile=profile,
|
||||
summary=str(err),
|
||||
payload=request_body,
|
||||
unsupported_event=isinstance(err, UnsupportedWebhookEventType),
|
||||
|
||||
@@ -33,21 +33,18 @@ class Helper:
|
||||
def __init__(
|
||||
self,
|
||||
request: HttpRequest,
|
||||
user_profile: UserProfile,
|
||||
payload: Dict[str, Any],
|
||||
include_title: bool,
|
||||
) -> None:
|
||||
self.payload = payload
|
||||
self.include_title = include_title
|
||||
self._request = request
|
||||
self._user_profile = user_profile
|
||||
|
||||
def log_unsupported(self, event: str) -> None:
|
||||
summary = f"The '{event}' event isn't currently supported by the GitHub webhook"
|
||||
request = self._request
|
||||
log_exception_to_webhook_logger(
|
||||
request=request,
|
||||
user_profile=self._user_profile,
|
||||
summary=summary,
|
||||
payload=request.body,
|
||||
unsupported_event=True,
|
||||
@@ -635,7 +632,6 @@ def api_github_webhook(
|
||||
|
||||
helper = Helper(
|
||||
request=request,
|
||||
user_profile=user_profile,
|
||||
payload=payload,
|
||||
include_title=user_specified_topic is not None,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user