Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

webhooks: Rename is_webhook to allow_webhook_access.

Alex Vandiverd24869e4844e
diff --git a/zerver/decorator.py b/zerver/decorator.py
index b76beae8708..f63d08cbd73 100644
--- a/zerver/decorator.py
+++ b/zerver/decorator.py
@@ -188,7 +188,7 @@ class InvalidZulipServerKeyError(InvalidZulipServerError):
return "Zulip server auth failure: key does not match role {role}"
def validate_api_key(request: HttpRequest, role: Optional[str],
- api_key: str, is_webhook: bool=False,
+ api_key: str, allow_webhook_access: bool=False,
client_name: Optional[str]=None) -> Union[UserProfile, "RemoteZulipServer"]:
# Remove whitespace to protect users from trivial errors.
api_key = api_key.strip()
@@ -213,7 +213,7 @@ def validate_api_key(request: HttpRequest, role: Optional[str],
return remote_server
user_profile = access_user_by_api_key(request, api_key, email=role)
- if user_profile.is_incoming_webhook and not is_webhook:
+ if user_profile.is_incoming_webhook and not allow_webhook_access:
raise JsonableError(_("This API is not available to incoming webhook bots."))
request.user = user_profile
@@ -285,7 +285,7 @@ def webhook_view(
@wraps(view_func)
def _wrapped_func_arguments(request: HttpRequest, api_key: str=REQ(),
*args: object, **kwargs: object) -> HttpResponse:
- user_profile = validate_api_key(request, None, api_key, is_webhook=True,
+ user_profile = validate_api_key(request, None, api_key, allow_webhook_access=True,
client_name=full_webhook_client_name(webhook_client_name))
if settings.RATE_LIMITING:
@@ -510,7 +510,7 @@ def authenticated_uploads_api_view(
def authenticated_rest_api_view(
*,
webhook_client_name: Optional[str] = None,
- is_webhook: bool = False,
+ allow_webhook_access: bool = False,
skip_rate_limiting: bool = False,
) -> Callable[[Callable[..., HttpResponse]], Callable[..., HttpResponse]]:
def _wrapped_view_func(view_func: Callable[..., HttpResponse]) -> Callable[..., HttpResponse]:
@@ -535,7 +535,7 @@ def authenticated_rest_api_view(
try:
# profile is a Union[UserProfile, RemoteZulipServer]
profile = validate_api_key(request, role, api_key,
- is_webhook=is_webhook or webhook_client_name is not None,
+ allow_webhook_access=allow_webhook_access or webhook_client_name is not None,
client_name=full_webhook_client_name(webhook_client_name))
except JsonableError as e:
return json_unauthorized(e.msg)
@@ -547,7 +547,7 @@ def authenticated_rest_api_view(
target_view_func = view_func
return target_view_func(request, profile, *args, **kwargs)
except Exception as err:
- if is_webhook or webhook_client_name is not None:
+ if allow_webhook_access or webhook_client_name is not None:
if isinstance(err, UnsupportedWebhookEventType) and webhook_client_name is not None:
err.webhook_name = webhook_client_name
request_body = request.POST.get('payload')
diff --git a/zerver/lib/rest.py b/zerver/lib/rest.py
index 0380ae046a4..8487bfbc285 100644
--- a/zerver/lib/rest.py
+++ b/zerver/lib/rest.py
@@ -138,7 +138,7 @@ def rest_dispatch(request: HttpRequest, **kwargs: Any) -> HttpResponse:
# Wrap function with decorator to authenticate the user before
# proceeding
target_function = authenticated_rest_api_view(
- is_webhook='allow_incoming_webhooks' in view_flags,
+ allow_webhook_access='allow_incoming_webhooks' in view_flags,
)(target_function)
elif request.path.startswith("/json") and 'allow_anonymous_user_web' in view_flags:
# For endpoints that support anonymous web access, we do that.
diff --git a/zerver/tests/test_decorators.py b/zerver/tests/test_decorators.py
index 8dd470fe48b..be038c19e3d 100644
--- a/zerver/tests/test_decorators.py
+++ b/zerver/tests/test_decorators.py
@@ -1314,7 +1314,7 @@ class TestValidateApiKey(ZulipTestCase):
api_key = get_api_key(self.webhook_bot)
profile = validate_api_key(HostRequestMock(host="zulip.testserver"),
self.webhook_bot.email, api_key,
- is_webhook=True)
+ allow_webhook_access=True)
self.assertEqual(profile.id, self.webhook_bot.id)
def test_validate_api_key_if_email_is_case_insensitive(self) -> None: