Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
settings_data: Add 'user_can_subscribe_other_users' helper.
sahil8390452d8e17518
diff --git a/frontend_tests/node_tests/compose.js b/frontend_tests/node_tests/compose.jsindex b98044fa382..8ca75177b72 100644--- a/frontend_tests/node_tests/compose.js+++ b/frontend_tests/node_tests/compose.js@@ -70,6 +70,9 @@ mock_esm("../../static/js/notifications", {mock_esm("../../static/js/rendered_markdown", {update_elements: () => {},});+mock_esm("../../static/js/settings_data", {+ user_can_subscribe_other_users: () => true,+});set_global("navigator", _navigator);// Setting these up so that we can test that links to uploads within messages arediff --git a/frontend_tests/node_tests/settings_data.js b/frontend_tests/node_tests/settings_data.jsindex 1367a212a16..4770b5e0ff2 100644--- a/frontend_tests/node_tests/settings_data.js+++ b/frontend_tests/node_tests/settings_data.js@@ -136,3 +136,34 @@ run_test("user_can_invite_others_to_realm", () => {isaac.date_joined = new Date(Date.now() - 20 * 86400000);assert.equal(can_invite_others_to_realm(), true);});++run_test("user_can_subscribe_other_users", () => {+ const can_subscribe_other_users = settings_data.user_can_subscribe_other_users;++ page_params.is_admin = true;+ page_params.realm_invite_to_stream_policy =+ settings_config.common_policy_values.by_admins_only.code;+ assert.equal(can_subscribe_other_users(), true);++ page_params.is_admin = false;+ assert.equal(can_subscribe_other_users(), false);++ page_params.is_guest = true;+ page_params.realm_invite_to_stream_policy =+ settings_config.common_policy_values.by_members.code;+ assert.equal(can_subscribe_other_users(), false);++ page_params.is_guest = false;+ assert.equal(can_subscribe_other_users(), true);++ page_params.realm_invite_to_stream_policy =+ settings_config.common_policy_values.by_full_members.code;+ page_params.user_id = 30;+ people.add_active_user(isaac);+ isaac.date_joined = new Date(Date.now());+ page_params.realm_waiting_period_threshold = 10;+ assert.equal(can_subscribe_other_users(), false);++ isaac.date_joined = new Date(Date.now() - 20 * 86400000);+ assert.equal(can_subscribe_other_users(), true);+});diff --git a/static/js/compose.js b/static/js/compose.jsindex 2062d987266..abfde23816a 100644--- a/static/js/compose.js+++ b/static/js/compose.js@@ -33,6 +33,7 @@ import * as rtl from "./rtl";import * as sent_messages from "./sent_messages";import * as server_events from "./server_events";import * as settings_config from "./settings_config";+import * as settings_data from "./settings_data";import * as stream_data from "./stream_data";import * as stream_edit from "./stream_edit";import * as sub_store from "./sub_store";@@ -1088,7 +1089,7 @@ export function warn_if_mentioning_unsubscribed_user(mentioned) {user_id,stream_id: sub.stream_id,name: mentioned.full_name,- can_subscribe_other_users: page_params.can_subscribe_other_users,+ can_subscribe_other_users: settings_data.user_can_subscribe_other_users(),};const new_row = render_compose_invite_users(context);diff --git a/static/js/server_events_dispatch.js b/static/js/server_events_dispatch.jsindex 00be3c40485..0f00e384710 100644--- a/static/js/server_events_dispatch.js+++ b/static/js/server_events_dispatch.js@@ -226,11 +226,6 @@ export function dispatch_normal_event(event) {page_params.can_create_streams =page_params.is_admin ||page_params.realm_create_stream_policy === 1;- } else if (event.property === "invite_to_stream_policy") {- // TODO: Add waiting_period_threshold logic here.- page_params.can_invite_to_stream =- page_params.is_admin ||- page_params.realm_invite_to_stream_policy === 1;}if (event.property === "name" && window.electron_bridge !== undefined) {diff --git a/static/js/settings_data.js b/static/js/settings_data.jsindex 8ce4be48508..2595f090846 100644--- a/static/js/settings_data.js+++ b/static/js/settings_data.js@@ -110,3 +110,7 @@ function user_has_permission(policy_value) {export function user_can_invite_others_to_realm() {return user_has_permission(page_params.realm_invite_to_realm_policy);}++export function user_can_subscribe_other_users() {+ return user_has_permission(page_params.realm_invite_to_stream_policy);+}