diff --git a/analytics/views/stats.py b/analytics/views/stats.py index c6fe90ae2e..c19d493790 100644 --- a/analytics/views/stats.py +++ b/analytics/views/stats.py @@ -410,7 +410,7 @@ def get_chart_data( data["display_order"] = labels_sort_function(data) else: data["display_order"] = None - return json_success(data=data) + return json_success(request, data=data) def sort_by_totals(value_arrays: Dict[str, List[int]]) -> List[str]: diff --git a/corporate/views/billing_page.py b/corporate/views/billing_page.py index 3dad1ea04d..f4b9f58c60 100644 --- a/corporate/views/billing_page.py +++ b/corporate/views/billing_page.py @@ -198,7 +198,7 @@ def update_plan( elif status == CustomerPlan.ENDED: assert plan.is_free_trial() downgrade_now_without_creating_additional_invoices(user.realm) - return json_success() + return json_success(request) if licenses is not None: if plan.automanage_licenses: @@ -221,7 +221,7 @@ def update_plan( ) validate_licenses(plan.charge_automatically, licenses, get_latest_seat_count(user.realm)) update_license_ledger_for_manual_plan(plan, timezone_now(), licenses=licenses) - return json_success() + return json_success(request) if licenses_at_next_renewal is not None: if plan.automanage_licenses: @@ -244,6 +244,6 @@ def update_plan( update_license_ledger_for_manual_plan( plan, timezone_now(), licenses_at_next_renewal=licenses_at_next_renewal ) - return json_success() + return json_success(request) raise JsonableError(_("Nothing to change.")) diff --git a/corporate/views/event_status.py b/corporate/views/event_status.py index 1f9a02f6be..805fec0f50 100644 --- a/corporate/views/event_status.py +++ b/corporate/views/event_status.py @@ -35,7 +35,7 @@ def event_status( if session.type == Session.CARD_UPDATE_FROM_BILLING_PAGE and not user.has_billing_access: raise JsonableError(_("Must be a billing administrator or an organization owner")) - return json_success(data={"session": session.to_dict()}) + return json_success(request, data={"session": session.to_dict()}) if stripe_payment_intent_id is not None: payment_intent = PaymentIntent.objects.filter( @@ -45,7 +45,7 @@ def event_status( if payment_intent is None: raise JsonableError(_("Payment intent not found")) - return json_success(data={"payment_intent": payment_intent.to_dict()}) + return json_success(request, data={"payment_intent": payment_intent.to_dict()}) raise JsonableError(_("Pass stripe_session_id or stripe_payment_intent_id")) diff --git a/corporate/views/session.py b/corporate/views/session.py index df92a37acc..65bed90c84 100644 --- a/corporate/views/session.py +++ b/corporate/views/session.py @@ -37,10 +37,11 @@ def start_card_update_stripe_session(request: HttpRequest, user: UserProfile) -> type=Session.CARD_UPDATE_FROM_BILLING_PAGE, ) return json_success( + request, data={ "stripe_session_url": stripe_session.url, "stripe_session_id": stripe_session.id, - } + }, ) @@ -93,8 +94,9 @@ def start_retry_payment_intent_session( session.save(update_fields=["payment_intent"]) session.save() return json_success( + request, data={ "stripe_session_id": stripe_session.id, "stripe_session_url": stripe_session.url, - } + }, ) diff --git a/corporate/views/upgrade.py b/corporate/views/upgrade.py index 3b388bc9a8..f2f5c38d0e 100644 --- a/corporate/views/upgrade.py +++ b/corporate/views/upgrade.py @@ -192,10 +192,11 @@ def upgrade( onboarding, ) return json_success( + request, data={ "stripe_session_url": stripe_checkout_session.url, "stripe_session_id": stripe_checkout_session.id, - } + }, ) else: process_initial_upgrade( @@ -206,7 +207,7 @@ def upgrade( False, is_free_trial_offer_enabled(), ) - return json_success(data={}) + return json_success(request) except BillingError as e: billing_logger.warning( @@ -357,7 +358,7 @@ def sponsorship( context=context, ) - return json_success() + return json_success(request) else: messages = [] for error_list in form.errors.get_json_data().values(): diff --git a/zerver/decorator.py b/zerver/decorator.py index b16430316b..8ee18edc24 100644 --- a/zerver/decorator.py +++ b/zerver/decorator.py @@ -1000,7 +1000,7 @@ def return_success_on_head_request(view_func: ViewFuncT) -> ViewFuncT: @wraps(view_func) def _wrapped_view_func(request: HttpRequest, *args: object, **kwargs: object) -> HttpResponse: if request.method == "HEAD": - return json_success() + return json_success(request) return view_func(request, *args, **kwargs) return cast(ViewFuncT, _wrapped_view_func) # https://github.com/python/mypy/issues/1927 diff --git a/zerver/lib/response.py b/zerver/lib/response.py index 512d79b686..9bddd228cd 100644 --- a/zerver/lib/response.py +++ b/zerver/lib/response.py @@ -1,7 +1,7 @@ from typing import Any, List, Mapping, Optional import orjson -from django.http import HttpResponse, HttpResponseNotAllowed +from django.http import HttpRequest, HttpResponse, HttpResponseNotAllowed from django.utils.translation import gettext as _ from zerver.lib.exceptions import JsonableError @@ -60,7 +60,7 @@ def json_response( ) -def json_success(data: Mapping[str, Any] = {}) -> HttpResponse: +def json_success(request: HttpRequest, data: Mapping[str, Any] = {}) -> HttpResponse: return json_response(data=data) diff --git a/zerver/tests/test_decorators.py b/zerver/tests/test_decorators.py index bb862a5c38..20d1d4ae49 100644 --- a/zerver/tests/test_decorators.py +++ b/zerver/tests/test_decorators.py @@ -395,11 +395,11 @@ class SkipRateLimitingTest(ZulipTestCase): def test_authenticated_rest_api_view(self) -> None: @authenticated_rest_api_view(skip_rate_limiting=False) def my_rate_limited_view(request: HttpRequest, user_profile: UserProfile) -> HttpResponse: - return json_success() # nocoverage # mock prevents this from being called + return json_success(request) # nocoverage # mock prevents this from being called @authenticated_rest_api_view(skip_rate_limiting=True) def my_unlimited_view(request: HttpRequest, user_profile: UserProfile) -> HttpResponse: - return json_success() + return json_success(request) request = HostRequestMock(host="zulip.testserver") request.META["HTTP_AUTHORIZATION"] = self.encode_email(self.example_email("hamlet")) @@ -418,11 +418,11 @@ class SkipRateLimitingTest(ZulipTestCase): def test_authenticated_uploads_api_view(self) -> None: @authenticated_uploads_api_view(skip_rate_limiting=False) def my_rate_limited_view(request: HttpRequest, user_profile: UserProfile) -> HttpResponse: - return json_success() # nocoverage # mock prevents this from being called + return json_success(request) # nocoverage # mock prevents this from being called @authenticated_uploads_api_view(skip_rate_limiting=True) def my_unlimited_view(request: HttpRequest, user_profile: UserProfile) -> HttpResponse: - return json_success() + return json_success(request) request = HostRequestMock(host="zulip.testserver") request.method = "POST" @@ -440,7 +440,7 @@ class SkipRateLimitingTest(ZulipTestCase): def test_authenticated_json_view(self) -> None: def my_view(request: HttpRequest, user_profile: UserProfile) -> HttpResponse: - return json_success() + return json_success(request) my_rate_limited_view = authenticated_json_view(my_view, skip_rate_limiting=False) my_unlimited_view = authenticated_json_view(my_view, skip_rate_limiting=True) diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.py index 4837f80375..cb7dde914d 100644 --- a/zerver/tests/test_subs.py +++ b/zerver/tests/test_subs.py @@ -3516,7 +3516,7 @@ class SubscriptionRestApiTest(ZulipTestCase): def thunk1() -> HttpResponse: user_profile.full_name = "Should not be committed" user_profile.save() - return json_success() + return json_success(request) def thunk2() -> HttpResponse: raise JsonableError("random failure") diff --git a/zerver/tornado/views.py b/zerver/tornado/views.py index c51e245959..c800090bb4 100644 --- a/zerver/tornado/views.py +++ b/zerver/tornado/views.py @@ -24,7 +24,7 @@ from zerver.tornado.exceptions import BadEventQueueIdError @internal_notify_view(True) def notify(request: HttpRequest) -> HttpResponse: process_notification(orjson.loads(request.POST["data"])) - return json_success() + return json_success(request) @has_request_variables @@ -40,7 +40,7 @@ def cleanup_event_queue( assert log_data is not None log_data["extra"] = f"[{queue_id}]" client.cleanup() - return json_success() + return json_success(request) @internal_notify_view(True) @@ -164,9 +164,9 @@ def get_events_backend( # Tornado discarding the response and instead long-polling the # request. See zulip_finish for more design details. handler._request = request - response = json_success() + response = json_success(request) response.asynchronous = True return response if result["type"] == "error": raise result["exception"] - return json_success(result["response"]) + return json_success(request, data=result["response"]) diff --git a/zerver/views/alert_words.py b/zerver/views/alert_words.py index 4a0f707e13..3178921772 100644 --- a/zerver/views/alert_words.py +++ b/zerver/views/alert_words.py @@ -11,7 +11,7 @@ from zerver.models import UserProfile def list_alert_words(request: HttpRequest, user_profile: UserProfile) -> HttpResponse: - return json_success({"alert_words": user_alert_words(user_profile)}) + return json_success(request, data={"alert_words": user_alert_words(user_profile)}) def clean_alert_words(alert_words: List[str]) -> List[str]: @@ -26,7 +26,7 @@ def add_alert_words( alert_words: List[str] = REQ(json_validator=check_list(check_capped_string(100))), ) -> HttpResponse: do_add_alert_words(user_profile, clean_alert_words(alert_words)) - return json_success({"alert_words": user_alert_words(user_profile)}) + return json_success(request, data={"alert_words": user_alert_words(user_profile)}) @has_request_variables @@ -36,4 +36,4 @@ def remove_alert_words( alert_words: List[str] = REQ(json_validator=check_list(check_string)), ) -> HttpResponse: do_remove_alert_words(user_profile, alert_words) - return json_success({"alert_words": user_alert_words(user_profile)}) + return json_success(request, data={"alert_words": user_alert_words(user_profile)}) diff --git a/zerver/views/attachments.py b/zerver/views/attachments.py index c9c14167a8..8b10ce7584 100644 --- a/zerver/views/attachments.py +++ b/zerver/views/attachments.py @@ -8,10 +8,11 @@ from zerver.models import UserProfile def list_by_user(request: HttpRequest, user_profile: UserProfile) -> HttpResponse: return json_success( - { + request, + data={ "attachments": user_attachments(user_profile), "upload_space_used": user_profile.realm.currently_used_upload_space_bytes(), - } + }, ) @@ -19,4 +20,4 @@ def remove(request: HttpRequest, user_profile: UserProfile, attachment_id: str) attachment = access_attachment_by_id(user_profile, int(attachment_id), needs_owner=True) remove_attachment(user_profile, attachment) notify_attachment_update(user_profile, "remove", {"id": int(attachment_id)}) - return json_success() + return json_success(request) diff --git a/zerver/views/auth.py b/zerver/views/auth.py index 501848c15f..be03e0d1fb 100644 --- a/zerver/views/auth.py +++ b/zerver/views/auth.py @@ -898,7 +898,7 @@ def api_fetch_api_key( RequestNotes.get_notes(request).requestor_for_logs = user_profile.format_requestor_for_logs() api_key = get_api_key(user_profile) - return json_success({"api_key": api_key, "email": user_profile.delivery_email}) + return json_success(request, data={"api_key": api_key, "email": user_profile.delivery_email}) def get_auth_backends_data(request: HttpRequest) -> Dict[str, Any]: @@ -963,7 +963,7 @@ def api_get_server_settings(request: HttpRequest) -> HttpResponse: ]: if context[settings_item] is not None: result[settings_item] = context[settings_item] - return json_success(result) + return json_success(request, data=result) @has_request_variables @@ -980,7 +980,7 @@ def json_fetch_api_key( raise JsonableError(_("Password is incorrect.")) api_key = get_api_key(user_profile) - return json_success({"api_key": api_key, "email": user_profile.delivery_email}) + return json_success(request, data={"api_key": api_key, "email": user_profile.delivery_email}) @require_post diff --git a/zerver/views/compatibility.py b/zerver/views/compatibility.py index 7ee1fa866f..97c080ce66 100644 --- a/zerver/views/compatibility.py +++ b/zerver/views/compatibility.py @@ -27,4 +27,4 @@ def check_global_compatibility(request: HttpRequest) -> HttpResponse: user_os = find_mobile_os(request.META["HTTP_USER_AGENT"]) if user_os == "android" and version_lt(user_agent["version"], android_min_app_version): raise JsonableError(legacy_compatibility_error_message) - return json_success() + return json_success(request) diff --git a/zerver/views/custom_profile_fields.py b/zerver/views/custom_profile_fields.py index adba3fd492..67f25bb5fe 100644 --- a/zerver/views/custom_profile_fields.py +++ b/zerver/views/custom_profile_fields.py @@ -38,7 +38,7 @@ def list_realm_custom_profile_fields( request: HttpRequest, user_profile: UserProfile ) -> HttpResponse: fields = custom_profile_fields_for_realm(user_profile.realm_id) - return json_success({"custom_fields": [f.as_dict() for f in fields]}) + return json_success(request, data={"custom_fields": [f.as_dict() for f in fields]}) hint_validator = check_capped_string(CustomProfileField.HINT_MAX_LENGTH) @@ -113,7 +113,7 @@ def create_realm_custom_profile_field( realm=user_profile.realm, field_subtype=field_subtype, ) - return json_success({"id": field.id}) + return json_success(request, data={"id": field.id}) else: field = try_add_realm_custom_profile_field( realm=user_profile.realm, @@ -122,7 +122,7 @@ def create_realm_custom_profile_field( field_type=field_type, hint=hint, ) - return json_success({"id": field.id}) + return json_success(request, data={"id": field.id}) except IntegrityError: raise JsonableError(_("A field with that label already exists.")) @@ -137,7 +137,7 @@ def delete_realm_custom_profile_field( raise JsonableError(_("Field id {id} not found.").format(id=field_id)) do_remove_realm_custom_profile_field(realm=user_profile.realm, field=field) - return json_success() + return json_success(request) @require_realm_admin @@ -165,7 +165,7 @@ def update_realm_custom_profile_field( try_update_realm_custom_profile_field(realm, field, name, hint=hint, field_data=field_data) except IntegrityError: raise JsonableError(_("A field with that label already exists.")) - return json_success() + return json_success(request) @require_realm_admin @@ -176,7 +176,7 @@ def reorder_realm_custom_profile_fields( order: List[int] = REQ(json_validator=check_list(check_int)), ) -> HttpResponse: try_reorder_realm_custom_profile_fields(user_profile.realm, order) - return json_success() + return json_success(request) @human_users_only @@ -188,7 +188,7 @@ def remove_user_custom_profile_data( ) -> HttpResponse: for field_id in data: check_remove_custom_profile_field_value(user_profile, field_id) - return json_success() + return json_success(request) @human_users_only @@ -211,4 +211,4 @@ def update_user_custom_profile_data( validate_user_custom_profile_data(user_profile.realm.id, data) do_update_user_custom_profile_data_if_changed(user_profile, data) # We need to call this explicitly otherwise constraints are not check - return json_success() + return json_success(request) diff --git a/zerver/views/development/cache.py b/zerver/views/development/cache.py index 23e8b0a399..08a08c60f1 100644 --- a/zerver/views/development/cache.py +++ b/zerver/views/development/cache.py @@ -18,4 +18,4 @@ def remove_caches(request: HttpRequest) -> HttpResponse: cache.clear() clear_client_cache() flush_per_request_caches() - return json_success() + return json_success(request) diff --git a/zerver/views/development/dev_login.py b/zerver/views/development/dev_login.py index 5499263a8b..6004db9799 100644 --- a/zerver/views/development/dev_login.py +++ b/zerver/views/development/dev_login.py @@ -135,7 +135,7 @@ def api_dev_fetch_api_key(request: HttpRequest, username: str = REQ()) -> HttpRe do_login(request, user_profile) api_key = get_api_key(user_profile) - return json_success({"api_key": api_key, "email": user_profile.delivery_email}) + return json_success(request, data={"api_key": api_key, "email": user_profile.delivery_email}) @csrf_exempt @@ -144,7 +144,8 @@ def api_dev_list_users(request: HttpRequest) -> HttpResponse: users = get_dev_users() return json_success( - dict( + request, + data=dict( direct_admins=[ dict(email=u.delivery_email, realm_uri=u.realm.uri) for u in users @@ -155,5 +156,5 @@ def api_dev_list_users(request: HttpRequest) -> HttpResponse: for u in users if not u.is_realm_admin ], - ) + ), ) diff --git a/zerver/views/development/email_log.py b/zerver/views/development/email_log.py index f99a414b6e..20f5f31ca4 100755 --- a/zerver/views/development/email_log.py +++ b/zerver/views/development/email_log.py @@ -25,7 +25,7 @@ ZULIP_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../") def email_page(request: HttpRequest) -> HttpResponse: if request.method == "POST": set_forward_address(request.POST["forward_address"]) - return json_success() + return json_success(request) try: with open(settings.EMAIL_CONTENT_LOG_PATH, "r+") as f: content = f.read() diff --git a/zerver/views/development/integrations.py b/zerver/views/development/integrations.py index 0a00976353..32c0bd88a9 100644 --- a/zerver/views/development/integrations.py +++ b/zerver/views/development/integrations.py @@ -91,7 +91,7 @@ def get_fixtures(request: HttpResponse, integration_name: str = REQ()) -> HttpRe headers = {fix_name(k): v for k, v in headers_raw.items()} fixtures[fixture] = {"body": body, "headers": headers} - return json_success({"fixtures": fixtures}) + return json_success(request, data={"fixtures": fixtures}) @has_request_variables @@ -110,7 +110,7 @@ def check_send_webhook_fixture_message( response = send_webhook_fixture_message(url, body, is_json, custom_headers_dict) if response.status_code == 200: responses = [{"status_code": response.status_code, "message": response.content.decode()}] - return json_success({"responses": responses}) + return json_success(request, data={"responses": responses}) else: return response @@ -150,4 +150,4 @@ def send_all_webhook_fixture_messages( "message": response.content.decode(), } ) - return json_success({"responses": responses}) + return json_success(request, data={"responses": responses}) diff --git a/zerver/views/development/registration.py b/zerver/views/development/registration.py index 8524a6bcfa..13d1bf0b15 100644 --- a/zerver/views/development/registration.py +++ b/zerver/views/development/registration.py @@ -16,7 +16,7 @@ from zerver.views.registration import accounts_register # This is used only by the Puppeteer test in 01-realm-creation.js. def confirmation_key(request: HttpRequest) -> HttpResponse: - return json_success(request.session.get("confirmation_key")) + return json_success(request, data=request.session.get("confirmation_key")) def modify_postdata(request: HttpRequest, **kwargs: Any) -> None: diff --git a/zerver/views/drafts.py b/zerver/views/drafts.py index b014fdb2cd..33ba4ffc5e 100644 --- a/zerver/views/drafts.py +++ b/zerver/views/drafts.py @@ -19,7 +19,7 @@ from zerver.models import Draft, UserProfile def fetch_drafts(request: HttpRequest, user_profile: UserProfile) -> HttpResponse: user_drafts = Draft.objects.filter(user_profile=user_profile).order_by("last_edit_time") draft_dicts = [draft.to_dict() for draft in user_drafts] - return json_success({"count": user_drafts.count(), "drafts": draft_dicts}) + return json_success(request, data={"count": user_drafts.count(), "drafts": draft_dicts}) @draft_endpoint @@ -33,7 +33,7 @@ def create_drafts( ) -> HttpResponse: created_draft_objects = do_create_drafts(draft_dicts, user_profile) draft_ids = [draft_object.id for draft_object in created_draft_objects] - return json_success({"ids": draft_ids}) + return json_success(request, data={"ids": draft_ids}) @draft_endpoint @@ -45,10 +45,10 @@ def edit_draft( draft_dict: Dict[str, Any] = REQ("draft", json_validator=draft_dict_validator), ) -> HttpResponse: do_edit_draft(draft_id, draft_dict, user_profile) - return json_success() + return json_success(request) @draft_endpoint def delete_draft(request: HttpRequest, user_profile: UserProfile, draft_id: int) -> HttpResponse: do_delete_draft(draft_id, user_profile) - return json_success() + return json_success(request) diff --git a/zerver/views/email_mirror.py b/zerver/views/email_mirror.py index be46882666..65cb7b9fb8 100644 --- a/zerver/views/email_mirror.py +++ b/zerver/views/email_mirror.py @@ -17,4 +17,4 @@ def email_mirror_message( result = mirror_email_message(rcpt_to, msg_base64) if result["status"] == "error": raise JsonableError(result["msg"]) - return json_success() + return json_success(request) diff --git a/zerver/views/events_register.py b/zerver/views/events_register.py index 45e9d6f274..1851ae4b2b 100644 --- a/zerver/views/events_register.py +++ b/zerver/views/events_register.py @@ -97,4 +97,4 @@ def events_register_backend( client_capabilities=client_capabilities, fetch_event_types=fetch_event_types, ) - return json_success(ret) + return json_success(request, data=ret) diff --git a/zerver/views/hotspots.py b/zerver/views/hotspots.py index 234f0d2571..da0c1b43dc 100644 --- a/zerver/views/hotspots.py +++ b/zerver/views/hotspots.py @@ -18,4 +18,4 @@ def mark_hotspot_as_read( if hotspot not in ALL_HOTSPOTS: raise JsonableError(_("Unknown hotspot: {}").format(hotspot)) do_mark_hotspot_as_read(user, hotspot) - return json_success() + return json_success(request) diff --git a/zerver/views/invite.py b/zerver/views/invite.py index 7ede560d27..6cc522a4d9 100644 --- a/zerver/views/invite.py +++ b/zerver/views/invite.py @@ -83,7 +83,7 @@ def invite_users_backend( invite_expires_in_days=invite_expires_in_days, invite_as=invite_as, ) - return json_success() + return json_success(request) def get_invitee_emails_set(invitee_emails_raw: str) -> Set[str]: @@ -100,7 +100,7 @@ def get_invitee_emails_set(invitee_emails_raw: str) -> Set[str]: @require_member_or_admin def get_user_invites(request: HttpRequest, user_profile: UserProfile) -> HttpResponse: all_users = do_get_invites_controlled_by_user(user_profile) - return json_success({"invites": all_users}) + return json_success(request, data={"invites": all_users}) @require_member_or_admin @@ -122,7 +122,7 @@ def revoke_user_invite( raise JsonableError(_("Must be an organization administrator")) do_revoke_user_invite(prereg_user) - return json_success() + return json_success(request) @require_realm_admin @@ -142,7 +142,7 @@ def revoke_multiuse_invite( check_if_owner_required(invite.invited_as, user_profile) do_revoke_multi_use_invite(invite) - return json_success() + return json_success(request) @require_member_or_admin @@ -166,7 +166,7 @@ def resend_user_invite_email( raise JsonableError(_("Must be an organization administrator")) timestamp = do_resend_user_invite_email(prereg_user) - return json_success({"timestamp": timestamp}) + return json_success(request, data={"timestamp": timestamp}) @require_realm_admin @@ -193,4 +193,4 @@ def generate_multiuse_invite_backend( invite_link = do_create_multiuse_invite_link( user_profile, invite_as, invite_expires_in_days, streams ) - return json_success({"invite_link": invite_link}) + return json_success(request, data={"invite_link": invite_link}) diff --git a/zerver/views/message_edit.py b/zerver/views/message_edit.py index 0bf0ef4374..0ad0f03621 100644 --- a/zerver/views/message_edit.py +++ b/zerver/views/message_edit.py @@ -87,7 +87,7 @@ def get_message_edit_history( # Fill in all the extra data that will make it usable fill_edit_history_entries(message_edit_history, message) - return json_success({"message_history": list(reversed(message_edit_history))}) + return json_success(request, data={"message_history": list(reversed(message_edit_history))}) PROPAGATE_MODE_VALUES = ["change_later", "change_one", "change_all"] @@ -123,7 +123,7 @@ def update_message_backend( assert log_data is not None log_data["extra"] = f"[{number_changed}]" - return json_success() + return json_success(request) def validate_can_delete_message(user_profile: UserProfile, message: Message) -> None: @@ -164,7 +164,7 @@ def delete_message_backend( do_delete_messages(user_profile.realm, [message]) except (Message.DoesNotExist, IntegrityError): raise JsonableError(_("Message already deleted")) - return json_success() + return json_success(request) @has_request_variables @@ -180,4 +180,4 @@ def json_fetch_raw_message( else: (message, user_message) = access_message(maybe_user_profile, message_id) - return json_success({"raw_content": message.content}) + return json_success(request, data={"raw_content": message.content}) diff --git a/zerver/views/message_fetch.py b/zerver/views/message_fetch.py index f0457e397f..c18513b696 100644 --- a/zerver/views/message_fetch.py +++ b/zerver/views/message_fetch.py @@ -1168,7 +1168,7 @@ def get_messages_backend( history_limited=query_info["history_limited"], anchor=anchor, ) - return json_success(ret) + return json_success(request, data=ret) def limit_query_to_range( @@ -1372,4 +1372,4 @@ def messages_in_narrow_backend( topic_matches, ) - return json_success({"messages": search_fields}) + return json_success(request, data={"messages": search_fields}) diff --git a/zerver/views/message_flags.py b/zerver/views/message_flags.py index 6c14490c76..8e3660edf9 100644 --- a/zerver/views/message_flags.py +++ b/zerver/views/message_flags.py @@ -45,7 +45,7 @@ def update_message_flags( log_data_str = f"[{operation} {flag}/{target_count_str}] actually {count}" request_notes.log_data["extra"] = log_data_str - return json_success({"result": "success", "messages": messages, "msg": ""}) + return json_success(request, data={"messages": messages}) @has_request_variables @@ -58,7 +58,7 @@ def mark_all_as_read(request: HttpRequest, user_profile: UserProfile) -> HttpRes assert request_notes.log_data is not None request_notes.log_data["extra"] = log_data_str - return json_success({"result": "success", "msg": ""}) + return json_success(request) @has_request_variables @@ -73,7 +73,7 @@ def mark_stream_as_read( assert log_data is not None log_data["extra"] = log_data_str - return json_success({"result": "success", "msg": ""}) + return json_success(request) @has_request_variables @@ -102,4 +102,4 @@ def mark_topic_as_read( assert log_data is not None log_data["extra"] = log_data_str - return json_success({"result": "success", "msg": ""}) + return json_success(request) diff --git a/zerver/views/message_send.py b/zerver/views/message_send.py index 9d967bb37a..a3bdba1c3c 100644 --- a/zerver/views/message_send.py +++ b/zerver/views/message_send.py @@ -297,7 +297,7 @@ def send_message_backend( forwarder_user_profile=user_profile, realm=realm, ) - return json_success(data={"deliver_at": deliver_at}) + return json_success(request, data={"deliver_at": deliver_at}) ret = check_send_message( sender, @@ -314,14 +314,14 @@ def send_message_backend( sender_queue_id=queue_id, widget_content=widget_content, ) - return json_success({"id": ret}) + return json_success(request, data={"id": ret}) @has_request_variables def zcommand_backend( request: HttpRequest, user_profile: UserProfile, command: str = REQ("command") ) -> HttpResponse: - return json_success(process_zcommands(command, user_profile)) + return json_success(request, data=process_zcommands(command, user_profile)) @has_request_variables @@ -336,4 +336,4 @@ def render_message_backend( message.sending_client = client rendering_result = render_markdown(message, content, realm=user_profile.realm) - return json_success({"rendered": rendering_result.rendered_content}) + return json_success(request, data={"rendered": rendering_result.rendered_content}) diff --git a/zerver/views/muting.py b/zerver/views/muting.py index f12e5a9c82..0dfa4db272 100644 --- a/zerver/views/muting.py +++ b/zerver/views/muting.py @@ -79,7 +79,7 @@ def update_muted_topic( topic_name=topic, date_muted=timezone_now(), ) - return json_success() + return json_success(request) elif op == "remove": unmute_topic( user_profile=user_profile, @@ -87,7 +87,7 @@ def update_muted_topic( stream_name=stream, topic_name=topic, ) - return json_success() + return json_success(request) def mute_user(request: HttpRequest, user_profile: UserProfile, muted_user_id: int) -> HttpResponse: @@ -103,7 +103,7 @@ def mute_user(request: HttpRequest, user_profile: UserProfile, muted_user_id: in raise JsonableError(_("User already muted")) do_mute_user(user_profile, muted_user, date_muted) - return json_success() + return json_success(request) def unmute_user( @@ -118,4 +118,4 @@ def unmute_user( raise JsonableError(_("User is not muted")) do_unmute_user(mute_object) - return json_success() + return json_success(request) diff --git a/zerver/views/presence.py b/zerver/views/presence.py index 0b88318ff9..869c259bca 100644 --- a/zerver/views/presence.py +++ b/zerver/views/presence.py @@ -60,7 +60,7 @@ def get_presence_backend( for val in result["presence"].values(): val.pop("client", None) val.pop("pushable", None) - return json_success(result) + return json_success(request, data=result) @human_users_only @@ -126,7 +126,7 @@ def update_user_status_backend( reaction_type=emoji_type, ) - return json_success() + return json_success(request) @human_users_only @@ -167,11 +167,11 @@ def update_active_status_backend( except UserActivity.DoesNotExist: ret["zephyr_mirror_active"] = False - return json_success(ret) + return json_success(request, data=ret) def get_statuses_for_realm(request: HttpRequest, user_profile: UserProfile) -> HttpResponse: # This isn't used by the web app; it's available for API use by # bots and other clients. We may want to add slim_presence # support for it (or just migrate its API wholesale) later. - return json_success(get_presence_response(user_profile, slim_presence=False)) + return json_success(request, data=get_presence_response(user_profile, slim_presence=False)) diff --git a/zerver/views/push_notifications.py b/zerver/views/push_notifications.py index e8f2ff4e4a..d89e56f223 100644 --- a/zerver/views/push_notifications.py +++ b/zerver/views/push_notifications.py @@ -35,7 +35,7 @@ def add_apns_device_token( ) -> HttpResponse: validate_token(token, PushDeviceToken.APNS) add_push_device_token(user_profile, token, PushDeviceToken.APNS, ios_app_id=appid) - return json_success() + return json_success(request) @human_users_only @@ -45,7 +45,7 @@ def add_android_reg_id( ) -> HttpResponse: validate_token(token, PushDeviceToken.GCM) add_push_device_token(user_profile, token, PushDeviceToken.GCM) - return json_success() + return json_success(request) @human_users_only @@ -55,7 +55,7 @@ def remove_apns_device_token( ) -> HttpResponse: validate_token(token, PushDeviceToken.APNS) remove_push_device_token(user_profile, token, PushDeviceToken.APNS) - return json_success() + return json_success(request) @human_users_only @@ -65,4 +65,4 @@ def remove_android_reg_id( ) -> HttpResponse: validate_token(token, PushDeviceToken.GCM) remove_push_device_token(user_profile, token, PushDeviceToken.GCM) - return json_success() + return json_success(request) diff --git a/zerver/views/reactions.py b/zerver/views/reactions.py index 3d66396fee..a1fd401433 100644 --- a/zerver/views/reactions.py +++ b/zerver/views/reactions.py @@ -26,7 +26,7 @@ def add_reaction( ) -> HttpResponse: check_add_reaction(user_profile, message_id, emoji_name, emoji_code, reaction_type) - return json_success() + return json_success(request) # transaction.atomic is required since we use FOR UPDATE queries in access_message @@ -77,4 +77,4 @@ def remove_reaction( # deactivated by an administrator in the meantime). do_remove_reaction(user_profile, message, emoji_code, reaction_type) - return json_success() + return json_success(request) diff --git a/zerver/views/realm.py b/zerver/views/realm.py index 8dbff794b7..322bdec9ea 100644 --- a/zerver/views/realm.py +++ b/zerver/views/realm.py @@ -294,7 +294,7 @@ def update_realm( do_change_realm_subdomain(realm, string_id, acting_user=user_profile) data["realm_uri"] = realm.uri - return json_success(data) + return json_success(request, data) @require_realm_owner @@ -302,16 +302,16 @@ def update_realm( def deactivate_realm(request: HttpRequest, user: UserProfile) -> HttpResponse: realm = user.realm do_deactivate_realm(realm, acting_user=user) - return json_success() + return json_success(request) @require_safe def check_subdomain_available(request: HttpRequest, subdomain: str) -> HttpResponse: try: check_subdomain(subdomain) - return json_success({"msg": "available"}) + return json_success(request, data={"msg": "available"}) except ValidationError as e: - return json_success({"msg": e.message}) + return json_success(request, data={"msg": e.message}) def realm_reactivation(request: HttpRequest, confirmation_key: str) -> HttpResponse: @@ -426,4 +426,4 @@ def update_realm_user_settings_defaults( if len(request_notes.ignored_parameters) > 0: result["ignored_parameters_unsupported"] = list(request_notes.ignored_parameters) - return json_success(result) + return json_success(request, data=result) diff --git a/zerver/views/realm_domains.py b/zerver/views/realm_domains.py index 5525a8f23d..527923f025 100644 --- a/zerver/views/realm_domains.py +++ b/zerver/views/realm_domains.py @@ -14,7 +14,7 @@ from zerver.models import RealmDomain, UserProfile, get_realm_domains def list_realm_domains(request: HttpRequest, user_profile: UserProfile) -> HttpResponse: domains = get_realm_domains(user_profile.realm) - return json_success({"domains": domains}) + return json_success(request, data={"domains": domains}) @require_realm_admin @@ -35,7 +35,7 @@ def create_realm_domain( _("The domain {domain} is already a part of your organization.").format(domain=domain) ) realm_domain = do_add_realm_domain(user_profile.realm, domain, allow_subdomains) - return json_success({"new_domain": [realm_domain.id, realm_domain.domain]}) + return json_success(request, data={"new_domain": [realm_domain.id, realm_domain.domain]}) @require_realm_admin @@ -51,7 +51,7 @@ def patch_realm_domain( do_change_realm_domain(realm_domain, allow_subdomains) except RealmDomain.DoesNotExist: raise JsonableError(_("No entry found for domain {domain}.").format(domain=domain)) - return json_success() + return json_success(request) @require_realm_admin @@ -64,4 +64,4 @@ def delete_realm_domain( do_remove_realm_domain(realm_domain, acting_user=user_profile) except RealmDomain.DoesNotExist: raise JsonableError(_("No entry found for domain {domain}.").format(domain=domain)) - return json_success() + return json_success(request) diff --git a/zerver/views/realm_emoji.py b/zerver/views/realm_emoji.py index 6595fa140d..29e03c2d69 100644 --- a/zerver/views/realm_emoji.py +++ b/zerver/views/realm_emoji.py @@ -15,7 +15,7 @@ def list_emoji(request: HttpRequest, user_profile: UserProfile) -> HttpResponse: # We don't do any checks here because the list of realm # emoji is public. - return json_success({"emoji": user_profile.realm.get_emoji()}) + return json_success(request, data={"emoji": user_profile.realm.get_emoji()}) @require_member_or_admin @@ -50,7 +50,7 @@ def upload_emoji( realm_emoji = check_add_realm_emoji(user_profile.realm, emoji_name, user_profile, emoji_file) if realm_emoji is None: raise JsonableError(_("Image file upload failed.")) - return json_success() + return json_success(request) def delete_emoji(request: HttpRequest, user_profile: UserProfile, emoji_name: str) -> HttpResponse: @@ -60,4 +60,4 @@ def delete_emoji(request: HttpRequest, user_profile: UserProfile, emoji_name: st raise JsonableError(_("Emoji '{}' does not exist").format(emoji_name)) check_remove_custom_emoji(user_profile, emoji_name) do_remove_realm_emoji(user_profile.realm, emoji_name) - return json_success() + return json_success(request) diff --git a/zerver/views/realm_export.py b/zerver/views/realm_export.py index 50118c31fa..727f1fc472 100644 --- a/zerver/views/realm_export.py +++ b/zerver/views/realm_export.py @@ -73,13 +73,13 @@ def export_realm(request: HttpRequest, user: UserProfile) -> HttpResponse: "id": row.id, } queue_json_publish("deferred_work", event) - return json_success() + return json_success(request) @require_realm_admin def get_realm_exports(request: HttpRequest, user: UserProfile) -> HttpResponse: realm_exports = get_realm_exports_serialized(user) - return json_success({"exports": realm_exports}) + return json_success(request, data={"exports": realm_exports}) @require_realm_admin @@ -95,4 +95,4 @@ def delete_realm_export(request: HttpRequest, user: UserProfile, export_id: int) if "deleted_timestamp" in export_data: raise JsonableError(_("Export already deleted")) do_delete_realm_export(user, audit_log_entry) - return json_success() + return json_success(request) diff --git a/zerver/views/realm_icon.py b/zerver/views/realm_icon.py index 826e9684f1..b8fe7b7a6c 100644 --- a/zerver/views/realm_icon.py +++ b/zerver/views/realm_icon.py @@ -35,7 +35,7 @@ def upload_icon(request: HttpRequest, user_profile: UserProfile) -> HttpResponse json_result = dict( icon_url=icon_url, ) - return json_success(json_result) + return json_success(request, data=json_result) @require_realm_admin @@ -50,7 +50,7 @@ def delete_icon_backend(request: HttpRequest, user_profile: UserProfile) -> Http json_result = dict( icon_url=gravatar_url, ) - return json_success(json_result) + return json_success(request, data=json_result) def get_icon_backend(request: HttpRequest, user_profile: UserProfile) -> HttpResponse: diff --git a/zerver/views/realm_linkifiers.py b/zerver/views/realm_linkifiers.py index 53fcf56905..9cbc7c02a8 100644 --- a/zerver/views/realm_linkifiers.py +++ b/zerver/views/realm_linkifiers.py @@ -13,7 +13,7 @@ from zerver.models import RealmFilter, UserProfile, linkifiers_for_realm # Custom realm linkifiers def list_linkifiers(request: HttpRequest, user_profile: UserProfile) -> HttpResponse: linkifiers = linkifiers_for_realm(user_profile.realm_id) - return json_success({"linkifiers": linkifiers}) + return json_success(request, data={"linkifiers": linkifiers}) @require_realm_admin @@ -30,7 +30,7 @@ def create_linkifier( pattern=pattern, url_format_string=url_format_string, ) - return json_success({"id": linkifier_id}) + return json_success(request, data={"id": linkifier_id}) except ValidationError as e: raise ValidationFailureError(e) @@ -43,7 +43,7 @@ def delete_linkifier( do_remove_linkifier(realm=user_profile.realm, id=filter_id) except RealmFilter.DoesNotExist: raise JsonableError(_("Linkifier not found.")) - return json_success() + return json_success(request) @require_realm_admin @@ -62,7 +62,7 @@ def update_linkifier( pattern=pattern, url_format_string=url_format_string, ) - return json_success() + return json_success(request) except RealmFilter.DoesNotExist: raise JsonableError(_("Linkifier not found.")) except ValidationError as e: diff --git a/zerver/views/realm_logo.py b/zerver/views/realm_logo.py index f01326261b..a5db760b42 100644 --- a/zerver/views/realm_logo.py +++ b/zerver/views/realm_logo.py @@ -35,7 +35,7 @@ def upload_logo( do_change_logo_source( user_profile.realm, user_profile.realm.LOGO_UPLOADED, night, acting_user=user_profile ) - return json_success() + return json_success(request) @require_realm_admin @@ -49,7 +49,7 @@ def delete_logo_backend( do_change_logo_source( user_profile.realm, user_profile.realm.LOGO_DEFAULT, night, acting_user=user_profile ) - return json_success() + return json_success(request) @has_request_variables diff --git a/zerver/views/realm_playgrounds.py b/zerver/views/realm_playgrounds.py index 1f1c66d86f..3d25da3efc 100644 --- a/zerver/views/realm_playgrounds.py +++ b/zerver/views/realm_playgrounds.py @@ -52,7 +52,7 @@ def add_realm_playground( ) except ValidationError as e: raise ValidationFailureError(e) - return json_success({"id": playground_id}) + return json_success(request, data={"id": playground_id}) @require_realm_admin @@ -62,4 +62,4 @@ def delete_realm_playground( ) -> HttpResponse: realm_playground = access_playground_by_id(user_profile.realm, playground_id) do_remove_realm_playground(user_profile.realm, realm_playground) - return json_success() + return json_success(request) diff --git a/zerver/views/report.py b/zerver/views/report.py index d4d4a51fef..f6aac95f11 100644 --- a/zerver/views/report.py +++ b/zerver/views/report.py @@ -70,7 +70,7 @@ def report_send_times( statsd.incr("locally_echoed") if rendered_content_disparity: statsd.incr("render_disparity") - return json_success() + return json_success(request) @has_request_variables @@ -89,7 +89,7 @@ def report_narrow_times( statsd.timing(f"narrow.initial_core.{base_key}", initial_core) statsd.timing(f"narrow.initial_free.{base_key}", initial_free) statsd.timing(f"narrow.network.{base_key}", network) - return json_success() + return json_success(request) @has_request_variables @@ -106,7 +106,7 @@ def report_unnarrow_times( base_key = statsd_key(realm.string_id, clean_periods=True) statsd.timing(f"unnarrow.initial_core.{base_key}", initial_core) statsd.timing(f"unnarrow.initial_free.{base_key}", initial_free) - return json_success() + return json_success(request) @has_request_variables @@ -124,7 +124,7 @@ def report_error( """Accepts an error report and stores in a queue for processing. The actual error reports are later handled by do_report_error""" if not settings.BROWSER_ERROR_REPORTING: - return json_success() + return json_success(request) more_info = dict(more_info) js_source_map = get_js_source_map() @@ -177,7 +177,7 @@ def report_error( ), ) - return json_success() + return json_success(request) @csrf_exempt @@ -206,4 +206,4 @@ def report_csp_violations( get_attr("script-sample"), ) - return json_success() + return json_success(request) diff --git a/zerver/views/storage.py b/zerver/views/storage.py index e818f63236..9c13acfb96 100644 --- a/zerver/views/storage.py +++ b/zerver/views/storage.py @@ -26,7 +26,7 @@ def update_storage( set_bot_storage(user_profile, list(storage.items())) except StateError as e: # nocoverage raise JsonableError(str(e)) - return json_success() + return json_success(request) @has_request_variables @@ -41,7 +41,7 @@ def get_storage( storage = {key: get_bot_storage(user_profile, key) for key in keys} except StateError as e: raise JsonableError(str(e)) - return json_success({"storage": storage}) + return json_success(request, data={"storage": storage}) @has_request_variables @@ -56,4 +56,4 @@ def remove_storage( remove_bot_storage(user_profile, keys) except StateError as e: raise JsonableError(str(e)) - return json_success() + return json_success(request) diff --git a/zerver/views/streams.py b/zerver/views/streams.py index d1b83a34d3..9770d894f2 100644 --- a/zerver/views/streams.py +++ b/zerver/views/streams.py @@ -145,7 +145,7 @@ def deactivate_stream_backend( ) -> HttpResponse: (stream, sub) = access_stream_for_delete_or_update(user_profile, stream_id) do_deactivate_stream(stream, acting_user=user_profile) - return json_success() + return json_success(request) @require_realm_admin @@ -157,7 +157,7 @@ def add_default_stream( if stream.invite_only: raise JsonableError(_("Private streams cannot be made default.")) do_add_default_stream(stream) - return json_success() + return json_success(request) @require_realm_admin @@ -174,7 +174,7 @@ def create_default_stream_group( (stream, sub) = access_stream_by_name(user_profile, stream_name) streams.append(stream) do_create_default_stream_group(user_profile.realm, group_name, description, streams) - return json_success() + return json_success(request) @require_realm_admin @@ -194,7 +194,7 @@ def update_default_stream_group_info( do_change_default_stream_group_name(user_profile.realm, group, new_group_name) if new_description is not None: do_change_default_stream_group_description(user_profile.realm, group, new_description) - return json_success() + return json_success(request) @require_realm_admin @@ -218,7 +218,7 @@ def update_default_stream_group_streams( do_remove_streams_from_default_stream_group(user_profile.realm, group, streams) else: raise JsonableError(_('Invalid value for "op". Specify one of "add" or "remove".')) - return json_success() + return json_success(request) @require_realm_admin @@ -228,7 +228,7 @@ def remove_default_stream_group( ) -> HttpResponse: group = access_default_stream_group_by_id(user_profile.realm, group_id) do_remove_default_stream_group(user_profile.realm, group) - return json_success() + return json_success(request) @require_realm_admin @@ -242,7 +242,7 @@ def remove_default_stream( allow_realm_admin=True, ) do_remove_default_stream(stream) - return json_success() + return json_success(request) @has_request_variables @@ -331,7 +331,7 @@ def update_stream_backend( is_web_public=is_web_public, acting_user=user_profile, ) - return json_success() + return json_success(request) @has_request_variables @@ -344,7 +344,7 @@ def list_subscriptions_backend( user_profile, include_subscribers=include_subscribers, ) - return json_success({"subscriptions": subscribed}) + return json_success(request, data={"subscriptions": subscribed}) add_subscriptions_schema = check_list( @@ -376,7 +376,7 @@ def update_subscriptions_backend( ] data = compose_views(thunks) - return json_success(data) + return json_success(request, data) def compose_views(thunks: List[Callable[[], HttpResponse]]) -> Dict[str, Any]: @@ -439,7 +439,7 @@ def remove_subscriptions_backend( for (subscriber, not_subscribed_stream) in not_subscribed: result["not_removed"].append(not_subscribed_stream.name) - return json_success(result) + return json_success(request, data=result) def you_were_just_subscribed_message( @@ -586,7 +586,7 @@ def add_subscriptions_backend( result["already_subscribed"] = dict(result["already_subscribed"]) if not authorization_errors_fatal: result["unauthorized"] = [s.name for s in unauthorized_streams] - return json_success(result) + return json_success(request, data=result) def send_messages_for_new_subscribers( @@ -708,7 +708,7 @@ def get_subscribers_backend( ) subscribers = get_subscriber_ids(stream, user_profile) - return json_success({"subscribers": list(subscribers)}) + return json_success(request, data={"subscribers": list(subscribers)}) # By default, lists all streams that the user has access to -- @@ -734,7 +734,7 @@ def get_streams_backend( include_default=include_default, include_owner_subscribed=include_owner_subscribed, ) - return json_success({"streams": streams}) + return json_success(request, data={"streams": streams}) @has_request_variables @@ -771,7 +771,7 @@ def get_topics_backend( public_history=stream.is_history_public_to_subscribers(), ) - return json_success(dict(topics=result)) + return json_success(request, data=dict(topics=result)) @transaction.atomic @@ -797,7 +797,7 @@ def delete_in_topic( do_delete_messages(user_profile.realm, messages) - return json_success() + return json_success(request) @require_post @@ -829,7 +829,7 @@ def json_stream_exists( ) result["subscribed"] = True - return json_success(result) # results are ignored for HEAD requests + return json_success(request, data=result) # results are ignored for HEAD requests @has_request_variables @@ -837,7 +837,7 @@ def json_get_stream_id( request: HttpRequest, user_profile: UserProfile, stream_name: str = REQ("stream") ) -> HttpResponse: (stream, sub) = access_stream_by_name(user_profile, stream_name) - return json_success({"stream_id": stream.id}) + return json_success(request, data={"stream_id": stream.id}) @has_request_variables @@ -925,4 +925,4 @@ def update_subscription_properties_backend( if len(request_notes.ignored_parameters) > 0: result["ignored_parameters_unsupported"] = list(request_notes.ignored_parameters) - return json_success(result) + return json_success(request, data=result) diff --git a/zerver/views/submessage.py b/zerver/views/submessage.py index 417422c399..7602e4572e 100644 --- a/zerver/views/submessage.py +++ b/zerver/views/submessage.py @@ -60,4 +60,4 @@ def process_submessage( msg_type=msg_type, content=content, ) - return json_success() + return json_success(request) diff --git a/zerver/views/tutorial.py b/zerver/views/tutorial.py index 649f891b04..739efa73fe 100644 --- a/zerver/views/tutorial.py +++ b/zerver/views/tutorial.py @@ -17,4 +17,4 @@ def set_tutorial_status( user_profile.tutorial_status = UserProfile.TUTORIAL_FINISHED user_profile.save(update_fields=["tutorial_status"]) - return json_success() + return json_success(request) diff --git a/zerver/views/typing.py b/zerver/views/typing.py index a977e2413f..161eca9593 100644 --- a/zerver/views/typing.py +++ b/zerver/views/typing.py @@ -54,4 +54,4 @@ def send_notification_backend( user_ids = notification_to check_send_typing_notification(user_profile, user_ids, operator) - return json_success() + return json_success(request) diff --git a/zerver/views/upload.py b/zerver/views/upload.py index 453b07b12f..fac2b4fbfb 100644 --- a/zerver/views/upload.py +++ b/zerver/views/upload.py @@ -24,7 +24,7 @@ from zerver.models import UserProfile, validate_attachment_request def serve_s3(request: HttpRequest, url_path: str, url_only: bool) -> HttpResponse: url = get_signed_upload_url(url_path) if url_only: - return json_success(dict(url=url)) + return json_success(request, data=dict(url=url)) return redirect(url) @@ -36,7 +36,7 @@ def serve_local(request: HttpRequest, path_id: str, url_only: bool) -> HttpRespo if url_only: url = generate_unauthed_file_access_url(path_id) - return json_success(dict(url=url)) + return json_success(request, data=dict(url=url)) # Here we determine whether a browser should treat the file like # an attachment (and thus clicking a link to it should download) @@ -129,4 +129,4 @@ def upload_file_backend(request: HttpRequest, user_profile: UserProfile) -> Http check_upload_within_quota(user_profile.realm, file_size) uri = upload_message_image_from_request(request, user_file, user_profile) - return json_success({"uri": uri}) + return json_success(request, data={"uri": uri}) diff --git a/zerver/views/user_groups.py b/zerver/views/user_groups.py index bc9a020620..8aee0a63bb 100644 --- a/zerver/views/user_groups.py +++ b/zerver/views/user_groups.py @@ -38,14 +38,14 @@ def add_user_group( ) -> HttpResponse: user_profiles = user_ids_to_users(members, user_profile.realm) check_add_user_group(user_profile.realm, name, user_profiles, description) - return json_success() + return json_success(request) @require_member_or_admin @has_request_variables def get_user_group(request: HttpRequest, user_profile: UserProfile) -> HttpResponse: user_groups = user_groups_in_realm_serialized(user_profile.realm) - return json_success({"user_groups": user_groups}) + return json_success(request, data={"user_groups": user_groups}) @require_user_group_edit_permission @@ -68,7 +68,7 @@ def edit_user_group( if description != user_group.description: do_update_user_group_description(user_group, description) - return json_success() + return json_success(request) @require_user_group_edit_permission @@ -80,7 +80,7 @@ def delete_user_group( ) -> HttpResponse: check_delete_user_group(user_group_id, user_profile) - return json_success() + return json_success(request) @require_user_group_edit_permission @@ -105,14 +105,14 @@ def update_user_group_backend( ] data = compose_views(thunks) - return json_success(data) + return json_success(request, data) def add_members_to_group_backend( request: HttpRequest, user_profile: UserProfile, user_group_id: int, members: Sequence[int] ) -> HttpResponse: if not members: - return json_success() + return json_success(request) user_group = access_user_group_by_id(user_group_id, user_profile) user_profiles = user_ids_to_users(members, user_profile.realm) @@ -127,14 +127,14 @@ def add_members_to_group_backend( ) bulk_add_members_to_user_group(user_group, user_profiles) - return json_success() + return json_success(request) def remove_members_from_group_backend( request: HttpRequest, user_profile: UserProfile, user_group_id: int, members: Sequence[int] ) -> HttpResponse: if not members: - return json_success() + return json_success(request) user_profiles = user_ids_to_users(members, user_profile.realm) user_group = access_user_group_by_id(user_group_id, user_profile) @@ -144,4 +144,4 @@ def remove_members_from_group_backend( raise JsonableError(_("There is no member '{}' in this user group").format(member)) remove_members_from_user_group(user_group, user_profiles) - return json_success() + return json_success(request) diff --git a/zerver/views/user_settings.py b/zerver/views/user_settings.py index db74f15583..d22ff3e37f 100644 --- a/zerver/views/user_settings.py +++ b/zerver/views/user_settings.py @@ -315,7 +315,7 @@ def json_change_settings( if len(request_notes.ignored_parameters) > 0: result["ignored_parameters_unsupported"] = list(request_notes.ignored_parameters) - return json_success(result) + return json_success(request, data=result) def set_avatar_backend(request: HttpRequest, user_profile: UserProfile) -> HttpResponse: @@ -339,7 +339,7 @@ def set_avatar_backend(request: HttpRequest, user_profile: UserProfile) -> HttpR json_result = dict( avatar_url=user_avatar_url, ) - return json_success(json_result) + return json_success(request, data=json_result) def delete_avatar_backend(request: HttpRequest, user_profile: UserProfile) -> HttpResponse: @@ -354,7 +354,7 @@ def delete_avatar_backend(request: HttpRequest, user_profile: UserProfile) -> Ht json_result = dict( avatar_url=gravatar_url, ) - return json_success(json_result) + return json_success(request, data=json_result) # We don't use @human_users_only here, because there are use cases for @@ -365,4 +365,4 @@ def regenerate_api_key(request: HttpRequest, user_profile: UserProfile) -> HttpR json_result = dict( api_key=new_api_key, ) - return json_success(json_result) + return json_success(request, data=json_result) diff --git a/zerver/views/users.py b/zerver/views/users.py index 2894b60da1..ee1f248123 100644 --- a/zerver/views/users.py +++ b/zerver/views/users.py @@ -114,7 +114,7 @@ def deactivate_user_own_backend(request: HttpRequest, user_profile: UserProfile) raise CannotDeactivateLastUserError(is_last_owner=True) do_deactivate_user(user_profile, acting_user=user_profile) - return json_success() + return json_success(request) def deactivate_bot_backend( @@ -128,7 +128,7 @@ def _deactivate_user_profile_backend( request: HttpRequest, user_profile: UserProfile, target: UserProfile ) -> HttpResponse: do_deactivate_user(target, acting_user=user_profile) - return json_success() + return json_success(request) def reactivate_user_backend( @@ -141,7 +141,7 @@ def reactivate_user_backend( assert target.bot_type is not None check_bot_creation_policy(user_profile, target.bot_type) do_reactivate_user(target, acting_user=user_profile) - return json_success() + return json_success(request) check_profile_data: Validator[ @@ -218,7 +218,7 @@ def update_user_backend( validate_user_custom_profile_data(target.realm.id, clean_profile_data) do_update_user_custom_profile_data_if_changed(target, clean_profile_data) - return json_success() + return json_success(request) def avatar( @@ -366,7 +366,7 @@ def patch_bot_backend( if bot.bot_owner is not None: json_result["bot_owner"] = bot.bot_owner.email - return json_success(json_result) + return json_success(request, data=json_result) @require_member_or_admin @@ -380,7 +380,7 @@ def regenerate_bot_api_key( json_result = dict( api_key=new_api_key, ) - return json_success(json_result) + return json_success(request, data=json_result) @require_member_or_admin @@ -511,7 +511,7 @@ def add_bot_backend( default_events_register_stream=get_stream_name(bot_profile.default_events_register_stream), default_all_public_streams=bot_profile.default_all_public_streams, ) - return json_success(json_result) + return json_success(request, data=json_result) @require_member_or_admin @@ -541,7 +541,7 @@ def get_bots_backend(request: HttpRequest, user_profile: UserProfile) -> HttpRes default_all_public_streams=bot_profile.default_all_public_streams, ) - return json_success({"bots": list(map(bot_info, bot_profiles))}) + return json_success(request, data={"bots": list(map(bot_info, bot_profiles))}) @has_request_variables @@ -583,7 +583,7 @@ def get_members_backend( else: data = {"members": [members[k] for k in members]} - return json_success(data) + return json_success(request, data) @require_realm_admin @@ -630,7 +630,7 @@ def create_user_backend( raise JsonableError(PASSWORD_TOO_WEAK_ERROR) target_user = do_create_user(email, password, realm, full_name, acting_user=user_profile) - return json_success({"user_id": target_user.id}) + return json_success(request, data={"user_id": target_user.id}) def get_profile_backend(request: HttpRequest, user_profile: UserProfile) -> HttpResponse: @@ -649,7 +649,7 @@ def get_profile_backend(request: HttpRequest, user_profile: UserProfile) -> Http if messages: result["max_message_id"] = messages[0].id - return json_success(result) + return json_success(request, data=result) @has_request_variables @@ -664,7 +664,7 @@ def get_subscription_backend( subscription_status = {"is_subscribed": subscribed_to_stream(target_user, stream_id)} - return json_success(subscription_status) + return json_success(request, data=subscription_status) @has_request_variables diff --git a/zerver/views/video_calls.py b/zerver/views/video_calls.py index 493bc6fa09..7367429514 100644 --- a/zerver/views/video_calls.py +++ b/zerver/views/video_calls.py @@ -158,14 +158,14 @@ def make_zoom_video_call(request: HttpRequest, user: UserProfile) -> HttpRespons elif not res.ok: raise JsonableError(_("Failed to create Zoom call")) - return json_success({"url": res.json()["join_url"]}) + return json_success(request, data={"url": res.json()["join_url"]}) @csrf_exempt @require_POST @has_request_variables def deauthorize_zoom_user(request: HttpRequest) -> HttpResponse: - return json_success() + return json_success(request) def get_bigbluebutton_url(request: HttpRequest, user_profile: UserProfile) -> HttpResponse: @@ -196,7 +196,7 @@ def get_bigbluebutton_url(request: HttpRequest, user_profile: UserProfile) -> Ht } ), ) - return json_success({"url": url}) + return json_success(request, data={"url": url}) # We use zulip_login_required here mainly to get access to the user's diff --git a/zerver/views/zephyr.py b/zerver/views/zephyr.py index e41d7ff10e..d8917d3270 100644 --- a/zerver/views/zephyr.py +++ b/zerver/views/zephyr.py @@ -74,4 +74,4 @@ def webathena_kerberos_login( logging.exception("Error updating the user's ccache", stack_info=True) raise JsonableError(_("We were unable to set up mirroring for you")) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/airbrake/view.py b/zerver/webhooks/airbrake/view.py index a400d4acba..62b5e18fe8 100644 --- a/zerver/webhooks/airbrake/view.py +++ b/zerver/webhooks/airbrake/view.py @@ -23,7 +23,7 @@ def api_airbrake_webhook( subject = get_subject(payload) body = get_body(payload) check_send_webhook_message(request, user_profile, subject, body) - return json_success() + return json_success(request) def get_subject(payload: Dict[str, Any]) -> str: diff --git a/zerver/webhooks/alertmanager/view.py b/zerver/webhooks/alertmanager/view.py index 982d08b4a9..d8a2de8dc6 100644 --- a/zerver/webhooks/alertmanager/view.py +++ b/zerver/webhooks/alertmanager/view.py @@ -55,4 +55,4 @@ def api_alertmanager_webhook( check_send_webhook_message(request, user_profile, topic, body) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/ansibletower/view.py b/zerver/webhooks/ansibletower/view.py index 962841d9b1..cbe5660df2 100644 --- a/zerver/webhooks/ansibletower/view.py +++ b/zerver/webhooks/ansibletower/view.py @@ -32,7 +32,7 @@ def api_ansibletower_webhook( subject = payload["name"] check_send_webhook_message(request, user_profile, subject, body) - return json_success() + return json_success(request) def extract_friendly_name(payload: Dict[str, Any]) -> str: diff --git a/zerver/webhooks/appfollow/view.py b/zerver/webhooks/appfollow/view.py index b572ea44df..770fac1884 100644 --- a/zerver/webhooks/appfollow/view.py +++ b/zerver/webhooks/appfollow/view.py @@ -25,7 +25,7 @@ def api_appfollow_webhook( topic = app_name check_send_webhook_message(request, user_profile, topic, body=convert_markdown(message)) - return json_success() + return json_success(request) def convert_markdown(text: str) -> str: diff --git a/zerver/webhooks/appveyor/view.py b/zerver/webhooks/appveyor/view.py index 93574247d1..e012719987 100644 --- a/zerver/webhooks/appveyor/view.py +++ b/zerver/webhooks/appveyor/view.py @@ -29,7 +29,7 @@ def api_appveyor_webhook( subject = get_subject_for_http_request(payload) check_send_webhook_message(request, user_profile, subject, body) - return json_success() + return json_success(request) def get_subject_for_http_request(payload: Dict[str, Any]) -> str: diff --git a/zerver/webhooks/basecamp/view.py b/zerver/webhooks/basecamp/view.py index f8d78906fc..755cef245b 100644 --- a/zerver/webhooks/basecamp/view.py +++ b/zerver/webhooks/basecamp/view.py @@ -75,7 +75,7 @@ def api_basecamp_webhook( raise UnsupportedWebhookEventType(event) check_send_webhook_message(request, user_profile, subject, body, event) - return json_success() + return json_success(request) def get_project_name(payload: Dict[str, Any]) -> str: diff --git a/zerver/webhooks/beanstalk/view.py b/zerver/webhooks/beanstalk/view.py index d36668cb3d..07115ef3a5 100644 --- a/zerver/webhooks/beanstalk/view.py +++ b/zerver/webhooks/beanstalk/view.py @@ -88,7 +88,7 @@ def api_beanstalk_webhook( git_repo = "uri" in payload if git_repo: if branches is not None and branches.find(payload["branch"]) == -1: - return json_success() + return json_success(request) # To get a linkable url, for commit in payload["commits"]: commit["author"] = {"username": commit["author"]["name"]} @@ -113,4 +113,4 @@ def api_beanstalk_webhook( content = f"{author} pushed [revision {revision}]({url}):\n\n> {short_commit_msg}" check_send_webhook_message(request, user_profile, subject, content) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/beeminder/view.py b/zerver/webhooks/beeminder/view.py index 5e7849a182..40e3d7db0d 100644 --- a/zerver/webhooks/beeminder/view.py +++ b/zerver/webhooks/beeminder/view.py @@ -50,4 +50,4 @@ def api_beeminder_webhook( expression=expression, ) check_send_webhook_message(request, user_profile, topic, body) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/bitbucket/view.py b/zerver/webhooks/bitbucket/view.py index e1f784a21c..15c43ce93f 100644 --- a/zerver/webhooks/bitbucket/view.py +++ b/zerver/webhooks/bitbucket/view.py @@ -44,7 +44,7 @@ def api_bitbucket_webhook( else: branch = payload["commits"][-1]["branch"] if branches is not None and branches.find(branch) == -1: - return json_success() + return json_success(request) committer = payload.get("user") content = get_push_commits_event_message( @@ -53,4 +53,4 @@ def api_bitbucket_webhook( subject = TOPIC_WITH_BRANCH_TEMPLATE.format(repo=repository["name"], branch=branch) check_send_webhook_message(request, user_profile, subject, content, unquote_url_parameters=True) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/bitbucket2/view.py b/zerver/webhooks/bitbucket2/view.py index a53020d0a4..7ec2cc53ec 100644 --- a/zerver/webhooks/bitbucket2/view.py +++ b/zerver/webhooks/bitbucket2/view.py @@ -87,11 +87,11 @@ def api_bitbucket2_webhook( if type == "push": # ignore push events with no changes if not payload["push"]["changes"]: - return json_success() + return json_success(request) branch = get_branch_name_for_push_event(payload) if branch and branches: if branches.find(branch) == -1: - return json_success() + return json_success(request) subject = get_subject_based_on_type(payload, type) body_function = get_body_based_on_type(type) @@ -113,7 +113,7 @@ def api_bitbucket2_webhook( request, user_profile, s, b, type, unquote_url_parameters=True ) - return json_success() + return json_success(request) def get_subject_for_branch_specified_events( diff --git a/zerver/webhooks/bitbucket3/view.py b/zerver/webhooks/bitbucket3/view.py index f5e5063de5..853e8e82d3 100644 --- a/zerver/webhooks/bitbucket3/view.py +++ b/zerver/webhooks/bitbucket3/view.py @@ -416,4 +416,4 @@ def api_bitbucket3_webhook( unquote_url_parameters=True, ) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/buildbot/view.py b/zerver/webhooks/buildbot/view.py index a0ff5d9bf3..d9317be339 100644 --- a/zerver/webhooks/buildbot/view.py +++ b/zerver/webhooks/buildbot/view.py @@ -23,7 +23,7 @@ def api_buildbot_webhook( topic = "general" body = get_message(payload) check_send_webhook_message(request, user_profile, topic, body, payload["event"]) - return json_success() + return json_success(request) def get_message(payload: Dict[str, Any]) -> str: diff --git a/zerver/webhooks/canarytoken/view.py b/zerver/webhooks/canarytoken/view.py index 04d46880f4..ca6713841d 100644 --- a/zerver/webhooks/canarytoken/view.py +++ b/zerver/webhooks/canarytoken/view.py @@ -37,4 +37,4 @@ def api_canarytoken_webhook( topic = user_specified_topic check_send_webhook_message(request, user_profile, topic, body) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/circleci/view.py b/zerver/webhooks/circleci/view.py index 96de45911b..f004b080cf 100644 --- a/zerver/webhooks/circleci/view.py +++ b/zerver/webhooks/circleci/view.py @@ -35,7 +35,7 @@ def api_circleci_webhook( body, payload.get("status") if not payload.get("build_num") else payload.get("outcome"), ) - return json_success() + return json_success(request) def get_subject(payload: Dict[str, Any]) -> str: diff --git a/zerver/webhooks/clubhouse/view.py b/zerver/webhooks/clubhouse/view.py index 373a4d3685..9f29507f86 100644 --- a/zerver/webhooks/clubhouse/view.py +++ b/zerver/webhooks/clubhouse/view.py @@ -723,7 +723,7 @@ def api_clubhouse_webhook( # such requests correspond to. So, it is best to ignore such # requests for now. if payload is None: - return json_success() + return json_success(request) if payload.get("primary_id") is not None: action = get_action_with_primary_id(payload) @@ -743,4 +743,4 @@ def api_clubhouse_webhook( else: send_stream_messages_for_actions(request, user_profile, payload, primary_action, event) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/codeship/view.py b/zerver/webhooks/codeship/view.py index a57de15e4c..02ea2ae767 100644 --- a/zerver/webhooks/codeship/view.py +++ b/zerver/webhooks/codeship/view.py @@ -34,7 +34,7 @@ def api_codeship_webhook( body = get_body_for_http_request(payload) check_send_webhook_message(request, user_profile, subject, body) - return json_success() + return json_success(request) def get_subject_for_http_request(payload: Dict[str, Any]) -> str: diff --git a/zerver/webhooks/crashlytics/view.py b/zerver/webhooks/crashlytics/view.py index 43507d935a..5fa5c5c762 100644 --- a/zerver/webhooks/crashlytics/view.py +++ b/zerver/webhooks/crashlytics/view.py @@ -41,4 +41,4 @@ def api_crashlytics_webhook( ) check_send_webhook_message(request, user_profile, subject, body) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/delighted/view.py b/zerver/webhooks/delighted/view.py index 01ccf1d794..fa6950176e 100644 --- a/zerver/webhooks/delighted/view.py +++ b/zerver/webhooks/delighted/view.py @@ -49,4 +49,4 @@ def api_delighted_webhook( topic = "Survey response" check_send_webhook_message(request, user_profile, topic, body) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/deskdotcom/view.py b/zerver/webhooks/deskdotcom/view.py index 315fa1af61..23ee7b9a18 100644 --- a/zerver/webhooks/deskdotcom/view.py +++ b/zerver/webhooks/deskdotcom/view.py @@ -20,4 +20,4 @@ def api_deskdotcom_webhook( ) -> HttpResponse: topic = "Desk.com notification" check_send_webhook_message(request, user_profile, topic, data) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/dialogflow/view.py b/zerver/webhooks/dialogflow/view.py index d45deacb9b..74fa022f90 100644 --- a/zerver/webhooks/dialogflow/view.py +++ b/zerver/webhooks/dialogflow/view.py @@ -38,4 +38,4 @@ def api_dialogflow_webhook( client = RequestNotes.get_notes(request).client assert client is not None check_send_private_message(user_profile, client, receiving_user, body) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/dropbox/view.py b/zerver/webhooks/dropbox/view.py index 191f237714..b0d43a965c 100644 --- a/zerver/webhooks/dropbox/view.py +++ b/zerver/webhooks/dropbox/view.py @@ -21,7 +21,7 @@ def api_dropbox_webhook( check_send_webhook_message( request, user_profile, topic, "File has been updated on Dropbox!" ) - return json_success() + return json_success(request) else: if challenge is None: raise RequestVariableMissingError("challenge") diff --git a/zerver/webhooks/errbit/view.py b/zerver/webhooks/errbit/view.py index 6ff5e88aa3..da6878dc7a 100644 --- a/zerver/webhooks/errbit/view.py +++ b/zerver/webhooks/errbit/view.py @@ -22,7 +22,7 @@ def api_errbit_webhook( subject = get_subject(payload) body = get_body(payload) check_send_webhook_message(request, user_profile, subject, body) - return json_success() + return json_success(request) def get_subject(payload: Dict[str, Any]) -> str: diff --git a/zerver/webhooks/flock/view.py b/zerver/webhooks/flock/view.py index dc7a710500..8baa23eac4 100644 --- a/zerver/webhooks/flock/view.py +++ b/zerver/webhooks/flock/view.py @@ -28,4 +28,4 @@ def api_flock_webhook( check_send_webhook_message(request, user_profile, topic, body) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/freshdesk/view.py b/zerver/webhooks/freshdesk/view.py index e8a568e91c..9c912cec73 100644 --- a/zerver/webhooks/freshdesk/view.py +++ b/zerver/webhooks/freshdesk/view.py @@ -164,7 +164,7 @@ def api_freshdesk_webhook( content = format_freshdesk_property_change_message(ticket, event_info) else: # Not an event we know handle; do nothing. - return json_success() + return json_success(request) check_send_webhook_message(request, user_profile, subject, content) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/freshping/view.py b/zerver/webhooks/freshping/view.py index acb30c5e3f..cbe595478e 100644 --- a/zerver/webhooks/freshping/view.py +++ b/zerver/webhooks/freshping/view.py @@ -33,7 +33,7 @@ def api_freshping_webhook( check_send_webhook_message( request, user_profile, subject, body, payload["webhook_event_data"]["check_state_name"] ) - return json_success() + return json_success(request) def get_subject_for_http_request(payload: Dict[str, Any]) -> str: diff --git a/zerver/webhooks/freshstatus/view.py b/zerver/webhooks/freshstatus/view.py index b86177a4ca..f42bdb19fa 100644 --- a/zerver/webhooks/freshstatus/view.py +++ b/zerver/webhooks/freshstatus/view.py @@ -99,7 +99,7 @@ def api_freshstatus_webhook( check_send_webhook_message( request, user_profile, subject, body, payload["event_data"]["event_type"] ) - return json_success() + return json_success(request) def get_services_content(services_data: List[Dict[str, Any]]) -> str: diff --git a/zerver/webhooks/front/view.py b/zerver/webhooks/front/view.py index 840f6bdb60..7c7c654744 100644 --- a/zerver/webhooks/front/view.py +++ b/zerver/webhooks/front/view.py @@ -152,4 +152,4 @@ def api_front_webhook( body = get_body_based_on_event(event)(payload) check_send_webhook_message(request, user_profile, topic, body, event) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/gci/view.py b/zerver/webhooks/gci/view.py index cdf07fafa1..5f42ad1f47 100644 --- a/zerver/webhooks/gci/view.py +++ b/zerver/webhooks/gci/view.py @@ -144,7 +144,7 @@ def api_gci_webhook( ) check_send_webhook_message(request, user_profile, subject, body, event) - return json_success() + return json_success(request) def get_event(payload: Dict[str, Any]) -> Optional[str]: diff --git a/zerver/webhooks/github/view.py b/zerver/webhooks/github/view.py index a0570886ff..458548b2ff 100644 --- a/zerver/webhooks/github/view.py +++ b/zerver/webhooks/github/view.py @@ -733,7 +733,7 @@ def api_github_webhook( # This is nothing to worry about--get_event() returns None # for events that are valid but not yet handled by us. # See IGNORED_EVENTS, for example. - return json_success() + return json_success(request) subject = get_subject_based_on_type(payload, event) @@ -746,7 +746,7 @@ def api_github_webhook( body = body_function(helper) check_send_webhook_message(request, user_profile, subject, body, event) - return json_success() + return json_success(request) def get_zulip_event_name( diff --git a/zerver/webhooks/gitlab/view.py b/zerver/webhooks/gitlab/view.py index ebe5b972c8..bc3b95ef86 100644 --- a/zerver/webhooks/gitlab/view.py +++ b/zerver/webhooks/gitlab/view.py @@ -421,7 +421,7 @@ def api_gitlab_webhook( topic = get_subject_based_on_event(event, payload, use_merge_request_title) check_send_webhook_message(request, user_profile, topic, body, event) - return json_success() + return json_success(request) def get_body_based_on_event(event: str) -> Any: diff --git a/zerver/webhooks/gocd/view.py b/zerver/webhooks/gocd/view.py index 7257362050..b817182661 100644 --- a/zerver/webhooks/gocd/view.py +++ b/zerver/webhooks/gocd/view.py @@ -53,4 +53,4 @@ def api_gocd_webhook( check_send_webhook_message(request, user_profile, topic, body) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/gogs/view.py b/zerver/webhooks/gogs/view.py index 4e4b192273..7fae8014d2 100644 --- a/zerver/webhooks/gogs/view.py +++ b/zerver/webhooks/gogs/view.py @@ -171,7 +171,7 @@ def gogs_webhook_main( if event == "push": branch = payload["ref"].replace("refs/heads/", "") if branches is not None and branch not in branches.split(","): - return json_success() + return json_success(request) body = format_push_event(payload) topic = TOPIC_WITH_BRANCH_TEMPLATE.format( repo=repo, @@ -231,4 +231,4 @@ def gogs_webhook_main( raise UnsupportedWebhookEventType(event) check_send_webhook_message(request, user_profile, topic, body, event) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/gosquared/view.py b/zerver/webhooks/gosquared/view.py index 37f3f635ec..839adecc56 100644 --- a/zerver/webhooks/gosquared/view.py +++ b/zerver/webhooks/gosquared/view.py @@ -61,4 +61,4 @@ def api_gosquared_webhook( else: raise UnsupportedWebhookEventType("unknown_event") - return json_success() + return json_success(request) diff --git a/zerver/webhooks/grafana/view.py b/zerver/webhooks/grafana/view.py index ddcc3c5ba0..5323889cb4 100644 --- a/zerver/webhooks/grafana/view.py +++ b/zerver/webhooks/grafana/view.py @@ -71,4 +71,4 @@ def api_grafana_webhook( # send the message check_send_webhook_message(request, user_profile, topic, body, payload.get("state")) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/greenhouse/view.py b/zerver/webhooks/greenhouse/view.py index 221ae3b82c..bec9f2b163 100644 --- a/zerver/webhooks/greenhouse/view.py +++ b/zerver/webhooks/greenhouse/view.py @@ -39,7 +39,7 @@ def api_greenhouse_webhook( payload: Dict[str, Any] = REQ(argument_type="body"), ) -> HttpResponse: if payload["action"] == "ping": - return json_success() + return json_success(request) if payload["action"] == "update_candidate": candidate = payload["payload"]["candidate"] @@ -61,4 +61,4 @@ def api_greenhouse_webhook( topic = "{} - {}".format(action, str(candidate["id"])) check_send_webhook_message(request, user_profile, topic, body) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/groove/view.py b/zerver/webhooks/groove/view.py index c689edf643..bd1435e5d6 100644 --- a/zerver/webhooks/groove/view.py +++ b/zerver/webhooks/groove/view.py @@ -109,7 +109,7 @@ def api_groove_webhook( if body is not None: check_send_webhook_message(request, user_profile, topic, body, event) - return json_success() + return json_success(request) fixture_to_headers = get_http_headers_from_filename("HTTP_X_GROOVE_EVENT") diff --git a/zerver/webhooks/harbor/view.py b/zerver/webhooks/harbor/view.py index 658e1343b6..76b1a2f5de 100644 --- a/zerver/webhooks/harbor/view.py +++ b/zerver/webhooks/harbor/view.py @@ -106,7 +106,7 @@ def api_harbor_webhook( topic = payload["event_data"]["repository"]["repo_full_name"] if event in IGNORED_EVENTS: - return json_success() + return json_success(request) content_func = EVENT_FUNCTION_MAPPER.get(event) @@ -118,4 +118,4 @@ def api_harbor_webhook( check_send_webhook_message( request, user_profile, topic, content, event, unquote_url_parameters=True ) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/hellosign/view.py b/zerver/webhooks/hellosign/view.py index de2e23d4db..229afe0bc2 100644 --- a/zerver/webhooks/hellosign/view.py +++ b/zerver/webhooks/hellosign/view.py @@ -66,4 +66,4 @@ def api_hellosign_webhook( topic = payload["signature_request"]["title"] check_send_webhook_message(request, user_profile, topic, body) - return json_success({"msg": "Hello API Event Received"}) + return json_success(request, data={"msg": "Hello API Event Received"}) diff --git a/zerver/webhooks/helloworld/view.py b/zerver/webhooks/helloworld/view.py index 85dab247f0..67a9bc4e73 100644 --- a/zerver/webhooks/helloworld/view.py +++ b/zerver/webhooks/helloworld/view.py @@ -32,4 +32,4 @@ def api_helloworld_webhook( # send the message check_send_webhook_message(request, user_profile, topic, body) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/heroku/view.py b/zerver/webhooks/heroku/view.py index a1e45a9ffd..19bd29894e 100644 --- a/zerver/webhooks/heroku/view.py +++ b/zerver/webhooks/heroku/view.py @@ -30,4 +30,4 @@ def api_heroku_webhook( content = TEMPLATE.format(user=user, head=head, app=app, url=url, git_log=git_log) check_send_webhook_message(request, user_profile, app, content) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/homeassistant/view.py b/zerver/webhooks/homeassistant/view.py index dcb8a7b7ca..1076c0e5a8 100644 --- a/zerver/webhooks/homeassistant/view.py +++ b/zerver/webhooks/homeassistant/view.py @@ -30,4 +30,4 @@ def api_homeassistant_webhook( check_send_webhook_message(request, user_profile, topic, body) # return json result - return json_success() + return json_success(request) diff --git a/zerver/webhooks/ifttt/view.py b/zerver/webhooks/ifttt/view.py index 45203545d0..0b51059a62 100644 --- a/zerver/webhooks/ifttt/view.py +++ b/zerver/webhooks/ifttt/view.py @@ -36,4 +36,4 @@ def api_iftt_app_webhook( raise JsonableError(_("Content must be a string")) check_send_webhook_message(request, user_profile, topic, content) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/insping/view.py b/zerver/webhooks/insping/view.py index 9b4656fb80..001515a4e8 100644 --- a/zerver/webhooks/insping/view.py +++ b/zerver/webhooks/insping/view.py @@ -45,4 +45,4 @@ def api_insping_webhook( check_send_webhook_message(request, user_profile, topic, body) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/intercom/view.py b/zerver/webhooks/intercom/view.py index c0e6aac6d2..58b57cdbfd 100644 --- a/zerver/webhooks/intercom/view.py +++ b/zerver/webhooks/intercom/view.py @@ -313,7 +313,7 @@ def api_intercom_webhook( ) -> HttpResponse: event_type = payload["topic"] if event_type == "ping": - return json_success() + return json_success(request) handler = EVENT_TO_FUNCTION_MAPPER.get(event_type) if handler is None: @@ -321,4 +321,4 @@ def api_intercom_webhook( topic, body = handler(payload) check_send_webhook_message(request, user_profile, topic, body, event_type) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/jira/view.py b/zerver/webhooks/jira/view.py index 84b54072df..1d353f13d8 100644 --- a/zerver/webhooks/jira/view.py +++ b/zerver/webhooks/jira/view.py @@ -347,7 +347,7 @@ def api_jira_webhook( event = get_event_type(payload) if event in IGNORED_EVENTS: - return json_success() + return json_success(request) if event is None: raise AnomalousWebhookPayload() @@ -364,4 +364,4 @@ def api_jira_webhook( check_send_webhook_message( request, user_profile, subject, content, event, unquote_url_parameters=True ) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/jotform/view.py b/zerver/webhooks/jotform/view.py index a92cffa2d0..8a5efaebc3 100644 --- a/zerver/webhooks/jotform/view.py +++ b/zerver/webhooks/jotform/view.py @@ -28,4 +28,4 @@ def api_jotform_webhook( message = form_response.strip() check_send_webhook_message(request, user_profile, topic, message) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/json/view.py b/zerver/webhooks/json/view.py index 3a44c300c5..140d7627a5 100644 --- a/zerver/webhooks/json/view.py +++ b/zerver/webhooks/json/view.py @@ -28,7 +28,7 @@ def api_json_webhook( subject = get_subject_for_http_request(payload) check_send_webhook_message(request, user_profile, subject, body) - return json_success() + return json_success(request) def get_subject_for_http_request(payload: Dict[str, Any]) -> str: diff --git a/zerver/webhooks/librato/view.py b/zerver/webhooks/librato/view.py index 2936965a54..10cb490c11 100644 --- a/zerver/webhooks/librato/view.py +++ b/zerver/webhooks/librato/view.py @@ -181,4 +181,4 @@ def api_librato_webhook( raise JsonableError(str(e)) check_send_webhook_message(request, user_profile, topic, content) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/lidarr/view.py b/zerver/webhooks/lidarr/view.py index e16fbbd482..63d3451177 100644 --- a/zerver/webhooks/lidarr/view.py +++ b/zerver/webhooks/lidarr/view.py @@ -63,7 +63,7 @@ def api_lidarr_webhook( subject = get_subject_for_http_request(payload) check_send_webhook_message(request, user_profile, subject, body, payload["eventType"]) - return json_success() + return json_success(request) def get_subject_for_http_request(payload: Dict[str, Any]) -> str: diff --git a/zerver/webhooks/mention/view.py b/zerver/webhooks/mention/view.py index 3c1c7371e9..690d42fe67 100644 --- a/zerver/webhooks/mention/view.py +++ b/zerver/webhooks/mention/view.py @@ -34,4 +34,4 @@ def api_mention_webhook( # send the message check_send_webhook_message(request, user_profile, topic, body) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/netlify/view.py b/zerver/webhooks/netlify/view.py index 2bb012348a..1da873d197 100644 --- a/zerver/webhooks/netlify/view.py +++ b/zerver/webhooks/netlify/view.py @@ -45,7 +45,7 @@ def api_netlify_webhook( check_send_webhook_message(request, user_profile, topic, body, event) - return json_success() + return json_success(request) def get_template(request: HttpRequest, payload: Dict[str, Any]) -> Tuple[str, str]: diff --git a/zerver/webhooks/newrelic/view.py b/zerver/webhooks/newrelic/view.py index 758d2bd9dd..560a53da92 100644 --- a/zerver/webhooks/newrelic/view.py +++ b/zerver/webhooks/newrelic/view.py @@ -76,4 +76,4 @@ def api_newrelic_webhook( topic = TOPIC_TEMPLATE.format(**topic_info) check_send_webhook_message(request, user_profile, topic, content, info["status"]) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/opbeat/view.py b/zerver/webhooks/opbeat/view.py index bb3019cbd5..c562019696 100644 --- a/zerver/webhooks/opbeat/view.py +++ b/zerver/webhooks/opbeat/view.py @@ -114,4 +114,4 @@ def api_opbeat_webhook( message = format_object(payload, "base", "") check_send_webhook_message(request, user_profile, message_subject, message) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/opencollective/view.py b/zerver/webhooks/opencollective/view.py index 08619806a3..c58b5ed61e 100644 --- a/zerver/webhooks/opencollective/view.py +++ b/zerver/webhooks/opencollective/view.py @@ -36,7 +36,7 @@ def api_opencollective_webhook( # send the message check_send_webhook_message(request, user_profile, topic, body) - return json_success() + return json_success(request) def get_name(payload: Dict[str, Any]) -> str: diff --git a/zerver/webhooks/opsgenie/view.py b/zerver/webhooks/opsgenie/view.py index 8a14d99279..436b672d47 100644 --- a/zerver/webhooks/opsgenie/view.py +++ b/zerver/webhooks/opsgenie/view.py @@ -101,4 +101,4 @@ def api_opsgenie_webhook( body = body_template.format(**info) check_send_webhook_message(request, user_profile, topic, body, info["alert_type"]) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/pagerduty/view.py b/zerver/webhooks/pagerduty/view.py index 49e8be00bd..7b4e75388b 100644 --- a/zerver/webhooks/pagerduty/view.py +++ b/zerver/webhooks/pagerduty/view.py @@ -266,4 +266,4 @@ def api_pagerduty_webhook( format_dict = build_pagerduty_formatdict_v3(event) send_formated_pagerduty(request, user_profile, event_type, format_dict) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/papertrail/view.py b/zerver/webhooks/papertrail/view.py index 80b2f5bbe9..954c765cc2 100644 --- a/zerver/webhooks/papertrail/view.py +++ b/zerver/webhooks/papertrail/view.py @@ -66,4 +66,4 @@ def api_papertrail_webhook( topic = "logs" check_send_webhook_message(request, user_profile, topic, post) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/pingdom/view.py b/zerver/webhooks/pingdom/view.py index e60c680f64..288ea060e7 100644 --- a/zerver/webhooks/pingdom/view.py +++ b/zerver/webhooks/pingdom/view.py @@ -55,7 +55,7 @@ def api_pingdom_webhook( raise UnsupportedWebhookEventType(check_type) check_send_webhook_message(request, user_profile, subject, body, check_type) - return json_success() + return json_success(request) def get_subject_for_http_request(payload: Dict[str, Any]) -> str: diff --git a/zerver/webhooks/pivotal/view.py b/zerver/webhooks/pivotal/view.py index 2732921dc3..5c55925c60 100644 --- a/zerver/webhooks/pivotal/view.py +++ b/zerver/webhooks/pivotal/view.py @@ -189,4 +189,4 @@ def api_pivotal_webhook(request: HttpRequest, user_profile: UserProfile) -> Http raise JsonableError(_("Unable to handle Pivotal payload")) check_send_webhook_message(request, user_profile, subject, content, event_type) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/radarr/view.py b/zerver/webhooks/radarr/view.py index 919c02ce07..a26adb3023 100644 --- a/zerver/webhooks/radarr/view.py +++ b/zerver/webhooks/radarr/view.py @@ -35,7 +35,7 @@ def api_radarr_webhook( subject = get_subject_for_http_request(payload) check_send_webhook_message(request, user_profile, subject, body, payload["eventType"]) - return json_success() + return json_success(request) def get_subject_for_http_request(payload: Dict[str, Any]) -> str: diff --git a/zerver/webhooks/raygun/view.py b/zerver/webhooks/raygun/view.py index 4d6895df4d..cc4708cb10 100644 --- a/zerver/webhooks/raygun/view.py +++ b/zerver/webhooks/raygun/view.py @@ -42,7 +42,7 @@ def api_raygun_webhook( check_send_webhook_message(request, user_profile, topic, message, event) - return json_success() + return json_success(request) def make_user_stats_chunk(error_dict: Dict[str, Any]) -> str: diff --git a/zerver/webhooks/reviewboard/view.py b/zerver/webhooks/reviewboard/view.py index 5255e563b5..f61083c63d 100644 --- a/zerver/webhooks/reviewboard/view.py +++ b/zerver/webhooks/reviewboard/view.py @@ -195,4 +195,4 @@ def api_reviewboard_webhook( else: raise UnsupportedWebhookEventType(event_type) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/semaphore/view.py b/zerver/webhooks/semaphore/view.py index 66b780e4db..37c1e5ee4e 100644 --- a/zerver/webhooks/semaphore/view.py +++ b/zerver/webhooks/semaphore/view.py @@ -106,7 +106,7 @@ def api_semaphore_webhook( else project_name ) check_send_webhook_message(request, user_profile, subject, content, event) - return json_success() + return json_success(request) def semaphore_classic(payload: Dict[str, Any]) -> Tuple[str, str, str, str]: diff --git a/zerver/webhooks/sentry/view.py b/zerver/webhooks/sentry/view.py index 09ee207a36..41a5764507 100644 --- a/zerver/webhooks/sentry/view.py +++ b/zerver/webhooks/sentry/view.py @@ -271,4 +271,4 @@ def api_sentry_webhook( subject, body = handle_deprecated_payload(payload) check_send_webhook_message(request, user_profile, subject, body) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/slack/view.py b/zerver/webhooks/slack/view.py index ce0e0361e9..64628a5914 100644 --- a/zerver/webhooks/slack/view.py +++ b/zerver/webhooks/slack/view.py @@ -38,4 +38,4 @@ def api_slack_webhook( client = RequestNotes.get_notes(request).client assert client is not None check_send_stream_message(user_profile, client, stream, subject, content) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/slack_incoming/view.py b/zerver/webhooks/slack_incoming/view.py index e9da1bff45..e1ff2f25d1 100644 --- a/zerver/webhooks/slack_incoming/view.py +++ b/zerver/webhooks/slack_incoming/view.py @@ -58,7 +58,7 @@ def api_slack_incoming_webhook( if body != "": body = replace_formatting(replace_links(body).strip()) check_send_webhook_message(request, user_profile, user_specified_topic, body) - return json_success() + return json_success(request) def add_block(block: Dict[str, Any], body: str) -> str: diff --git a/zerver/webhooks/solano/view.py b/zerver/webhooks/solano/view.py index dc4a6080e8..f11b5a77f9 100644 --- a/zerver/webhooks/solano/view.py +++ b/zerver/webhooks/solano/view.py @@ -70,10 +70,10 @@ def api_solano_webhook( ) check_send_webhook_message(request, user_profile, topic, body, event) - return json_success() + return json_success(request) def handle_test_event(request: HttpRequest, user_profile: UserProfile, topic: str) -> HttpResponse: body = "Solano webhook set up correctly." check_send_webhook_message(request, user_profile, topic, body) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/sonarqube/view.py b/zerver/webhooks/sonarqube/view.py index 839c0f4d61..670881c6cc 100644 --- a/zerver/webhooks/sonarqube/view.py +++ b/zerver/webhooks/sonarqube/view.py @@ -129,4 +129,4 @@ def api_sonarqube_webhook( topic = project message = render_body_without_branch(payload) check_send_webhook_message(request, user_profile, topic, message) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/sonarr/view.py b/zerver/webhooks/sonarr/view.py index d8e4d3617f..f7303fe1c7 100644 --- a/zerver/webhooks/sonarr/view.py +++ b/zerver/webhooks/sonarr/view.py @@ -50,7 +50,7 @@ def api_sonarr_webhook( subject = get_subject_for_http_request(payload) check_send_webhook_message(request, user_profile, subject, body, payload["eventType"]) - return json_success() + return json_success(request) def get_subject_for_http_request(payload: Dict[str, Any]) -> str: diff --git a/zerver/webhooks/splunk/view.py b/zerver/webhooks/splunk/view.py index 02d0e39d50..bccd476175 100644 --- a/zerver/webhooks/splunk/view.py +++ b/zerver/webhooks/splunk/view.py @@ -51,4 +51,4 @@ def api_splunk_webhook( # send the message check_send_webhook_message(request, user_profile, topic, body) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/statuspage/view.py b/zerver/webhooks/statuspage/view.py index 28b4fb285c..5fc108a46e 100644 --- a/zerver/webhooks/statuspage/view.py +++ b/zerver/webhooks/statuspage/view.py @@ -73,4 +73,4 @@ def api_statuspage_webhook( raise UnsupportedWebhookEventType("unknown-event") check_send_webhook_message(request, user_profile, topic, body, event) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/stripe/view.py b/zerver/webhooks/stripe/view.py index 3e6f00b92d..5a62a30934 100644 --- a/zerver/webhooks/stripe/view.py +++ b/zerver/webhooks/stripe/view.py @@ -56,9 +56,9 @@ def api_stripe_webhook( try: topic, body = topic_and_body(payload) except SuppressedEvent: # nocoverage - return json_success() + return json_success(request) check_send_webhook_message(request, user_profile, topic, body, payload["type"]) - return json_success() + return json_success(request) def topic_and_body(payload: Dict[str, Any]) -> Tuple[str, str]: diff --git a/zerver/webhooks/taiga/view.py b/zerver/webhooks/taiga/view.py index ac874d15f5..a1b6b583a1 100644 --- a/zerver/webhooks/taiga/view.py +++ b/zerver/webhooks/taiga/view.py @@ -35,7 +35,7 @@ def api_taiga_webhook( topic = message["data"]["milestone"]["name"] check_send_webhook_message(request, user_profile, topic, content) - return json_success() + return json_success(request) templates = { diff --git a/zerver/webhooks/teamcity/view.py b/zerver/webhooks/teamcity/view.py index 64456e4da9..03cb86e688 100644 --- a/zerver/webhooks/teamcity/view.py +++ b/zerver/webhooks/teamcity/view.py @@ -65,7 +65,7 @@ def api_teamcity_webhook( ).strip() send_rate_limited_pm_notification_to_bot_owner(user_profile, user_profile.realm, message) - return json_success() + return json_success(request) build_name = message["buildFullName"] build_url = message["buildStatusUrl"] @@ -134,14 +134,14 @@ def api_teamcity_webhook( teamcity_fullname, teamcity_shortname, ) - return json_success() + return json_success(request) body = f"Your personal build for {body}" client = RequestNotes.get_notes(request).client assert client is not None check_send_private_message(user_profile, client, teamcity_user, body) - return json_success() + return json_success(request) check_send_webhook_message(request, user_profile, topic, body) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/thinkst/view.py b/zerver/webhooks/thinkst/view.py index 77f7cbe1b4..ba4ddd5c0e 100644 --- a/zerver/webhooks/thinkst/view.py +++ b/zerver/webhooks/thinkst/view.py @@ -137,4 +137,4 @@ def api_thinkst_webhook( topic = f"{kind} alert - {name}" check_send_webhook_message(request, user_profile, topic, response) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/transifex/view.py b/zerver/webhooks/transifex/view.py index 13048b3891..c123a8a2b1 100644 --- a/zerver/webhooks/transifex/view.py +++ b/zerver/webhooks/transifex/view.py @@ -35,4 +35,4 @@ def api_transifex_webhook( else: raise UnsupportedWebhookEventType("Unknown Event Type") check_send_webhook_message(request, user_profile, subject, body, event) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/travis/view.py b/zerver/webhooks/travis/view.py index 6eef027add..17cc4b073f 100644 --- a/zerver/webhooks/travis/view.py +++ b/zerver/webhooks/travis/view.py @@ -44,7 +44,7 @@ def api_travis_webhook( event = str(message["type"]) message_status = message["status_message"] if ignore_pull_requests and message["type"] == "pull_request": - return json_success() + return json_success(request) if message_status in GOOD_STATUSES: emoji = ":thumbs_up:" @@ -65,4 +65,4 @@ def api_travis_webhook( topic = "builds" check_send_webhook_message(request, user_profile, topic, body, event) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/trello/view/__init__.py b/zerver/webhooks/trello/view/__init__.py index 7721cdc06e..8d7a98b903 100644 --- a/zerver/webhooks/trello/view/__init__.py +++ b/zerver/webhooks/trello/view/__init__.py @@ -27,12 +27,12 @@ def api_trello_webhook( action_type = payload["action"].get("type") message = get_subject_and_body(payload, action_type) if message is None: - return json_success() + return json_success(request) else: subject, body = message check_send_webhook_message(request, user_profile, subject, body) - return json_success() + return json_success(request) def get_subject_and_body(payload: Mapping[str, Any], action_type: str) -> Optional[Tuple[str, str]]: diff --git a/zerver/webhooks/updown/view.py b/zerver/webhooks/updown/view.py index d2d1b28b18..372a7951ba 100644 --- a/zerver/webhooks/updown/view.py +++ b/zerver/webhooks/updown/view.py @@ -78,7 +78,7 @@ def api_updown_webhook( ) -> HttpResponse: for event in payload: send_message_for_event(request, user_profile, event) - return json_success() + return json_success(request) def get_event_type(event: Dict[str, Any]) -> str: diff --git a/zerver/webhooks/uptimerobot/view.py b/zerver/webhooks/uptimerobot/view.py index 3bb3cf62a2..3cc1824c43 100644 --- a/zerver/webhooks/uptimerobot/view.py +++ b/zerver/webhooks/uptimerobot/view.py @@ -56,7 +56,7 @@ def api_uptimerobot_webhook( raise JsonableError(_("Invalid payload")) check_send_webhook_message(request, user_profile, subject, body, event) - return json_success() + return json_success(request) def get_subject_for_http_request(payload: Dict[str, Any]) -> str: diff --git a/zerver/webhooks/wordpress/view.py b/zerver/webhooks/wordpress/view.py index d5d3e1b744..bdce82434d 100644 --- a/zerver/webhooks/wordpress/view.py +++ b/zerver/webhooks/wordpress/view.py @@ -58,4 +58,4 @@ def api_wordpress_webhook( topic = "WordPress notification" check_send_webhook_message(request, user_profile, topic, data, hook) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/yo/view.py b/zerver/webhooks/yo/view.py index b8335f1751..0a80c1214b 100644 --- a/zerver/webhooks/yo/view.py +++ b/zerver/webhooks/yo/view.py @@ -25,4 +25,4 @@ def api_yo_app_webhook( client = RequestNotes.get_notes(request).client assert client is not None check_send_private_message(user_profile, client, receiving_user, body) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/zabbix/view.py b/zerver/webhooks/zabbix/view.py index 6968d64b6d..94b1d4f0d7 100644 --- a/zerver/webhooks/zabbix/view.py +++ b/zerver/webhooks/zabbix/view.py @@ -50,7 +50,7 @@ def api_zabbix_webhook( raise JsonableError(_("Invalid payload")) check_send_webhook_message(request, user_profile, subject, body) - return json_success() + return json_success(request) def get_subject_for_http_request(payload: Dict[str, Any]) -> str: diff --git a/zerver/webhooks/zapier/view.py b/zerver/webhooks/zapier/view.py index 23eaa94d4e..5577877e46 100644 --- a/zerver/webhooks/zapier/view.py +++ b/zerver/webhooks/zapier/view.py @@ -23,11 +23,12 @@ def api_zapier_webhook( # label for users to be able to distinguish between different Zulip # bots and API keys in their UI return json_success( - { + request, + data={ "full_name": user_profile.full_name, "email": user_profile.email, "id": user_profile.id, - } + }, ) topic = payload.get("topic") @@ -42,4 +43,4 @@ def api_zapier_webhook( raise JsonableError(_("Content can't be empty")) check_send_webhook_message(request, user_profile, topic, content) - return json_success() + return json_success(request) diff --git a/zerver/webhooks/zendesk/view.py b/zerver/webhooks/zendesk/view.py index f23fb00ef0..6ac8ae3155 100644 --- a/zerver/webhooks/zendesk/view.py +++ b/zerver/webhooks/zendesk/view.py @@ -30,4 +30,4 @@ def api_zendesk_webhook( """ subject = truncate(f"#{ticket_id}: {ticket_title}", 60) check_send_webhook_message(request, user_profile, subject, message) - return json_success() + return json_success(request) diff --git a/zilencer/views.py b/zilencer/views.py index e0c44072ea..e0859e1d97 100644 --- a/zilencer/views.py +++ b/zilencer/views.py @@ -84,7 +84,7 @@ def deactivate_remote_server( remote_server: RemoteZulipServer, ) -> HttpResponse: do_deactivate_remote_server(remote_server) - return json_success() + return json_success(request) @csrf_exempt @@ -146,7 +146,7 @@ def register_remote_server( remote_server.api_key = new_org_key remote_server.save() - return json_success({"created": created}) + return json_success(request, data={"created": created}) @has_request_variables @@ -174,7 +174,7 @@ def register_remote_push_device( except IntegrityError: pass - return json_success() + return json_success(request) @has_request_variables @@ -193,7 +193,7 @@ def unregister_remote_push_device( if deleted[0] == 0: raise JsonableError(err_("Token does not exist")) - return json_success() + return json_success(request) @has_request_variables @@ -204,7 +204,7 @@ def unregister_all_remote_push_devices( ) -> HttpResponse: server = validate_entity(entity) RemotePushDeviceToken.objects.filter(user_id=user_id, server=server).delete() - return json_success() + return json_success(request) @has_request_variables @@ -269,7 +269,11 @@ def remote_server_notify_push( send_apple_push_notification(user_id, apple_devices, apns_payload, remote=server) return json_success( - {"total_android_devices": len(android_devices), "total_apple_devices": len(apple_devices)} + request, + data={ + "total_android_devices": len(android_devices), + "total_apple_devices": len(apple_devices), + }, ) @@ -403,7 +407,7 @@ def remote_server_post_analytics( ] batch_create_table_data(server, RemoteRealmAuditLog, row_objects) - return json_success() + return json_success(request) def get_last_id_from_server(server: RemoteZulipServer, model: Any) -> int: @@ -424,4 +428,4 @@ def remote_server_check_analytics( "last_installation_count_id": get_last_id_from_server(server, RemoteInstallationCount), "last_realmauditlog_id": get_last_id_from_server(server, RemoteRealmAuditLog), } - return json_success(result) + return json_success(request, data=result)