mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	support: Return json error if the POST request is invalid.
This commit is contained in:
		@@ -698,8 +698,8 @@ class TestSupportEndpoint(ZulipTestCase):
 | 
			
		||||
            self.assert_in_success_response(["Lear & Co. scrubbed"], result)
 | 
			
		||||
 | 
			
		||||
        with mock.patch("analytics.views.do_scrub_realm") as m:
 | 
			
		||||
            with self.assertRaises(AssertionError):
 | 
			
		||||
                result = self.client_post("/activity/support", {"realm_id": f"{lear_realm.id}"})
 | 
			
		||||
            result = self.client_post("/activity/support", {"realm_id": f"{lear_realm.id}"})
 | 
			
		||||
            self.assert_json_error(result, "Invalid parameters")
 | 
			
		||||
            m.assert_not_called()
 | 
			
		||||
 | 
			
		||||
class TestGetChartDataHelpers(ZulipTestCase):
 | 
			
		||||
 
 | 
			
		||||
@@ -53,7 +53,7 @@ from zerver.lib.actions import (
 | 
			
		||||
from zerver.lib.exceptions import JsonableError
 | 
			
		||||
from zerver.lib.realm_icon import realm_icon_url
 | 
			
		||||
from zerver.lib.request import REQ, has_request_variables
 | 
			
		||||
from zerver.lib.response import json_success
 | 
			
		||||
from zerver.lib.response import json_error, json_success
 | 
			
		||||
from zerver.lib.subdomains import get_subdomain_from_hostname
 | 
			
		||||
from zerver.lib.timestamp import convert_to_UTC, timestamp_to_datetime
 | 
			
		||||
from zerver.lib.validator import to_non_negative_int
 | 
			
		||||
@@ -1125,7 +1125,8 @@ def support(request: HttpRequest) -> HttpResponse:
 | 
			
		||||
        keys = set(request.POST.keys())
 | 
			
		||||
        if "csrfmiddlewaretoken" in keys:
 | 
			
		||||
            keys.remove("csrfmiddlewaretoken")
 | 
			
		||||
        assert(len(keys) == 2)
 | 
			
		||||
        if len(keys) != 2:
 | 
			
		||||
            return json_error(_("Invalid parameters"))
 | 
			
		||||
 | 
			
		||||
        realm_id = request.POST.get("realm_id")
 | 
			
		||||
        realm = Realm.objects.get(id=realm_id)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user