From 11fcbe52a6785f8809cde56eceba4f1e1281133f Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Tue, 18 Dec 2018 16:13:59 -0800 Subject: [PATCH] auth: Automate calculation of get_auth_backends_data. This change lets us eliminate the need for new authentication backends to edit get_auth_backends_data, since we're just computing it from the official registry in zproject/backends.py. Should save a few lines of work whenever we add a new auth backend, and make that more accessible to new contributors. --- zerver/views/auth.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/zerver/views/auth.py b/zerver/views/auth.py index 1cc36ffa01..137cef9e5d 100644 --- a/zerver/views/auth.py +++ b/zerver/views/auth.py @@ -38,9 +38,8 @@ from zerver.models import PreregistrationUser, UserProfile, remote_user_to_email get_realm from zerver.signals import email_on_new_login from zproject.backends import password_auth_enabled, dev_auth_enabled, \ - github_auth_enabled, google_auth_enabled, ldap_auth_enabled, \ - ZulipLDAPConfigurationError, ZulipLDAPAuthBackend, email_auth_enabled, \ - remote_auth_enabled + ldap_auth_enabled, ZulipLDAPConfigurationError, ZulipLDAPAuthBackend, \ + AUTH_BACKEND_NAME_MAP, auth_enabled_helper from version import ZULIP_VERSION import hashlib @@ -827,15 +826,13 @@ def get_auth_backends_data(request: HttpRequest) -> Dict[str, Any]: raise JsonableError(_("Subdomain required")) else: realm = None - return { + result = { "password": password_auth_enabled(realm), - "dev": dev_auth_enabled(realm), - "email": email_auth_enabled(realm), - "github": github_auth_enabled(realm), - "google": google_auth_enabled(realm), - "remoteuser": remote_auth_enabled(realm), - "ldap": ldap_auth_enabled(realm), } + for auth_backend_name in AUTH_BACKEND_NAME_MAP: + key = auth_backend_name.lower() + result[key] = auth_enabled_helper([auth_backend_name], realm) + return result @csrf_exempt def api_get_auth_backends(request: HttpRequest) -> HttpResponse: