Ejemplo n.º 1
0
    def test_do_change_realm_description_clears_cached_descriptions(self) -> None:
        realm = get_realm("zulip")
        rendered_description = get_realm_rendered_description(realm)
        text_description = get_realm_text_description(realm)

        realm.description = "New description"
        realm.save(update_fields=["description"])

        new_rendered_description = get_realm_rendered_description(realm)
        self.assertNotEqual(rendered_description, new_rendered_description)
        self.assertIn(realm.description, new_rendered_description)

        new_text_description = get_realm_text_description(realm)
        self.assertNotEqual(text_description, new_text_description)
        self.assertEqual(realm.description, new_text_description)
Ejemplo n.º 2
0
def login_context(request: HttpRequest) -> Dict[str, Any]:
    realm = get_realm_from_request(request)

    if realm is None:
        realm_description = None
        realm_invite_required = False
        realm_web_public_access_enabled = False
    else:
        realm_description = get_realm_rendered_description(realm)
        realm_invite_required = realm.invite_required
        # We offer web-public access only if the realm has actual web
        # public streams configured, in addition to having it enabled.
        realm_web_public_access_enabled = realm.allow_web_public_streams_access(
        )

    context: Dict[str, Any] = {
        "realm_invite_required": realm_invite_required,
        "realm_description": realm_description,
        "require_email_format_usernames":
        require_email_format_usernames(realm),
        "password_auth_enabled": password_auth_enabled(realm),
        "two_factor_authentication_enabled":
        settings.TWO_FACTOR_AUTHENTICATION_ENABLED,
        "realm_web_public_access_enabled": realm_web_public_access_enabled,
    }

    if realm is not None and realm.description:
        context["OPEN_GRAPH_TITLE"] = realm.name
        context["OPEN_GRAPH_DESCRIPTION"] = get_realm_text_description(realm)

    # Add the keys for our standard authentication backends.
    no_auth_enabled = True
    for auth_backend_name in AUTH_BACKEND_NAME_MAP:
        name_lower = auth_backend_name.lower()
        key = f"{name_lower}_auth_enabled"
        is_enabled = auth_enabled_helper([auth_backend_name], realm)
        context[key] = is_enabled
        if is_enabled:
            no_auth_enabled = False

    context["external_authentication_methods"] = get_external_method_dicts(
        realm)
    context["no_auth_enabled"] = no_auth_enabled

    # Include another copy of external_authentication_methods in page_params for use
    # by the desktop client. We expand it with IDs of the <button> elements corresponding
    # to the authentication methods.
    context["page_params"] = dict(
        external_authentication_methods=get_external_method_dicts(realm), )
    for auth_dict in context["page_params"]["external_authentication_methods"]:
        auth_dict["button_id_suffix"] = "auth_button_{}".format(
            auth_dict["name"])

    return context
Ejemplo n.º 3
0
def login_context(request: HttpRequest) -> Dict[str, Any]:
    realm = get_realm_from_request(request)

    if realm is None:
        realm_description = None
        realm_invite_required = False
    else:
        realm_description = get_realm_rendered_description(realm)
        realm_invite_required = realm.invite_required

    context: Dict[str, Any] = {
        'realm_invite_required':
        realm_invite_required,
        'realm_description':
        realm_description,
        'require_email_format_usernames':
        require_email_format_usernames(realm),
        'password_auth_enabled':
        password_auth_enabled(realm),
        'any_social_backend_enabled':
        any_social_backend_enabled(realm),
        'two_factor_authentication_enabled':
        settings.TWO_FACTOR_AUTHENTICATION_ENABLED,
    }

    if realm is not None and realm.description:
        context['OPEN_GRAPH_TITLE'] = realm.name
        context['OPEN_GRAPH_DESCRIPTION'] = get_realm_text_description(realm)

    # Add the keys for our standard authentication backends.
    no_auth_enabled = True
    for auth_backend_name in AUTH_BACKEND_NAME_MAP:
        name_lower = auth_backend_name.lower()
        key = f"{name_lower}_auth_enabled"
        is_enabled = auth_enabled_helper([auth_backend_name], realm)
        context[key] = is_enabled
        if is_enabled:
            no_auth_enabled = False

    context['external_authentication_methods'] = get_external_method_dicts(
        realm)
    context['no_auth_enabled'] = no_auth_enabled

    # Include another copy of external_authentication_methods in page_params for use
    # by the desktop client. We expand it with IDs of the <button> elements corresponding
    # to the authentication methods.
    context['page_params'] = dict(
        external_authentication_methods=get_external_method_dicts(realm), )
    for auth_dict in context['page_params']['external_authentication_methods']:
        auth_dict['button_id_suffix'] = "auth_button_{}".format(
            auth_dict['name'])

    return context
