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.
This commit is contained in:
Sahil Batra 2021-11-23 16:53:48 +05:30 committed by Tim Abbott
parent ad99b4fac9
commit 56a8443f05
2 changed files with 14 additions and 2 deletions

View File

@ -896,6 +896,9 @@ class Realm(models.Model):
# target every open Internet service that can host files. # target every open Internet service that can host files.
return False return False
if not self.enable_spectator_access:
return False
return True return True
def has_web_public_streams(self) -> bool: def has_web_public_streams(self) -> bool:
@ -909,10 +912,11 @@ class Realm(models.Model):
def allow_web_public_streams_access(self) -> bool: def allow_web_public_streams_access(self) -> bool:
""" """
If any of the streams in the realm is web 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. 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) post_save.connect(flush_realm, sender=Realm)

View File

@ -847,6 +847,14 @@ class RealmTest(ZulipTestCase):
self.assertEqual(realm.has_web_public_streams(), False) self.assertEqual(realm.has_web_public_streams(), False)
self.assertEqual(realm.web_public_streams_enabled(), 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 # Convert Rome to a public stream
rome.is_web_public = False rome.is_web_public = False
rome.save() rome.save()