mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 13:33:24 +00:00 
			
		
		
		
	config_error: Coalesce redundant dicts.
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							536aa32255
						
					
				
				
					commit
					5506dffa36
				
			@@ -14,7 +14,7 @@
 | 
			
		||||
                <div class="errorcontent">
 | 
			
		||||
                    <h1 class="lead">{{ _("Configuration error") }}</h1>
 | 
			
		||||
                    <br />
 | 
			
		||||
                    {% if error_name == "ldap_error_realm_is_none" %}
 | 
			
		||||
                    {% if error_name == "ldap" %}
 | 
			
		||||
                        {% trans %}
 | 
			
		||||
                        You are trying to log in using LDAP without creating an
 | 
			
		||||
                        organization first. Please use EmailAuthBackend to create
 | 
			
		||||
@@ -22,7 +22,7 @@
 | 
			
		||||
                        {% endtrans %}
 | 
			
		||||
                    {% endif %}
 | 
			
		||||
 | 
			
		||||
                    {% if error_name == "smtp_error" %}
 | 
			
		||||
                    {% if error_name == "smtp" %}
 | 
			
		||||
                        <p>
 | 
			
		||||
                            It appears there are problems with the
 | 
			
		||||
                            email configuration.
 | 
			
		||||
@@ -47,7 +47,7 @@
 | 
			
		||||
                        {% endif %}
 | 
			
		||||
                    {% endif %}
 | 
			
		||||
 | 
			
		||||
                    {% if error_name == "dev_not_supported_error" %}
 | 
			
		||||
                    {% if error_name == "dev_not_supported" %}
 | 
			
		||||
                        {% include "zerver/authentication_backends/dev-not-supported-error.html" %}
 | 
			
		||||
                    {% endif %}
 | 
			
		||||
 | 
			
		||||
@@ -55,8 +55,8 @@
 | 
			
		||||
                        {% if development_environment %}
 | 
			
		||||
                        {% with %}
 | 
			
		||||
                            {% set settings_path = secrets_path %}
 | 
			
		||||
                            {% set client_id_key_name = "social_auth_" + social_backend_name + "_key" %}
 | 
			
		||||
                            {% include "zerver/authentication_backends/" + social_backend_name + "-error.html" %}
 | 
			
		||||
                            {% set client_id_key_name = "social_auth_" + error_name + "_key" %}
 | 
			
		||||
                            {% include "zerver/authentication_backends/" + error_name + "-error.html" %}
 | 
			
		||||
                        {% endwith %}
 | 
			
		||||
                        <p>
 | 
			
		||||
                            For more information, have a look at
 | 
			
		||||
@@ -65,8 +65,8 @@
 | 
			
		||||
                        </p>
 | 
			
		||||
                        {% else %}
 | 
			
		||||
                        {% with %}
 | 
			
		||||
                            {% set client_id_key_name = "SOCIAL_AUTH_" + social_backend_name.upper() + "_KEY" %}
 | 
			
		||||
                            {% include "zerver/authentication_backends/" + social_backend_name + "-error.html" %}
 | 
			
		||||
                            {% set client_id_key_name = "SOCIAL_AUTH_" + error_name.upper() + "_KEY" %}
 | 
			
		||||
                            {% include "zerver/authentication_backends/" + error_name + "-error.html" %}
 | 
			
		||||
                        {% endwith %}
 | 
			
		||||
                        <p>
 | 
			
		||||
                            For more information, have a look at
 | 
			
		||||
@@ -76,7 +76,7 @@
 | 
			
		||||
                        {% endif %}
 | 
			
		||||
                    {% endif %}
 | 
			
		||||
 | 
			
		||||
                    {% if social_backend_name == "saml" %}
 | 
			
		||||
                    {% if error_name == "saml" %}
 | 
			
		||||
                        <p>
 | 
			
		||||
                            SAML authentication is either not enabled or misconfigured. Have a look at
 | 
			
		||||
                            our <a href="https://zulip.readthedocs.io/en/latest/production/authentication-methods.html#SAML">setup guide</a>.
 | 
			
		||||
