mirror of https://github.com/zulip/zulip.git
Desupport using uninstantiated REQ with has_request_variables.
This makes life difficult for doing static type annotations, and didn't make the code look that much better anyway.
This commit is contained in:
parent
41336f3782
commit
960144a49e
|
@ -170,7 +170,7 @@ def api_key_only_webhook_view(client_name):
|
|||
@csrf_exempt
|
||||
@has_request_variables
|
||||
@wraps(view_func)
|
||||
def _wrapped_func_arguments(request, api_key=REQ,
|
||||
def _wrapped_func_arguments(request, api_key=REQ(),
|
||||
*args, **kwargs):
|
||||
|
||||
try:
|
||||
|
@ -280,7 +280,7 @@ def authenticated_api_view(view_func):
|
|||
@require_post
|
||||
@has_request_variables
|
||||
@wraps(view_func)
|
||||
def _wrapped_view_func(request, email=REQ, api_key=REQ('api_key', default=None),
|
||||
def _wrapped_view_func(request, email=REQ(), api_key=REQ('api_key', default=None),
|
||||
api_key_legacy=REQ('api-key', default=None),
|
||||
*args, **kwargs):
|
||||
if not api_key and not api_key_legacy:
|
||||
|
|
|
@ -106,13 +106,6 @@ def has_request_variables(view_func):
|
|||
if value.post_var_name is None:
|
||||
value.post_var_name = name
|
||||
post_params.append(value)
|
||||
elif value == REQ:
|
||||
# If the function definition does not actually instantiate
|
||||
# a REQ object but instead uses the REQ class itself as a
|
||||
# value, we instantiate it as a convenience
|
||||
post_var = value(name)
|
||||
post_var.func_var_name = name
|
||||
post_params.append(post_var)
|
||||
|
||||
@wraps(view_func)
|
||||
def _wrapped_view_func(request, *args, **kwargs):
|
||||
|
|
|
@ -322,7 +322,7 @@ def api_endpoint_docs(request):
|
|||
|
||||
@authenticated_json_post_view
|
||||
@has_request_variables
|
||||
def json_invite_users(request, user_profile, invitee_emails=REQ):
|
||||
def json_invite_users(request, user_profile, invitee_emails=REQ()):
|
||||
if not invitee_emails:
|
||||
return json_error("You must specify at least one email address.")
|
||||
|
||||
|
@ -1079,7 +1079,7 @@ def get_uploaded_file(request, realm_id, filename,
|
|||
@csrf_exempt
|
||||
@require_post
|
||||
@has_request_variables
|
||||
def api_fetch_api_key(request, username=REQ, password=REQ):
|
||||
def api_fetch_api_key(request, username=REQ(), password=REQ()):
|
||||
# type: (Any, Any, Any) -> Any
|
||||
return_data = {} # type: Dict[str, bool]
|
||||
if username == "google-oauth2-token":
|
||||
|
@ -1117,7 +1117,7 @@ def get_status_list(requesting_user_profile):
|
|||
'server_timestamp': time.time()}
|
||||
|
||||
@has_request_variables
|
||||
def update_active_status_backend(request, user_profile, status=REQ,
|
||||
def update_active_status_backend(request, user_profile, status=REQ(),
|
||||
new_user_input=REQ(validator=check_bool, default=False)):
|
||||
status_val = UserPresence.status_from_string(status)
|
||||
if status_val is None:
|
||||
|
@ -1184,7 +1184,7 @@ def events_register_backend(request, user_profile, apply_markdown=True,
|
|||
|
||||
@authenticated_json_post_view
|
||||
@has_request_variables
|
||||
def json_refer_friend(request, user_profile, email=REQ):
|
||||
def json_refer_friend(request, user_profile, email=REQ()):
|
||||
if not email:
|
||||
return json_error("No email address specified")
|
||||
if user_profile.invites_granted - user_profile.invites_used <= 0:
|
||||
|
@ -1221,11 +1221,11 @@ def add_push_device_token(request, user_profile, token, kind, ios_app_id=None):
|
|||
return json_success()
|
||||
|
||||
@has_request_variables
|
||||
def add_apns_device_token(request, user_profile, token=REQ, appid=REQ(default=settings.ZULIP_IOS_APP_ID)):
|
||||
def add_apns_device_token(request, user_profile, token=REQ(), appid=REQ(default=settings.ZULIP_IOS_APP_ID)):
|
||||
return add_push_device_token(request, user_profile, token, PushDeviceToken.APNS, ios_app_id=appid)
|
||||
|
||||
@has_request_variables
|
||||
def add_android_reg_id(request, user_profile, token=REQ):
|
||||
def add_android_reg_id(request, user_profile, token=REQ()):
|
||||
return add_push_device_token(request, user_profile, token, PushDeviceToken.GCM)
|
||||
|
||||
def remove_push_device_token(request, user_profile, token, kind):
|
||||
|
@ -1241,11 +1241,11 @@ def remove_push_device_token(request, user_profile, token, kind):
|
|||
return json_success()
|
||||
|
||||
@has_request_variables
|
||||
def remove_apns_device_token(request, user_profile, token=REQ):
|
||||
def remove_apns_device_token(request, user_profile, token=REQ()):
|
||||
return remove_push_device_token(request, user_profile, token, PushDeviceToken.APNS)
|
||||
|
||||
@has_request_variables
|
||||
def remove_android_reg_id(request, user_profile, token=REQ):
|
||||
def remove_android_reg_id(request, user_profile, token=REQ()):
|
||||
return remove_push_device_token(request, user_profile, token, PushDeviceToken.GCM)
|
||||
|
||||
|
||||
|
|
|
@ -809,7 +809,7 @@ def json_fetch_raw_message(request, user_profile,
|
|||
return json_success({"raw_content": message.content})
|
||||
|
||||
@has_request_variables
|
||||
def render_message_backend(request, user_profile, content=REQ):
|
||||
def render_message_backend(request, user_profile, content=REQ()):
|
||||
rendered_content = bugdown.convert(content, user_profile.realm.domain)
|
||||
return json_success({"rendered": rendered_content})
|
||||
|
||||
|
|
|
@ -68,9 +68,9 @@ def json_report_unnarrow_time(request, user_profile,
|
|||
|
||||
@authenticated_json_post_view
|
||||
@has_request_variables
|
||||
def json_report_error(request, user_profile, message=REQ, stacktrace=REQ,
|
||||
ui_message=REQ(validator=check_bool), user_agent=REQ,
|
||||
href=REQ, log=REQ,
|
||||
def json_report_error(request, user_profile, message=REQ(), stacktrace=REQ(),
|
||||
ui_message=REQ(validator=check_bool), user_agent=REQ(),
|
||||
href=REQ(), log=REQ(),
|
||||
more_info=REQ(validator=check_dict([]), default=None)):
|
||||
|
||||
if not settings.ERROR_REPORTING:
|
||||
|
|
|
@ -125,34 +125,34 @@ def deactivate_stream_backend(request, user_profile, stream_name):
|
|||
|
||||
@require_realm_admin
|
||||
@has_request_variables
|
||||
def add_default_stream(request, user_profile, stream_name=REQ):
|
||||
def add_default_stream(request, user_profile, stream_name=REQ()):
|
||||
do_add_default_stream(user_profile.realm, stream_name)
|
||||
return json_success()
|
||||
|
||||
@require_realm_admin
|
||||
@has_request_variables
|
||||
def remove_default_stream(request, user_profile, stream_name=REQ):
|
||||
def remove_default_stream(request, user_profile, stream_name=REQ()):
|
||||
do_remove_default_stream(user_profile.realm, stream_name)
|
||||
return json_success()
|
||||
|
||||
@authenticated_json_post_view
|
||||
@require_realm_admin
|
||||
@has_request_variables
|
||||
def json_rename_stream(request, user_profile, old_name=REQ, new_name=REQ):
|
||||
def json_rename_stream(request, user_profile, old_name=REQ(), new_name=REQ()):
|
||||
do_rename_stream(user_profile.realm, old_name, new_name)
|
||||
return json_success()
|
||||
|
||||
@authenticated_json_post_view
|
||||
@require_realm_admin
|
||||
@has_request_variables
|
||||
def json_make_stream_public(request, user_profile, stream_name=REQ):
|
||||
def json_make_stream_public(request, user_profile, stream_name=REQ()):
|
||||
do_make_stream_public(user_profile, user_profile.realm, stream_name)
|
||||
return json_success()
|
||||
|
||||
@authenticated_json_post_view
|
||||
@require_realm_admin
|
||||
@has_request_variables
|
||||
def json_make_stream_private(request, user_profile, stream_name=REQ):
|
||||
def json_make_stream_private(request, user_profile, stream_name=REQ()):
|
||||
do_make_stream_private(user_profile.realm, stream_name)
|
||||
return json_success()
|
||||
|
||||
|
@ -404,7 +404,7 @@ def get_streams_backend(request, user_profile,
|
|||
|
||||
@authenticated_json_post_view
|
||||
@has_request_variables
|
||||
def json_stream_exists(request, user_profile, stream=REQ,
|
||||
def json_stream_exists(request, user_profile, stream=REQ(),
|
||||
autosubscribe=REQ(default=False)):
|
||||
return stream_exists_backend(request, user_profile, stream, autosubscribe)
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ def json_change_ui_settings(request, user_profile,
|
|||
@authenticated_json_post_view
|
||||
@has_request_variables
|
||||
def json_change_settings(request, user_profile,
|
||||
full_name=REQ,
|
||||
full_name=REQ(),
|
||||
old_password=REQ(default=""),
|
||||
new_password=REQ(default=""),
|
||||
confirm_password=REQ(default="")):
|
||||
|
|
|
@ -164,7 +164,7 @@ def regenerate_bot_api_key(request, user_profile, email):
|
|||
return json_success(json_result)
|
||||
|
||||
@has_request_variables
|
||||
def add_bot_backend(request, user_profile, full_name=REQ, short_name=REQ,
|
||||
def add_bot_backend(request, user_profile, full_name=REQ(), short_name=REQ(),
|
||||
default_sending_stream=REQ(default=None),
|
||||
default_events_register_stream=REQ(default=None),
|
||||
default_all_public_streams=REQ(validator=check_bool, default=None)):
|
||||
|
@ -266,8 +266,8 @@ def get_members_backend(request, user_profile):
|
|||
|
||||
@require_realm_admin
|
||||
@has_request_variables
|
||||
def create_user_backend(request, user_profile, email=REQ, password=REQ,
|
||||
full_name=REQ, short_name=REQ):
|
||||
def create_user_backend(request, user_profile, email=REQ(), password=REQ(),
|
||||
full_name=REQ(), short_name=REQ()):
|
||||
form = CreateUserForm({'full_name': full_name, 'email': email})
|
||||
if not form.is_valid():
|
||||
return json_error('Bad name or username')
|
||||
|
|
|
@ -124,7 +124,7 @@ def api_github_v2(user_profile, event, payload, branches, default_stream, commit
|
|||
|
||||
@authenticated_api_view
|
||||
@has_request_variables
|
||||
def api_github_landing(request, user_profile, event=REQ,
|
||||
def api_github_landing(request, user_profile, event=REQ(),
|
||||
payload=REQ(validator=check_dict([])),
|
||||
branches=REQ(default=''),
|
||||
stream=REQ(default=''),
|
||||
|
|
|
@ -76,7 +76,7 @@ def submit_feedback(request, deployment, message=REQ(validator=check_dict([]))):
|
|||
return HttpResponse(message['sender_email'])
|
||||
|
||||
@has_request_variables
|
||||
def report_error(request, deployment, type=REQ, report=REQ(validator=check_dict([]))):
|
||||
def report_error(request, deployment, type=REQ(), report=REQ(validator=check_dict([]))):
|
||||
report['deployment'] = deployment.name
|
||||
if type == 'browser':
|
||||
notify_browser_error(report)
|
||||
|
|
Loading…
Reference in New Issue