Expose an endpoint to identify the API/webclient bases for a particular user.

We fall back to guessing based on the realm if the user doesn't have a
profile in our system

(imported from commit 833885168c451074c885b4422d62986855a215f7)
This commit is contained in:
Luke Faraone
2013-10-23 18:27:52 -04:00
parent a1b44986e0
commit 2d787e952b
4 changed files with 42 additions and 3 deletions

View File

@@ -1,12 +1,14 @@
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt, csrf_protect
from zerver.models import get_realm
from zerver.lib.actions import internal_send_message
from zerver.decorator import has_request_variables, REQ, json_to_dict
from zerver.lib.actions import internal_send_message
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.models import get_realm, get_user_profile_by_email, email_to_domain, \
UserProfile, Realm
from zilencer.models import Deployment
from zerver.lib.rest import rest_dispatch as _rest_dispatch
rest_dispatch = csrf_exempt((lambda request, *args, **kwargs: _rest_dispatch(request, globals(), *args, **kwargs)))
@@ -46,3 +48,15 @@ def submit_feedback(request, deployment, message=REQ(converter=json_to_dict)):
internal_send_message("feedback@zulip.com", "stream", "support", subject, content)
return HttpResponse(message['sender_email'])
# Requests made to this endpoint are UNAUTHENTICATED
@csrf_exempt
@has_request_variables
def lookup_endpoints_for_user(request, email=REQ()):
try:
return json_response(get_user_profile_by_email(email).realm.deployment.endpoints)
except UserProfile.DoesNotExist:
try:
return json_response(get_realm(email_to_domain(email)).deployment.endpoints)
except AttributeError:
return json_error("Cannot determine endpoint for user.", status=404)