Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

portico: Extract communities directory eligibility criteria.

Prakhar Pratyushbb05423e5f2b
diff --git a/corporate/lib/communities_directory.py b/corporate/lib/communities_directory.py
new file mode 100644
index 00000000000..c44ac9e0a72
--- /dev/null
+++ b/corporate/lib/communities_directory.py
@@ -0,0 +1,23 @@
+def meets_communities_directory_base_criteria(
+ *,
+ description: str,
+ invite_required: bool,
+ emails_restricted_to_domains: bool,
+ has_web_public_streams: bool,
+ is_demo_organization: bool,
+) -> bool:
+ """The criteria an organization asking to be advertised in the
+ communities directory must meet.
+
+ These are all the required criteria for cloud orgs; a remote
+ organization must additionally be reachable.
+ """
+ if description == "":
+ # Organizations that never wrote a description.
+ return False
+
+ if is_demo_organization:
+ return False
+
+ open_to_public = not invite_required and not emails_restricted_to_domains
+ return has_web_public_streams or open_to_public
diff --git a/corporate/views/portico.py b/corporate/views/portico.py
index 384450a8bb0..13ab5c28e16 100644
--- a/corporate/views/portico.py
+++ b/corporate/views/portico.py
@@ -9,6 +9,7 @@ from django.template.response import TemplateResponse
from django.urls import reverse
from pydantic import Json
+from corporate.lib.communities_directory import meets_communities_directory_base_criteria
from corporate.lib.decorator import (
authenticated_remote_realm_management_endpoint,
authenticated_remote_server_management_endpoint,
@@ -333,14 +334,6 @@ def communities_view(request: HttpRequest) -> HttpResponse:
Realm.objects.filter(
want_advertise_in_communities_directory=True,
)
- .exclude(
- # Filter out realms who haven't changed their description from the default.
- description="",
- )
- .exclude(
- # Filter out demo organizations.
- demo_organization_scheduled_deletion_date__isnull=False,
- )
.exclude(
# Filter out deactivated organizations.
deactivated=True,
@@ -348,8 +341,13 @@ def communities_view(request: HttpRequest) -> HttpResponse:
.order_by("name")
)
for realm in want_to_be_advertised_realms:
- open_to_public = not realm.invite_required and not realm.emails_restricted_to_domains
- if realm.allow_web_public_streams_access() or open_to_public:
+ if meets_communities_directory_base_criteria(
+ description=realm.description,
+ invite_required=realm.invite_required,
+ emails_restricted_to_domains=realm.emails_restricted_to_domains,
+ has_web_public_streams=realm.allow_web_public_streams_access(),
+ is_demo_organization=realm.demo_organization_scheduled_deletion_date is not None,
+ ):
[org_type] = (
org_type
for org_type in Realm.ORG_TYPES