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.
This commit is contained in:
Alex Vandiver
2020-08-19 13:14:40 -07:00
committed by Tim Abbott
parent f95dd628bd
commit 8016769613
28 changed files with 49 additions and 36 deletions

View File

@@ -623,7 +623,7 @@ Many third-party services have dozens of different event types. In some cases, w
may choose to explicitly ignore specific events. In other cases, there may be
events that are new or events that we don't know about. In such cases, we
recommend raising `UnexpectedWebhookEventType` (found in
`zerver/lib/webhooks/common.py`), like so:
`zerver/lib/exceptions.py`), like so:
```
raise UnexpectedWebhookEventType(webhook_name, event_type)

View File

@@ -7,9 +7,6 @@ from zulint.linters import run_pyflakes
def check_pyflakes(files: List[str], options: argparse.Namespace) -> bool:
suppress_patterns = [
("scripts/lib/pythonrc.py", "imported but unused"),
# Intentionally imported by zerver/lib/webhooks/common.py
('', "'zerver.lib.exceptions.UnexpectedWebhookEventType' imported but unused"),
# Our ipython startup pythonrc file intentionally imports *
("scripts/lib/pythonrc.py",

View File

@@ -10,12 +10,7 @@ from zerver.lib.actions import (
check_send_stream_message,
send_rate_limited_pm_notification_to_bot_owner,
)
from zerver.lib.exceptions import (
ErrorCode,
JsonableError,
StreamDoesNotExistError,
UnexpectedWebhookEventType,
)
from zerver.lib.exceptions import ErrorCode, JsonableError, StreamDoesNotExistError
from zerver.lib.request import REQ, has_request_variables
from zerver.lib.send_email import FromAddress
from zerver.models import UserProfile

View File

@@ -36,7 +36,12 @@ from zerver.lib.actions import (
do_set_realm_property,
)
from zerver.lib.cache import dict_to_items_tuple, ignore_unhashable_lru_cache, items_tuple_to_dict
from zerver.lib.exceptions import InvalidAPIKeyError, InvalidAPIKeyFormatError, JsonableError
from zerver.lib.exceptions import (
InvalidAPIKeyError,
InvalidAPIKeyFormatError,
JsonableError,
UnexpectedWebhookEventType,
)
from zerver.lib.initial_password import initial_password
from zerver.lib.request import (
REQ,
@@ -76,7 +81,6 @@ from zerver.lib.validator import (
to_non_negative_int,
to_positive_or_allowed_int,
)
from zerver.lib.webhooks.common import UnexpectedWebhookEventType
from zerver.models import Realm, UserProfile, get_realm, get_user
if settings.ZILENCER_ENABLED:

View File

@@ -5,9 +5,10 @@ from typing import Any, Dict
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.webhooks.common import UnexpectedWebhookEventType, check_send_webhook_message
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile
from .support_event import SUPPORT_EVENTS

View File

@@ -8,10 +8,10 @@ from typing import Any, Dict, List, 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.webhooks.common import (
UnexpectedWebhookEventType,
check_send_webhook_message,
validate_extract_webhook_http_header,
)

View File

@@ -6,9 +6,10 @@ from typing import Any, Callable, Dict, List, 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.webhooks.common import UnexpectedWebhookEventType, check_send_webhook_message
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.lib.webhooks.git import (
CONTENT_MESSAGE_TEMPLATE,
TOPIC_WITH_BRANCH_TEMPLATE,

View File

@@ -4,9 +4,10 @@ from typing import Any, Dict, 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.webhooks.common import UnexpectedWebhookEventType, check_send_webhook_message
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile
EPIC_NAME_TEMPLATE = "**{name}**"

View File

@@ -5,10 +5,10 @@ from typing import Any, Callable, Dict, Optional
from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view, log_exception_to_webhook_logger
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.webhooks.common import (
UnexpectedWebhookEventType,
check_send_webhook_message,
get_http_headers_from_filename,
validate_extract_webhook_http_header,

View File

@@ -6,11 +6,11 @@ from typing import Any, Dict, 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_bool
from zerver.lib.webhooks.common import (
UnexpectedWebhookEventType,
check_send_webhook_message,
validate_extract_webhook_http_header,
)

View File

@@ -4,10 +4,10 @@ from typing import Any, Callable, Dict, 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.webhooks.common import (
UnexpectedWebhookEventType,
check_send_webhook_message,
get_http_headers_from_filename,
validate_extract_webhook_http_header,

View File

@@ -3,9 +3,10 @@ from typing import Any, Dict
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.webhooks.common import UnexpectedWebhookEventType, check_send_webhook_message
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile
TRAFFIC_SPIKE_TEMPLATE = '[{website_name}]({website_url}) has {user_num} visitors online.'

View File

@@ -5,10 +5,10 @@ from typing import Any, Callable, Dict, 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.webhooks.common import (
UnexpectedWebhookEventType,
check_send_webhook_message,
get_http_headers_from_filename,
validate_extract_webhook_http_header,

View File

@@ -5,9 +5,10 @@ from django.db.models import Q
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.webhooks.common import UnexpectedWebhookEventType, check_send_webhook_message
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import Realm, UserProfile
IGNORED_EVENTS = [

View File

@@ -5,9 +5,10 @@ from typing import Any, Callable, Dict, List, Tuple
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.webhooks.common import UnexpectedWebhookEventType, check_send_webhook_message
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile
COMPANY_CREATED = """

View File

@@ -7,9 +7,10 @@ from django.db.models import Q
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.webhooks.common import UnexpectedWebhookEventType, check_send_webhook_message
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import Realm, UserProfile, get_user_by_delivery_email
IGNORED_EVENTS = [

View File

@@ -3,10 +3,10 @@ from typing import Any, Dict, Iterable
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.webhooks.common import (
UnexpectedWebhookEventType,
check_send_webhook_message,
get_http_headers_from_filename,
validate_extract_webhook_http_header,

View File

@@ -4,10 +4,11 @@ from typing import Any, Dict, 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_dict
from zerver.lib.webhooks.common import UnexpectedWebhookEventType, check_send_webhook_message
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile
ALERT_TEMPLATE = "{long_description} ([view alert]({alert_url}))."

View File

@@ -4,9 +4,10 @@ from typing import Any, Dict, Iterable
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.webhooks.common import UnexpectedWebhookEventType, check_send_webhook_message
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile
PAGER_DUTY_EVENT_NAMES = {

View File

@@ -4,9 +4,10 @@ from typing import Any, Dict
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.webhooks.common import UnexpectedWebhookEventType, check_send_webhook_message
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile
PINGDOM_TOPIC_TEMPLATE = '{name} status.'

View File

@@ -8,9 +8,10 @@ from django.http import HttpRequest, HttpResponse
from django.utils.translation import ugettext as _
from zerver.decorator import api_key_only_webhook_view
from zerver.lib.exceptions import UnexpectedWebhookEventType
from zerver.lib.request import has_request_variables
from zerver.lib.response import json_error, json_success
from zerver.lib.webhooks.common import UnexpectedWebhookEventType, check_send_webhook_message
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile

View File

@@ -4,9 +4,10 @@ from typing import Any, Dict
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.webhooks.common import UnexpectedWebhookEventType, check_send_webhook_message
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile

View File

@@ -3,10 +3,10 @@ from typing import Any, Dict, Iterable
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.webhooks.common import (
UnexpectedWebhookEventType,
check_send_webhook_message,
get_http_headers_from_filename,
validate_extract_webhook_http_header,

View File

@@ -4,9 +4,10 @@ from typing import Any, Dict, List, Optional, Tuple
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.webhooks.common import UnexpectedWebhookEventType, check_send_webhook_message
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile
DEPRECATED_EXCEPTION_MESSAGE_TEMPLATE = """

View File

@@ -5,10 +5,11 @@ from typing import Any, Dict, Optional, Sequence, Tuple
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.timestamp import timestamp_to_datetime
from zerver.lib.webhooks.common import UnexpectedWebhookEventType, check_send_webhook_message
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile

View File

@@ -4,10 +4,11 @@ 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 UnexpectedWebhookEventType, check_send_webhook_message
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile

View File

@@ -5,9 +5,10 @@ import orjson
from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view, return_success_on_head_request
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.webhooks.common import UnexpectedWebhookEventType, check_send_webhook_message
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile
from .board_actions import SUPPORTED_BOARD_ACTIONS, process_board_action

View File

@@ -5,9 +5,10 @@ from typing import Any, Dict, List
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.webhooks.common import UnexpectedWebhookEventType, check_send_webhook_message
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile
TOPIC_TEMPLATE = "{service_url}"