From 56a8443f05789ce08affd0f89f970f201217a791 Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Tue, 23 Nov 2021 16:53:48 +0530 Subject: [PATCH] models: Check enable_spectator_access value in web_public_streams_enabled. This commit changes web_public_streams_enabled to return False if realm.enable_spectator_access is False. This is added so that creating web-public streams is not allowed if enable_spectator_access is False. --- zerver/models.py | 8 ++++++-- zerver/tests/test_realm.py | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/zerver/models.py b/zerver/models.py index a9071f5014..99ab675440 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -896,6 +896,9 @@ class Realm(models.Model): # target every open Internet service that can host files. return False + if not self.enable_spectator_access: + return False + return True def has_web_public_streams(self) -> bool: @@ -909,10 +912,11 @@ class Realm(models.Model): def allow_web_public_streams_access(self) -> bool: """ If any of the streams in the realm is web - public and `enable_spectator_access` is True, + public and `enable_spectator_access` and + settings.WEB_PUBLIC_STREAMS_ENABLED is True, then the Realm is web public. """ - return self.enable_spectator_access and self.has_web_public_streams() + return self.has_web_public_streams() post_save.connect(flush_realm, sender=Realm) diff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.py index a7dcf182e5..8680ba6202 100644 --- a/zerver/tests/test_realm.py +++ b/zerver/tests/test_realm.py @@ -847,6 +847,14 @@ class RealmTest(ZulipTestCase): self.assertEqual(realm.has_web_public_streams(), False) self.assertEqual(realm.web_public_streams_enabled(), False) + realm.enable_spectator_access = False + realm.save() + self.assertEqual(realm.has_web_public_streams(), False) + self.assertEqual(realm.web_public_streams_enabled(), False) + + realm.enable_spectator_access = True + realm.save() + # Convert Rome to a public stream rome.is_web_public = False rome.save()