Files
zulip/zerver/webhooks/transifex/view.py
Alex Vandiver 8016769613 webhooks: Move UnexpectedWebhookEventType into zerver.lib.exceptions.
8e10ab282a moved UnexpectedWebhookEventType into
`zerver.lib.exceptions`, but left the import into
`zserver.lib.webhooks.common` so that webhooks could continue to
import the exception from there.

This clutters things and adds complexity; there is no compelling
reason that the exception's source of truth should not move alongside
all other exceptions.
2020-09-10 17:47:21 -07:00

35 lines
1.3 KiB
Python

# Webhooks for external integrations.
from typing import Optional
from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view
from zerver.lib.exceptions import UnexpectedWebhookEventType
from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success
from zerver.lib.validator import check_int
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile
@api_key_only_webhook_view('Transifex', notify_bot_owner_on_invalid_json=False)
@has_request_variables
def api_transifex_webhook(
request: HttpRequest,
user_profile: UserProfile,
project: str = REQ(),
resource: str = REQ(),
language: str = REQ(),
translated: Optional[int] = REQ(validator=check_int, default=None),
reviewed: Optional[int] = REQ(validator=check_int, default=None),
) -> HttpResponse:
subject = f"{project} in {language}"
if translated:
body = f"Resource {resource} fully translated."
elif reviewed:
body = f"Resource {resource} fully reviewed."
else:
raise UnexpectedWebhookEventType('Transifex', 'Unknown Event Type')
check_send_webhook_message(request, user_profile, subject, body)
return json_success()