@@ -90,18 +90,19 @@
 | 
			
		||||
                        {% endif %}
 | 
			
		||||
                    {% endif %}
 | 
			
		||||
 | 
			
		||||
                    {% if error_name == "remoteuser_error_backend_disabled" %}
 | 
			
		||||
                    {% if error_name == "remote_user_backend_disabled" %}
 | 
			
		||||
                    <p>
 | 
			
		||||
                        Authentication via the REMOTE_USER header is
 | 
			
		||||
                        disabled in `/etc/zulip/settings.py`.
 | 
			
		||||
                    </p>
 | 
			
		||||
                    {% endif %}
 | 
			
		||||
                    {% if error_name == "remoteuser_error_remote_user_header_missing" %}
 | 
			
		||||
                    {% if error_name == "remote_user_header_missing" %}
 | 
			
		||||
                    <p>
 | 
			
		||||
                        The REMOTE_USER header is not set.
 | 
			
		||||
                    </p>
 | 
			
		||||
                    {% endif %}
 | 
			
		||||
                    {% if error_name == "oidc_error" %}
 | 
			
		||||
                    {% if error_name == "oidc" %}
 | 
			
		||||
                    {# TODO: Improve the config error page for OIDC #}
 | 
			
		||||
                    <p>
 | 
			
		||||
                        The OpenID Connect backend is not configured correctly.
 | 
			
		||||
                    </p>
 | 
			
		||||
 
 | 
			
		||||
@@ -5407,7 +5407,7 @@ class TestDevAuthBackend(ZulipTestCase):
 | 
			
		||||
        self.assert_in_success_response(["Configuration error", "DevAuthBackend"], response)
 | 
			
		||||
 | 
			
		||||
    def test_dev_direct_production_config_error(self) -> None:
 | 
			
		||||
        result = self.client_get("/config-error/dev")
 | 
			
		||||
        result = self.client_get("/config-error/dev_not_supported")
 | 
			
		||||
        self.assertEqual(result.status_code, 200)
 | 
			
		||||
        self.assert_in_success_response(["DevAuthBackend"], result)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -15,7 +15,6 @@ from zerver.lib.url_redirects import (
 | 
			
		||||
)
 | 
			
		||||
from zerver.models import Stream
 | 
			
		||||
from zproject import urls
 | 
			
		||||
from zproject.backends import AUTH_BACKEND_NAME_MAP
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class PublicURLTest(ZulipTestCase):
 | 
			
		||||
@@ -136,23 +135,19 @@ class PublicURLTest(ZulipTestCase):
 | 
			
		||||
        Here we simply sanity-check that all the URLs load
 | 
			
		||||
        correctly.
 | 
			
		||||
        """
 | 
			
		||||
        auth_types = [auth.lower() for auth in AUTH_BACKEND_NAME_MAP]
 | 
			
		||||
        for auth in [
 | 
			
		||||
            "azuread",
 | 
			
		||||
            "email",
 | 
			
		||||
            "remoteuser",
 | 
			
		||||
            # The endpoint is generated dynamically based on the configuration of the OIDC backend,
 | 
			
		||||
            # so it can't be tested here.
 | 
			
		||||
            "openid connect",
 | 
			
		||||
        ]:  # We do not have configerror pages for AzureAD and Email.
 | 
			
		||||
            auth_types.remove(auth)
 | 
			
		||||
 | 
			
		||||
        auth_types += [
 | 
			
		||||
        auth_error_pages = [
 | 
			
		||||
            "apple",
 | 
			
		||||
            "dev_not_supported",
 | 
			
		||||
            "github",
 | 
			
		||||
            "gitlab",
 | 
			
		||||
            "google",
 | 
			
		||||
            "ldap",
 | 
			
		||||
            "remote_user_backend_disabled",
 | 
			
		||||
            "remote_user_header_missing",
 | 
			
		||||
            "saml",
 | 
			
		||||
            "smtp",
 | 
			
		||||
            "remoteuser/remote_user_backend_disabled",
 | 
			
		||||
            "remoteuser/remote_user_header_missing",
 | 
			
		||||
        ]
 | 
			
		||||
        urls = [f"/config-error/{auth_type}" for auth_type in auth_types]
 | 
			
		||||
        urls = [f"/config-error/{err_page_name}" for err_page_name in auth_error_pages]
 | 
			
		||||
        with self.settings(DEVELOPMENT=True):
 | 
			
		||||
            for url in urls:
 | 
			
		||||
                response = self.client_get(url)
 | 
			
		||||
 
 | 
			
		||||
@@ -76,7 +76,7 @@ def dev_direct_login(
 | 
			
		||||
    if (not dev_auth_enabled()) or settings.PRODUCTION:
 | 
			
		||||
        # This check is probably not required, since authenticate would fail without
 | 
			
		||||
        # an enabled DevAuthBackend.
 | 
			
		||||
        return config_error(request, "dev")
 | 
			
		||||
        return config_error(request, "dev_not_supported")
 | 
			
		||||
 | 
			
		||||
    subdomain = get_subdomain(request)
 | 
			
		||||
    realm = get_realm(subdomain)
 | 
			
		||||
@@ -88,7 +88,7 @@ def dev_direct_login(
 | 
			
		||||
    email = request.POST["direct_email"]
 | 
			
		||||
    user_profile = authenticate(dev_auth_username=email, realm=realm)
 | 
			
		||||
    if user_profile is None:
 | 
			
		||||
        return config_error(request, "dev")
 | 
			
		||||
        return config_error(request, "dev_not_supported")
 | 
			
		||||
    assert isinstance(user_profile, UserProfile)
 | 
			
		||||
    do_login(request, user_profile)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -10,14 +10,8 @@ def config_error(request: HttpRequest, error_category_name: str) -> HttpResponse
 | 
			
		||||
        "google": {"social_backend_name": "google", "has_error_template": True},
 | 
			
		||||
        "github": {"social_backend_name": "github", "has_error_template": True},
 | 
			
		||||
        "gitlab": {"social_backend_name": "gitlab", "has_error_template": True},
 | 
			
		||||
        "ldap": {"error_name": "ldap_error_realm_is_none"},
 | 
			
		||||
        "dev": {"error_name": "dev_not_supported_error"},
 | 
			
		||||
        "saml": {"social_backend_name": "saml"},
 | 
			
		||||
        "smtp": {"error_name": "smtp_error"},
 | 
			
		||||
        "remote_user_backend_disabled": {"error_name": "remoteuser_error_backend_disabled"},
 | 
			
		||||
        "remote_user_header_missing": {"error_name": "remoteuser_error_remote_user_header_missing"},
 | 
			
		||||
        # TODO: Improve the config error page for OIDC.
 | 
			
		||||
        "oidc": {"error_name": "oidc_error"},
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return render(request, "zerver/config_error.html", contexts[error_category_name])
 | 
			
		||||
    context = contexts.get(error_category_name, {})
 | 
			
		||||
    context["error_name"] = error_category_name
 | 
			
		||||
    return render(request, "zerver/config_error.html", context)
 | 
			
		||||
 
 | 
			
		||||
@@ -92,7 +92,6 @@ urls = [
 | 
			
		||||
    ),
 | 
			
		||||
    path("devtools/integrations/<integration_name>/fixtures", get_fixtures),
 | 
			
		||||
    path("config-error/<error_category_name>", config_error, name="config_error"),
 | 
			
		||||
    path("config-error/remoteuser/<error_category_name>", config_error),
 | 
			
		||||
    # Special endpoint to remove all the server-side caches.
 | 
			
		||||
    path("flush_caches", remove_caches),
 | 
			
		||||
    # Redirect camo URLs for development
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user