mirror of https://github.com/zulip/zulip.git
Eliminate json_to_dict and use check_dict instead.
All usages of json_to_dict were replaced with the check_dict validator. The check_dict validations can eventually be extended to validate the keys and values of incoming data, but now we just use check_dict([]) in all the places where we had json_to_dict, which means we aren't checking for any specific keys; we are just making sure it's a dictionary. (imported from commit fc5add9a7ef149dfac2a9a6d9a153799c4c0c24d)
This commit is contained in:
parent
3d04f5f738
commit
ebce82b136
|
@ -489,9 +489,6 @@ def json_to_foo(json, type):
|
||||||
raise ValueError("argument is not a %s" % (type().__class__.__name__))
|
raise ValueError("argument is not a %s" % (type().__class__.__name__))
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def json_to_dict(json):
|
|
||||||
return json_to_foo(json, dict)
|
|
||||||
|
|
||||||
def json_to_list(json):
|
def json_to_list(json):
|
||||||
return json_to_foo(json, list)
|
return json_to_foo(json, list)
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ from zerver.models import get_client
|
||||||
|
|
||||||
from zerver.decorator import asynchronous, \
|
from zerver.decorator import asynchronous, \
|
||||||
authenticated_json_post_view, internal_notify_view, RespondAsynchronously, \
|
authenticated_json_post_view, internal_notify_view, RespondAsynchronously, \
|
||||||
has_request_variables, json_to_dict, REQ
|
has_request_variables, REQ
|
||||||
|
|
||||||
from zerver.lib.response import json_success, json_error
|
from zerver.lib.response import json_success, json_error
|
||||||
from zerver.lib.validator import check_bool, check_list, check_string
|
from zerver.lib.validator import check_bool, check_list, check_string
|
||||||
|
|
|
@ -55,7 +55,7 @@ from zerver.lib.validator import check_string, check_list, check_dict, check_int
|
||||||
from zerver.decorator import require_post, \
|
from zerver.decorator import require_post, \
|
||||||
authenticated_api_view, authenticated_json_post_view, \
|
authenticated_api_view, authenticated_json_post_view, \
|
||||||
has_request_variables, authenticated_json_view, \
|
has_request_variables, authenticated_json_view, \
|
||||||
to_non_negative_int, json_to_dict, json_to_bool, \
|
to_non_negative_int, json_to_bool, \
|
||||||
JsonableError, get_user_profile_by_email, REQ, require_realm_admin, \
|
JsonableError, get_user_profile_by_email, REQ, require_realm_admin, \
|
||||||
RequestVariableConversionError
|
RequestVariableConversionError
|
||||||
from zerver.lib.avatar import avatar_url, get_avatar_url
|
from zerver.lib.avatar import avatar_url, get_avatar_url
|
||||||
|
@ -1726,7 +1726,7 @@ def json_report_unnarrow_time(request, user_profile,
|
||||||
def json_report_error(request, user_profile, message=REQ, stacktrace=REQ,
|
def json_report_error(request, user_profile, message=REQ, stacktrace=REQ,
|
||||||
ui_message=REQ(validator=check_bool), user_agent=REQ,
|
ui_message=REQ(validator=check_bool), user_agent=REQ,
|
||||||
href=REQ, log=REQ,
|
href=REQ, log=REQ,
|
||||||
more_info=REQ(converter=json_to_dict, default=None)):
|
more_info=REQ(validator=check_dict([]), default=None)):
|
||||||
|
|
||||||
if not settings.ERROR_REPORTING:
|
if not settings.ERROR_REPORTING:
|
||||||
return json_success()
|
return json_success()
|
||||||
|
|
|
@ -7,8 +7,9 @@ from zerver.models import UserProfile, get_client, get_user_profile_by_email
|
||||||
from zerver.lib.actions import check_send_message
|
from zerver.lib.actions import check_send_message
|
||||||
from zerver.lib.notifications import convert_html_to_markdown
|
from zerver.lib.notifications import convert_html_to_markdown
|
||||||
from zerver.lib.response import json_success, json_error
|
from zerver.lib.response import json_success, json_error
|
||||||
|
from zerver.lib.validator import check_dict
|
||||||
from zerver.decorator import authenticated_api_view, REQ, \
|
from zerver.decorator import authenticated_api_view, REQ, \
|
||||||
has_request_variables, json_to_dict, authenticated_rest_api_view, \
|
has_request_variables, authenticated_rest_api_view, \
|
||||||
api_key_only_webhook_view, to_non_negative_int, ruby_boolean
|
api_key_only_webhook_view, to_non_negative_int, ruby_boolean
|
||||||
from zerver.views.messages import send_message_backend
|
from zerver.views.messages import send_message_backend
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
@ -133,7 +134,7 @@ def api_github_v2(user_profile, event, payload, branches, default_stream, commit
|
||||||
@authenticated_api_view
|
@authenticated_api_view
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def api_github_landing(request, user_profile, event=REQ,
|
def api_github_landing(request, user_profile, event=REQ,
|
||||||
payload=REQ(converter=json_to_dict),
|
payload=REQ(validator=check_dict([])),
|
||||||
branches=REQ(default=''),
|
branches=REQ(default=''),
|
||||||
stream=REQ(default=''),
|
stream=REQ(default=''),
|
||||||
version=REQ(converter=to_non_negative_int, default=1),
|
version=REQ(converter=to_non_negative_int, default=1),
|
||||||
|
@ -609,7 +610,7 @@ def beanstalk_decoder(view_func):
|
||||||
@authenticated_rest_api_view
|
@authenticated_rest_api_view
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def api_beanstalk_webhook(request, user_profile,
|
def api_beanstalk_webhook(request, user_profile,
|
||||||
payload=REQ(converter=json_to_dict)):
|
payload=REQ(validator=check_dict([]))):
|
||||||
# Beanstalk supports both SVN and git repositories
|
# Beanstalk supports both SVN and git repositories
|
||||||
# We distinguish between the two by checking for a
|
# We distinguish between the two by checking for a
|
||||||
# 'uri' key that is only present for git repos
|
# 'uri' key that is only present for git repos
|
||||||
|
@ -650,8 +651,8 @@ def api_deskdotcom_webhook(request, user_profile, data=REQ(),
|
||||||
|
|
||||||
@api_key_only_webhook_view
|
@api_key_only_webhook_view
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def api_newrelic_webhook(request, user_profile, alert=REQ(converter=json_to_dict, default=None),
|
def api_newrelic_webhook(request, user_profile, alert=REQ(validator=check_dict([]), default=None),
|
||||||
deployment=REQ(converter=json_to_dict, default=None)):
|
deployment=REQ(validator=check_dict([]), default=None)):
|
||||||
try:
|
try:
|
||||||
stream = request.GET['stream']
|
stream = request.GET['stream']
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
|
@ -678,7 +679,7 @@ def api_newrelic_webhook(request, user_profile, alert=REQ(converter=json_to_dict
|
||||||
|
|
||||||
@authenticated_rest_api_view
|
@authenticated_rest_api_view
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def api_bitbucket_webhook(request, user_profile, payload=REQ(converter=json_to_dict),
|
def api_bitbucket_webhook(request, user_profile, payload=REQ(validator=check_dict([])),
|
||||||
stream=REQ(default='commits')):
|
stream=REQ(default='commits')):
|
||||||
repository = payload['repository']
|
repository = payload['repository']
|
||||||
commits = [{'id': commit['raw_node'], 'message': commit['message'],
|
commits = [{'id': commit['raw_node'], 'message': commit['message'],
|
||||||
|
|
|
@ -5,11 +5,12 @@ from django.http import HttpResponseRedirect
|
||||||
from django.shortcuts import render_to_response, redirect
|
from django.shortcuts import render_to_response, redirect
|
||||||
from django.template import RequestContext, loader
|
from django.template import RequestContext, loader
|
||||||
|
|
||||||
from zerver.decorator import has_request_variables, REQ, json_to_dict
|
from zerver.decorator import has_request_variables, REQ
|
||||||
from zerver.lib.actions import internal_send_message
|
from zerver.lib.actions import internal_send_message
|
||||||
from zerver.lib.redis_utils import get_redis_client
|
from zerver.lib.redis_utils import get_redis_client
|
||||||
from zerver.lib.response import json_success, json_error, json_response, json_method_not_allowed
|
from zerver.lib.response import json_success, json_error, json_response, json_method_not_allowed
|
||||||
from zerver.lib.rest import rest_dispatch as _rest_dispatch
|
from zerver.lib.rest import rest_dispatch as _rest_dispatch
|
||||||
|
from zerver.lib.validator import check_dict
|
||||||
from zerver.models import get_realm, get_user_profile_by_email, resolve_email_to_domain, \
|
from zerver.models import get_realm, get_user_profile_by_email, resolve_email_to_domain, \
|
||||||
UserProfile
|
UserProfile
|
||||||
from zilencer.forms import EnterpriseToSForm
|
from zilencer.forms import EnterpriseToSForm
|
||||||
|
@ -43,7 +44,7 @@ def get_ticket_number():
|
||||||
return ticket_number
|
return ticket_number
|
||||||
|
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def submit_feedback(request, deployment, message=REQ(converter=json_to_dict)):
|
def submit_feedback(request, deployment, message=REQ(validator=check_dict([]))):
|
||||||
domainish = message["sender_domain"]
|
domainish = message["sender_domain"]
|
||||||
if get_realm("zulip.com") not in deployment.realms.all():
|
if get_realm("zulip.com") not in deployment.realms.all():
|
||||||
domainish += " via " + deployment.name
|
domainish += " via " + deployment.name
|
||||||
|
@ -78,7 +79,7 @@ def submit_feedback(request, deployment, message=REQ(converter=json_to_dict)):
|
||||||
return HttpResponse(message['sender_email'])
|
return HttpResponse(message['sender_email'])
|
||||||
|
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def report_error(request, deployment, type=REQ, report=REQ(converter=json_to_dict)):
|
def report_error(request, deployment, type=REQ, report=REQ(validator=check_dict([]))):
|
||||||
report['deployment'] = deployment.name
|
report['deployment'] = deployment.name
|
||||||
if type == 'browser':
|
if type == 'browser':
|
||||||
notify_browser_error(report)
|
notify_browser_error(report)
|
||||||
|
|
Loading…
Reference in New Issue