mirror of https://github.com/zulip/zulip.git
Add route to fetch emails for mobile passwordless login.
[Tweaked by tabbott to rename API to explicitly support not just Android]
This commit is contained in:
parent
7ea0eaed1c
commit
007eee6061
|
@ -231,3 +231,17 @@ class DevFetchAPIKeyTest(AuthedTestCase):
|
|||
result = self.client.post("/api/v1/dev_fetch_api_key",
|
||||
dict(username=self.email))
|
||||
self.assert_json_error_contains(result, "Dev environment not enabled.", 400)
|
||||
|
||||
class DevGetEmailsTest(AuthedTestCase):
|
||||
def test_success(self):
|
||||
# type: () -> None
|
||||
result = self.client.get("/api/v1/dev_get_emails")
|
||||
self.assert_json_success(result)
|
||||
self.assertIn("direct_admins", result.content)
|
||||
self.assertIn("direct_users", result.content)
|
||||
|
||||
def test_dev_auth_disabled(self):
|
||||
# type: () -> None
|
||||
with mock.patch('zerver.views.dev_auth_enabled', return_value=False):
|
||||
result = self.client.get("/api/v1/dev_get_emails")
|
||||
self.assert_json_error_contains(result, "Dev environment not enabled.", 400)
|
||||
|
|
|
@ -612,6 +612,17 @@ def api_dev_fetch_api_key(request, username=REQ()):
|
|||
login(request, user_profile)
|
||||
return json_success({"api_key": user_profile.api_key, "email": user_profile.email})
|
||||
|
||||
@csrf_exempt
|
||||
def api_dev_get_emails(request):
|
||||
# type: (HttpRequest) -> HttpResponse
|
||||
if not dev_auth_enabled() or settings.PRODUCTION:
|
||||
return json_error(_("Dev environment not enabled."))
|
||||
MAX_DEV_BACKEND_USERS = 100 # type: int
|
||||
users_query = UserProfile.objects.select_related().filter(is_bot=False, is_active=True)
|
||||
users = users_query.order_by('email')[0:MAX_DEV_BACKEND_USERS]
|
||||
return json_success(dict(direct_admins=[u.email for u in users if u.is_realm_admin],
|
||||
direct_users=[u.email for u in users if not u.is_realm_admin]))
|
||||
|
||||
@authenticated_json_post_view
|
||||
@has_request_variables
|
||||
def json_bulk_invite_users(request, user_profile,
|
||||
|
|
|
@ -142,6 +142,9 @@ urlpatterns += patterns('zerver.views',
|
|||
|
||||
# This is for the signing in through the devAuthBackEnd on mobile apps.
|
||||
url(r'^api/v1/dev_fetch_api_key$', 'api_dev_fetch_api_key'),
|
||||
# This is for fetching the emails of the admins and the users.
|
||||
url(r'^api/v1/dev_get_emails$', 'api_dev_get_emails'),
|
||||
|
||||
# Used to present the GOOGLE_CLIENT_ID to mobile apps
|
||||
url(r'^api/v1/fetch_google_client_id$', 'api_fetch_google_client_id'),
|
||||
|
||||
|
|
Loading…
Reference in New Issue