Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
models: Add is_web_public property to Realm model.
Aman Agrawal354491d03723
diff --git a/zerver/models.py b/zerver/models.pyindex 81fe54587e1..c368f7e230b 100644--- a/zerver/models.py+++ b/zerver/models.py@@ -852,6 +852,19 @@ class Realm(models.Model):def presence_disabled(self) -> bool:return self.is_zephyr_mirror_realm+ def has_web_public_streams(self) -> bool:+ """+ If any of the streams in the realm is web+ public, then the realm is web public.+ """+ if self.plan_type == Realm.LIMITED:+ # We don't enable web public streams feature+ # for realms on LIMITED plan to avoid spamming+ # behaviour.+ return False++ return Stream.objects.filter(realm=self, is_web_public=True).exists()+post_save.connect(flush_realm, sender=Realm)diff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.pyindex 9f0c26b1f6e..25ded55e883 100644--- a/zerver/tests/test_realm.py+++ b/zerver/tests/test_realm.py@@ -735,6 +735,30 @@ class RealmTest(ZulipTestCase):self.assertEqual(realm.signup_notifications_stream.name, "core team")self.assertEqual(realm.signup_notifications_stream.realm, realm)+ def test_realm_is_web_public(self) -> None:+ realm = get_realm("zulip")+ # By default "Rome" is web_public in zulip realm+ rome = Stream.objects.get(name="Rome")+ self.assertEqual(rome.is_web_public, True)+ self.assertEqual(realm.has_web_public_streams(), True)++ # Convert Rome to a public stream+ rome.is_web_public = False+ rome.save()+ self.assertEqual(Stream.objects.filter(realm=realm, is_web_public=True).count(), 0)+ self.assertEqual(realm.has_web_public_streams(), False)++ # Restore state+ rome.is_web_public = True+ rome.save()+ self.assertEqual(Stream.objects.filter(realm=realm, is_web_public=True).count(), 1)+ self.assertEqual(realm.has_web_public_streams(), True)++ realm.plan_type = Realm.LIMITED+ realm.save()+ self.assertEqual(Stream.objects.filter(realm=realm, is_web_public=True).count(), 1)+ self.assertEqual(realm.has_web_public_streams(), False)+class RealmAPITest(ZulipTestCase):def setUp(self) -> None: