Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

streams: Delete risky helper get_stream_by_id.

Tim Abbott9d852870ee25
diff --git a/zerver/lib/streams.py b/zerver/lib/streams.py
index b2bac1cbdb0..ebb1cd42468 100644
--- a/zerver/lib/streams.py
+++ b/zerver/lib/streams.py
@@ -333,7 +333,8 @@ def access_stream_common(
# First, we don't allow any access to streams in other realms.
if stream.realm_id != user_profile.realm_id:
- raise JsonableError(error)
+ # Callers should verify this on their own, so this functions as defensive code.
+ raise AssertionError("user_profile and stream realms don't match")
try:
sub = Subscription.objects.get(
@@ -372,9 +373,12 @@ def access_stream_by_id(
require_active: bool = True,
allow_realm_admin: bool = False,
) -> Tuple[Stream, Optional[Subscription]]:
- stream = get_stream_by_id(stream_id)
-
error = _("Invalid stream id")
+ try:
+ stream = get_stream_by_id_in_realm(stream_id, user_profile.realm)
+ except Stream.DoesNotExist:
+ raise JsonableError(error)
+
sub = access_stream_common(
user_profile,
stream,
@@ -402,15 +406,6 @@ def get_web_public_streams_queryset(realm: Realm) -> "QuerySet[Stream]":
)
-def get_stream_by_id(stream_id: int) -> Stream:
- error = _("Invalid stream id")
- try:
- stream = Stream.objects.get(id=stream_id)
- except Stream.DoesNotExist:
- raise JsonableError(error)
- return stream
-
-
def check_stream_name_available(realm: Realm, name: str) -> None:
check_stream_name(name)
try:
diff --git a/zerver/tests/test_message_edit.py b/zerver/tests/test_message_edit.py
index 70e00b2ea68..79b6574802e 100644
--- a/zerver/tests/test_message_edit.py
+++ b/zerver/tests/test_message_edit.py
@@ -1215,7 +1215,7 @@ class EditMessageTest(ZulipTestCase):
"topic": "new topic",
},
)
- self.assertEqual(len(queries), 49)
+ self.assertEqual(len(queries), 48)
self.assertEqual(len(cache_tries), 13)
messages = get_topic_messages(user_profile, old_stream, "test")