Ejemplo n.º 4
0
def login_context(request: HttpRequest) -> Dict[str, Any]:
    realm = get_realm_from_request(request)

    if realm is None:
        realm_description = None
        realm_invite_required = False
    else:
        realm_description = get_realm_rendered_description(realm)
        realm_invite_required = realm.invite_required

    context = {
        'realm_invite_required':
        realm_invite_required,
        'realm_description':
        realm_description,
        'require_email_format_usernames':
        require_email_format_usernames(realm),
        'password_auth_enabled':
        password_auth_enabled(realm),
        'any_social_backend_enabled':
        any_social_backend_enabled(realm),
        'two_factor_authentication_enabled':
        settings.TWO_FACTOR_AUTHENTICATION_ENABLED,
    }  # type: Dict[str, Any]

    if realm is not None and realm.description:
        context['OPEN_GRAPH_TITLE'] = realm.name
        context['OPEN_GRAPH_DESCRIPTION'] = get_realm_text_description(realm)

    # Add the keys for our standard authentication backends.
    no_auth_enabled = True
    for auth_backend_name in AUTH_BACKEND_NAME_MAP:
        name_lower = auth_backend_name.lower()
        key = "%s_auth_enabled" % (name_lower, )
        is_enabled = auth_enabled_helper([auth_backend_name], realm)
        context[key] = is_enabled
        if is_enabled:
            no_auth_enabled = False

    context['external_authentication_methods'] = get_external_method_dicts(
        realm)
    context['no_auth_enabled'] = no_auth_enabled

    return context
Ejemplo n.º 5
0
def login_context(request: HttpRequest) -> Dict[str, Any]:
    realm = get_realm_from_request(request)

    if realm is None:
        realm_description = None
        realm_invite_required = False
    else:
        realm_description = get_realm_rendered_description(realm)
        realm_invite_required = realm.invite_required

    context = {
        'realm_invite_required':
        realm_invite_required,
        'realm_description':
        realm_description,
        'require_email_format_usernames':
        require_email_format_usernames(realm),
        'password_auth_enabled':
        password_auth_enabled(realm),
        'any_oauth_backend_enabled':
        any_oauth_backend_enabled(realm),
        'two_factor_authentication_enabled':
        settings.TWO_FACTOR_AUTHENTICATION_ENABLED,
    }  # type: Dict[str, Any]

    if realm is not None and realm.description:
        context['OPEN_GRAPH_TITLE'] = realm.name
        context['OPEN_GRAPH_DESCRIPTION'] = get_realm_text_description(realm)

    # Add the keys for our standard authentication backends.
    no_auth_enabled = True
    social_backends = []
    for auth_backend_name in AUTH_BACKEND_NAME_MAP:
        name_lower = auth_backend_name.lower()
        key = "%s_auth_enabled" % (name_lower, )
        is_enabled = auth_enabled_helper([auth_backend_name], realm)
        context[key] = is_enabled
        if is_enabled:
            no_auth_enabled = False

        # Now add the enabled social backends to the social_backends
        # list used to generate buttons for login/register pages.
        backend = AUTH_BACKEND_NAME_MAP[auth_backend_name]
        if not is_enabled or backend not in SOCIAL_AUTH_BACKENDS:
            continue
        social_backends.append({
            'name':
            backend.name,
            'display_name':
            backend.auth_backend_name,
            'login_url':
            reverse('login-social', args=(backend.name, )),
            'signup_url':
            reverse('signup-social', args=(backend.name, )),
            'sort_order':
            backend.sort_order,
        })
    context['social_backends'] = sorted(social_backends,
                                        key=lambda x: x['sort_order'],
                                        reverse=True)
    context['no_auth_enabled'] = no_auth_enabled

    return context