realm: Allow setting notification settings to unsubscribed private streams.

We previously did not allow setting signup_notifications_stream and
notifications_stream settings to private streams that admin is not
subscribed to, even when admins have access to metadata of all the
streams in the realm and can see them in the dropdown options as well.

This commit fixes it to allow admins to set these settings to private
streams that the admin is not subscribed to.
This commit is contained in:
Sahil Batra 2023-11-22 22:37:57 +05:30 committed by Tim Abbott
parent b392655cdb
commit b1d5cd6bf6
2 changed files with 23 additions and 2 deletions

View File

@ -494,6 +494,15 @@ class RealmTest(ZulipTestCase):
assert realm.notifications_stream is not None
self.assertEqual(realm.notifications_stream.id, new_notif_stream_id)
# Test that admin can set the setting to an unsubscribed private stream as well.
new_notif_stream_id = self.make_stream("private_stream", invite_only=True).id
req = dict(notifications_stream_id=orjson.dumps(new_notif_stream_id).decode())
result = self.client_patch("/json/realm", req)
self.assert_json_success(result)
realm = get_realm("zulip")
assert realm.notifications_stream is not None
self.assertEqual(realm.notifications_stream.id, new_notif_stream_id)
invalid_notif_stream_id = 1234
req = dict(notifications_stream_id=orjson.dumps(invalid_notif_stream_id).decode())
result = self.client_patch("/json/realm", req)
@ -563,6 +572,18 @@ class RealmTest(ZulipTestCase):
assert realm.signup_notifications_stream is not None
self.assertEqual(realm.signup_notifications_stream.id, new_signup_notifications_stream_id)
# Test that admin can set the setting to an unsubscribed private stream as well.
new_signup_notifications_stream_id = self.make_stream("private_stream", invite_only=True).id
req = dict(
signup_notifications_stream_id=orjson.dumps(new_signup_notifications_stream_id).decode()
)
result = self.client_patch("/json/realm", req)
self.assert_json_success(result)
realm = get_realm("zulip")
assert realm.signup_notifications_stream is not None
self.assertEqual(realm.signup_notifications_stream.id, new_signup_notifications_stream_id)
invalid_signup_notifications_stream_id = 1234
req = dict(
signup_notifications_stream_id=orjson.dumps(

View File

@ -383,7 +383,7 @@ def update_realm(
new_notifications_stream = None
if notifications_stream_id >= 0:
(new_notifications_stream, sub) = access_stream_by_id(
user_profile, notifications_stream_id
user_profile, notifications_stream_id, allow_realm_admin=True
)
do_set_realm_notifications_stream(
realm, new_notifications_stream, notifications_stream_id, acting_user=user_profile
@ -397,7 +397,7 @@ def update_realm(
new_signup_notifications_stream = None
if signup_notifications_stream_id >= 0:
(new_signup_notifications_stream, sub) = access_stream_by_id(
user_profile, signup_notifications_stream_id
user_profile, signup_notifications_stream_id, allow_realm_admin=True
)
do_set_realm_signup_notifications_stream(
realm,