Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
rate_limiter: Use should_rate_limit() for consistent exemption.
The Dance7e1e5ce83b29
diff --git a/zerver/forms.py b/zerver/forms.pyindex 09ea0688457..45b7352d4c2 100644--- a/zerver/forms.py+++ b/zerver/forms.py@@ -33,7 +33,7 @@ from zerver.lib.email_validation import (from zerver.lib.exceptions import JsonableError, RateLimitedErrorfrom zerver.lib.i18n import get_language_listfrom zerver.lib.name_restrictions import is_reserved_subdomain-from zerver.lib.rate_limiter import RateLimitedObject, rate_limit_request_by_ip+from zerver.lib.rate_limiter import RateLimitedObject, rate_limit_request_by_ip, should_rate_limitfrom zerver.lib.subdomains import get_subdomain, is_root_domain_availablefrom zerver.lib.users import check_full_namefrom zerver.models import PreregistrationRealm, Realm, UserProfile@@ -544,7 +544,7 @@ class ZulipPasswordResetForm(PasswordResetForm):logging.info("Realm is deactivated")return- if settings.RATE_LIMITING:+ if should_rate_limit(request):try:rate_limit_password_reset_form_by_email(email)rate_limit_request_by_ip(request, domain="sends_email_by_ip")diff --git a/zerver/views/user_settings.py b/zerver/views/user_settings.pyindex b3611efe820..2336bb493fe 100644--- a/zerver/views/user_settings.py+++ b/zerver/views/user_settings.py@@ -43,7 +43,7 @@ from zerver.lib.email_validation import ()from zerver.lib.exceptions import JsonableError, RateLimitedError, UserDeactivatedErrorfrom zerver.lib.i18n import get_available_language_codes-from zerver.lib.rate_limiter import RateLimitedUser+from zerver.lib.rate_limiter import RateLimitedUser, should_rate_limitfrom zerver.lib.response import json_successfrom zerver.lib.send_email import FromAddress, send_emailfrom zerver.lib.sounds import get_available_notification_sounds@@ -415,11 +415,12 @@ def json_change_settings(if user_profile.delivery_email != new_email:validate_email_change_request(user_profile, new_email)- ratelimited, time_until_free = RateLimitedUser(- user_profile, domain="email_change_by_user"- ).rate_limit()- if ratelimited:- raise RateLimitedError(time_until_free)+ if should_rate_limit(request):+ ratelimited, time_until_free = RateLimitedUser(+ user_profile, domain="email_change_by_user"+ ).rate_limit()+ if ratelimited:+ raise RateLimitedError(time_until_free)do_start_email_change_process(user_profile, new_email)diff --git a/zerver/views/users.py b/zerver/views/users.pyindex af10ba70862..28f1d1bec5a 100644--- a/zerver/views/users.py+++ b/zerver/views/users.py@@ -52,7 +52,10 @@ from zerver.lib.exceptions import (OrganizationOwnerRequiredError,)from zerver.lib.integrations import EMBEDDED_BOTS-from zerver.lib.rate_limiter import rate_limit_spectator_attachment_access_by_file+from zerver.lib.rate_limiter import (+ rate_limit_spectator_attachment_access_by_file,+ should_rate_limit,+)from zerver.lib.response import json_successfrom zerver.lib.send_email import FromAddress, send_emailfrom zerver.lib.streams import access_stream_by_id, access_stream_by_name, subscribed_to_stream@@ -353,7 +356,7 @@ def avatar_by_id(if not realm.allow_web_public_streams_access():raise MissingAuthenticationError- if settings.RATE_LIMITING:+ if should_rate_limit(request):unique_avatar_key = f"{realm.id}/{user_id}/{medium}"rate_limit_spectator_attachment_access_by_file(unique_avatar_key)else: