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.

stream_data: Handle inaccessible stream in topic policy checks.

Sahil Batrad17815464153
diff --git a/web/src/stream_data.ts b/web/src/stream_data.ts
index c80175d4a69..e939f5db67c 100644
--- a/web/src/stream_data.ts
+++ b/web/src/stream_data.ts
@@ -1206,7 +1206,9 @@ export function can_use_empty_topic(stream_id: number | undefined): boolean {
return false;
}
const sub = sub_store.get(stream_id);
- assert(sub !== undefined);
+ if (!sub) {
+ return false;
+ }
let topics_policy = sub.topics_policy;
if (sub.topics_policy === settings_config.get_stream_topics_policy_values().inherit.code) {
@@ -1224,7 +1226,9 @@ export function is_empty_topic_only_channel(stream_id: number | undefined): bool
return false;
}
const sub = sub_store.get(stream_id);
- assert(sub !== undefined);
+ if (!sub) {
+ return false;
+ }
let topics_policy = sub.topics_policy;
if (sub.topics_policy === settings_config.get_stream_topics_policy_values().inherit.code) {
diff --git a/web/tests/stream_data.test.cjs b/web/tests/stream_data.test.cjs
index b647fb2041b..31b5f2d3a57 100644
--- a/web/tests/stream_data.test.cjs
+++ b/web/tests/stream_data.test.cjs
@@ -2573,6 +2573,7 @@ run_test("is_empty_topic_only_channel", ({override}) => {
};
override(realm, "realm_topics_policy", "allow_empty_topic");
assert.equal(stream_data.is_empty_topic_only_channel(undefined), false);
+ assert.equal(stream_data.is_empty_topic_only_channel(99), false);
stream_data.add_sub_for_tests(scotland);
override(current_user, "user_id", me.user_id);
@@ -2581,3 +2582,32 @@ run_test("is_empty_topic_only_channel", ({override}) => {
assert.equal(stream_data.is_empty_topic_only_channel(social.stream_id), true);
assert.equal(stream_data.is_empty_topic_only_channel(scotland.stream_id), false);
});
+
+run_test("can_use_empty_topic", ({override}) => {
+ const social = {
+ subscribed: true,
+ color: "red",
+ name: "social",
+ stream_id: 2,
+ topics_policy: "empty_topic_only",
+ };
+ stream_data.add_sub_for_tests(social);
+ const scotland = {
+ subscribed: true,
+ color: "red",
+ name: "scotland",
+ stream_id: 3,
+ topics_policy: "inherit",
+ };
+ override(realm, "realm_topics_policy", "allow_empty_topic");
+ assert.equal(stream_data.can_use_empty_topic(undefined), false);
+ assert.equal(stream_data.can_use_empty_topic(99), false);
+
+ assert.equal(stream_data.can_use_empty_topic(social.stream_id), true);
+
+ stream_data.add_sub_for_tests(scotland);
+
+ assert.equal(stream_data.can_use_empty_topic(scotland.stream_id), true);
+ override(realm, "realm_topics_policy", "disable_empty_topic");
+ assert.equal(stream_data.can_use_empty_topic(scotland.stream_id), false);
+});