Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
realm: Enable spectator access by default in development.
Aman Agrawal00d3b8825798
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.pyindex b9476a3f0e5..48b2ea79f72 100644--- a/zerver/lib/actions.py+++ b/zerver/lib/actions.py@@ -5067,6 +5067,7 @@ def do_create_realm(org_type: Optional[int] = None,date_created: Optional[datetime.datetime] = None,is_demo_organization: Optional[bool] = False,+ enable_spectator_access: Optional[bool] = False,) -> Realm:if string_id == settings.SOCIAL_AUTH_SUBDOMAIN:raise AssertionError("Creating a realm on SOCIAL_AUTH_SUBDOMAIN is not allowed!")@@ -5089,6 +5090,8 @@ def do_create_realm(kwargs["plan_type"] = plan_typeif org_type is not None:kwargs["org_type"] = org_type+ if enable_spectator_access is not None:+ kwargs["enable_spectator_access"] = enable_spectator_accessif date_created is not None:# The date_created parameter is intended only for use by testdiff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.pyindex 6529cb0cb0d..0a819c790dd 100644--- a/zerver/tests/test_home.py+++ b/zerver/tests/test_home.py@@ -313,11 +313,21 @@ class HomeTest(ZulipTestCase):self.assertEqual(result.url, "/login/")# Tell server that user wants to login anonymously- # Redirects to load webapp. Since Realm.enable_spectator_access- # is False, the login should fail.+ # Redirects to load webapp.realm = get_realm("zulip")result = self.client_post("/", {"prefers_web_public_view": "true"})- self.assertEqual(self.client.session.get("prefers_web_public_view"), None)+ self.assertEqual(self.client.session.get("prefers_web_public_view"), True)+ self.assertEqual(realm.enable_spectator_access, True)+ self.assertEqual(result.status_code, 302)+ self.assertEqual(result.url, "http://zulip.testserver")++ # Disable spectator login. Since Realm.enable_spectator_access+ # is False, the login should fail.+ realm.enable_spectator_access = False+ realm.save()++ result = self.client_post("/", {"prefers_web_public_view": "true"})+ self.assertEqual(self.client.session.get("prefers_web_public_view"), True)self.assertEqual(realm.enable_spectator_access, False)self.assertEqual(result.status_code, 302)self.assertEqual(result.url, "/login/")@@ -352,9 +362,6 @@ class HomeTest(ZulipTestCase):self.client_get("/")self.assertEqual(self.client.session.get("prefers_web_public_view"), None)- realm.enable_spectator_access = False- realm.save()-def test_home_under_2fa_without_otp_device(self) -> None:with self.settings(TWO_FACTOR_AUTHENTICATION_ENABLED=True):self.login("iago")diff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.pyindex 564da1cb2f7..a7dcf182e5b 100644--- a/zerver/tests/test_realm.py+++ b/zerver/tests/test_realm.py@@ -93,6 +93,13 @@ class RealmTest(ZulipTestCase):self.assertEqual(realm.user_group_edit_policy, Realm.POLICY_MODERATORS_ONLY)self.assertEqual(realm.invite_to_stream_policy, Realm.POLICY_MODERATORS_ONLY)+ def test_realm_enable_spectator_access(self) -> None:+ realm = do_create_realm("test_web_public_true", "Foo", enable_spectator_access=True)+ self.assertEqual(realm.enable_spectator_access, True)++ realm = do_create_realm("test_web_public_false", "Boo", enable_spectator_access=False)+ self.assertEqual(realm.enable_spectator_access, False)+def test_do_set_realm_name_caching(self) -> None:"""The main complicated thing about setting realm names is fighting thecache, and we start by populating the cache for Hamlet, and we enddiff --git a/zilencer/management/commands/populate_db.py b/zilencer/management/commands/populate_db.pyindex 2fea0e1584b..1ad08b59ec4 100644--- a/zilencer/management/commands/populate_db.py+++ b/zilencer/management/commands/populate_db.py@@ -314,6 +314,7 @@ class Command(BaseCommand):invite_required=False,plan_type=Realm.PLAN_TYPE_SELF_HOSTED,org_type=Realm.ORG_TYPES["business"]["id"],+ enable_spectator_access=True,)RealmDomain.objects.create(realm=zulip_realm, domain="zulip.com")assert zulip_realm.notifications_stream is not None