authenticated_rest_api_view: Use is_remote_server.

Using is_remote_server is more readable and future-proof since
it provides a level of abstraction.
This commit is contained in:
Umair Khan 2017-04-28 11:52:04 +05:00 committed by Tim Abbott
parent e6cc0ffcdd
commit 4e2a6834d8
1 changed files with 5 additions and 4 deletions

View File

@ -455,14 +455,15 @@ def authenticated_rest_api_view(is_webhook=False):
except JsonableError as e: except JsonableError as e:
return json_unauthorized(e.error) return json_unauthorized(e.error)
request.user = profile request.user = profile
if isinstance(profile, UserProfile): if is_remote_server(role):
request._email = profile.email
process_client(request, profile)
else:
assert isinstance(profile, RemoteZulipServer) # type: ignore # https://github.com/python/mypy/issues/2957 assert isinstance(profile, RemoteZulipServer) # type: ignore # https://github.com/python/mypy/issues/2957
request._email = "zulip-server:" + role request._email = "zulip-server:" + role
profile.rate_limits = "" profile.rate_limits = ""
process_client(request, profile, remote_server_request=True) process_client(request, profile, remote_server_request=True)
else:
assert isinstance(profile, UserProfile) # type: ignore # https://github.com/python/mypy/issues/2957
request._email = profile.email
process_client(request, profile)
# Apply rate limiting # Apply rate limiting
return rate_limit()(view_func)(request, profile, *args, **kwargs) return rate_limit()(view_func)(request, profile, *args, **kwargs)
return _wrapped_func_arguments return _wrapped_func_arguments