decorator: Clean up 'profile' variable reuse.

This commit is contained in:
Tim Abbott 2017-08-14 15:41:04 -07:00
parent a2011b5a48
commit 1144eed48b
1 changed files with 3 additions and 3 deletions

View File

@ -185,15 +185,15 @@ def validate_api_key(request, role, api_key, is_webhook=False):
if settings.ZILENCER_ENABLED and is_remote_server(role): if settings.ZILENCER_ENABLED and is_remote_server(role):
try: try:
profile = get_remote_server_by_uuid(role) # type: Union[UserProfile, RemoteZulipServer] remote_server = get_remote_server_by_uuid(role)
except RemoteZulipServer.DoesNotExist: except RemoteZulipServer.DoesNotExist:
raise JsonableError(_("Invalid Zulip server: %s") % (role,)) raise JsonableError(_("Invalid Zulip server: %s") % (role,))
if api_key != profile.api_key: if api_key != remote_server.api_key:
raise JsonableError(_("Invalid API key")) raise JsonableError(_("Invalid API key"))
if not check_subdomain(get_subdomain(request), ""): if not check_subdomain(get_subdomain(request), ""):
raise JsonableError(_("This API key only works on the root subdomain")) raise JsonableError(_("This API key only works on the root subdomain"))
return profile return remote_server
try: try:
profile = get_user_profile_by_email(role) profile = get_user_profile_by_email(role)