Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
stream_data: Move stream_*_policy_values to settings_config.
Anders Kaseorgd17c0dabc865
diff --git a/web/src/settings_config.ts b/web/src/settings_config.tsindex 926b5955f6c..7263a518a72 100644--- a/web/src/settings_config.ts+++ b/web/src/settings_config.ts@@ -4,6 +4,7 @@ import {$t, $t_html} from "./i18n";import {page_params} from "./page_params";import type {RealmDefaultSettings} from "./realm_user_settings_defaults";import type {StreamSpecificNotificationSettings} from "./sub_store";+import {StreamPostPolicy} from "./sub_store";import type {FollowedTopicNotificationSettings,PmNotificationSettings,@@ -949,3 +950,61 @@ export const automatically_follow_or_unmute_topics_policy_values = {description: $t({defaultMessage: "Never"}),},};++export const stream_privacy_policy_values = {+ web_public: {+ code: "web-public",+ name: $t({defaultMessage: "Web-public"}),+ description: $t({+ defaultMessage:+ "Organization members can join (guests must be invited by a subscriber); anyone on the Internet can view complete message history without creating an account",+ }),+ },+ public: {+ code: "public",+ name: $t({defaultMessage: "Public"}),+ description: $t({+ defaultMessage:+ "Organization members can join (guests must be invited by a subscriber); organization members can view complete message history without joining",+ }),+ },+ private_with_public_history: {+ code: "invite-only-public-history",+ name: $t({defaultMessage: "Private, shared history"}),+ description: $t({+ defaultMessage:+ "Must be invited by a subscriber; new subscribers can view complete message history; hidden from non-administrator users",+ }),+ },+ private: {+ code: "invite-only",+ name: $t({defaultMessage: "Private, protected history"}),+ description: $t({+ defaultMessage:+ "Must be invited by a subscriber; new subscribers can only see messages sent after they join; hidden from non-administrator users",+ }),+ },+};++export const stream_post_policy_values = {+ // These strings should match the strings in the+ // Stream.POST_POLICIES object in zerver/models.py.+ everyone: {+ code: StreamPostPolicy.EVERYONE,+ description: $t({defaultMessage: "Everyone"}),+ },+ non_new_members: {+ code: StreamPostPolicy.RESTRICT_NEW_MEMBERS,+ description: $t({defaultMessage: "Admins, moderators and full members"}),+ },+ moderators: {+ code: StreamPostPolicy.MODERATORS,+ description: $t({+ defaultMessage: "Admins and moderators",+ }),+ },+ admins: {+ code: StreamPostPolicy.ADMINS,+ description: $t({defaultMessage: "Admins only"}),+ },+} as const;diff --git a/web/src/stream_data.ts b/web/src/stream_data.tsindex 44b4e9849e4..d49f68a5033 100644--- a/web/src/stream_data.ts+++ b/web/src/stream_data.ts@@ -1,18 +1,17 @@import * as blueslip from "./blueslip";import * as color_data from "./color_data";import {FoldDict} from "./fold_dict";-import {$t} from "./i18n";import {page_params} from "./page_params";import * as peer_data from "./peer_data";import * as people from "./people";import * as settings_config from "./settings_config";import * as settings_data from "./settings_data";import * as sub_store from "./sub_store";-import {StreamPostPolicy} from "./sub_store";import type {ApiStreamSubscription,NeverSubscribedStream,Stream,+ StreamPostPolicy,StreamSpecificNotificationSettings,StreamSubscription,} from "./sub_store";@@ -129,64 +128,6 @@ const stream_ids_by_name = new FoldDict<number>();const stream_ids_by_old_names = new FoldDict<number>();const default_stream_ids = new Set<number>();-export const stream_privacy_policy_values = {- web_public: {- code: "web-public",- name: $t({defaultMessage: "Web-public"}),- description: $t({- defaultMessage:- "Organization members can join (guests must be invited by a subscriber); anyone on the Internet can view complete message history without creating an account",- }),- },- public: {- code: "public",- name: $t({defaultMessage: "Public"}),- description: $t({- defaultMessage:- "Organization members can join (guests must be invited by a subscriber); organization members can view complete message history without joining",- }),- },- private_with_public_history: {- code: "invite-only-public-history",- name: $t({defaultMessage: "Private, shared history"}),- description: $t({- defaultMessage:- "Must be invited by a subscriber; new subscribers can view complete message history; hidden from non-administrator users",- }),- },- private: {- code: "invite-only",- name: $t({defaultMessage: "Private, protected history"}),- description: $t({- defaultMessage:- "Must be invited by a subscriber; new subscribers can only see messages sent after they join; hidden from non-administrator users",- }),- },-};--export const stream_post_policy_values = {- // These strings should match the strings in the- // Stream.POST_POLICIES object in zerver/models.py.- everyone: {- code: StreamPostPolicy.EVERYONE,- description: $t({defaultMessage: "Everyone"}),- },- non_new_members: {- code: StreamPostPolicy.RESTRICT_NEW_MEMBERS,- description: $t({defaultMessage: "Admins, moderators and full members"}),- },- moderators: {- code: StreamPostPolicy.MODERATORS,- description: $t({- defaultMessage: "Admins and moderators",- }),- },- admins: {- code: StreamPostPolicy.ADMINS,- description: $t({defaultMessage: "Admins only"}),- },-} as const;-export function clear_subscriptions(): void {// This function is only used once at page load, and then// it should only be used in tests.@@ -630,7 +571,7 @@ export function can_post_messages_in_stream(stream: StreamSubscription): booleanreturn true;}- if (stream.stream_post_policy === stream_post_policy_values.admins.code) {+ if (stream.stream_post_policy === settings_config.stream_post_policy_values.admins.code) {return false;}@@ -638,13 +579,13 @@ export function can_post_messages_in_stream(stream: StreamSubscription): booleanreturn true;}- if (stream.stream_post_policy === stream_post_policy_values.moderators.code) {+ if (stream.stream_post_policy === settings_config.stream_post_policy_values.moderators.code) {return false;}if (page_params.is_guest &&- stream.stream_post_policy !== stream_post_policy_values.everyone.code+ stream.stream_post_policy !== settings_config.stream_post_policy_values.everyone.code) {return false;}@@ -654,7 +595,8 @@ export function can_post_messages_in_stream(stream: StreamSubscription): booleanconst person_date_joined = new Date(person.date_joined).getTime();const days = (current_datetime - person_date_joined) / 1000 / 86400;if (- stream.stream_post_policy === stream_post_policy_values.non_new_members.code &&+ stream.stream_post_policy ===+ settings_config.stream_post_policy_values.non_new_members.code &&days < page_params.realm_waiting_period_threshold) {return false;@@ -676,15 +618,15 @@ export function get_stream_privacy_policy(stream_id: number): string {const sub = sub_store.get(stream_id)!;if (sub.is_web_public) {- return stream_privacy_policy_values.web_public.code;+ return settings_config.stream_privacy_policy_values.web_public.code;}if (!sub.invite_only) {- return stream_privacy_policy_values.public.code;+ return settings_config.stream_privacy_policy_values.public.code;}if (sub.invite_only && !sub.history_public_to_subscribers) {- return stream_privacy_policy_values.private.code;+ return settings_config.stream_privacy_policy_values.private.code;}- return stream_privacy_policy_values.private_with_public_history.code;+ return settings_config.stream_privacy_policy_values.private_with_public_history.code;}export function is_web_public(stream_id: number): boolean {diff --git a/web/src/stream_edit.js b/web/src/stream_edit.jsindex 24ab86e8b97..cdc6335bcd7 100644--- a/web/src/stream_edit.js+++ b/web/src/stream_edit.js@@ -244,8 +244,8 @@ export function show_settings_for(node) {sub,notification_settings,other_settings,- stream_post_policy_values: stream_data.stream_post_policy_values,- stream_privacy_policy_values: stream_data.stream_privacy_policy_values,+ stream_post_policy_values: settings_config.stream_post_policy_values,+ stream_privacy_policy_values: settings_config.stream_privacy_policy_values,stream_privacy_policy: stream_data.get_stream_privacy_policy(stream_id),check_default_stream: stream_data.is_default_stream_id(stream_id),zulip_plan_is_not_limited: page_params.zulip_plan_is_not_limited,@@ -341,21 +341,21 @@ export function stream_setting_changed(e, from_notification_settings) {export function get_request_data_for_stream_privacy(selected_val) {switch (selected_val) {- case stream_data.stream_privacy_policy_values.public.code: {+ case settings_config.stream_privacy_policy_values.public.code: {return {is_private: false,history_public_to_subscribers: true,is_web_public: false,};}- case stream_data.stream_privacy_policy_values.private.code: {+ case settings_config.stream_privacy_policy_values.private.code: {return {is_private: true,history_public_to_subscribers: false,is_web_public: false,};}- case stream_data.stream_privacy_policy_values.web_public.code: {+ case settings_config.stream_privacy_policy_values.web_public.code: {return {is_private: false,history_public_to_subscribers: true,diff --git a/web/src/stream_settings_ui.js b/web/src/stream_settings_ui.jsindex d93cd312a7f..efb1d0ce228 100644--- a/web/src/stream_settings_ui.js+++ b/web/src/stream_settings_ui.js@@ -695,7 +695,7 @@ export function setup_page(callback) {// TODO: Ideally we'd indicate in some way what stream types// the user can create, by showing other options as disabled.- const stream_privacy_policy = stream_data.stream_privacy_policy_values.public.code;+ const stream_privacy_policy = settings_config.stream_privacy_policy_values.public.code;const notifications_stream = stream_data.get_notifications_stream();const notifications_stream_sub = stream_data.get_sub_by_name(notifications_stream);@@ -710,9 +710,9 @@ export function setup_page(callback) {max_stream_name_length: page_params.max_stream_name_length,max_stream_description_length: page_params.max_stream_description_length,is_owner: page_params.is_owner,- stream_privacy_policy_values: stream_data.stream_privacy_policy_values,+ stream_privacy_policy_values: settings_config.stream_privacy_policy_values,stream_privacy_policy,- stream_post_policy_values: stream_data.stream_post_policy_values,+ stream_post_policy_values: settings_config.stream_post_policy_values,check_default_stream: false,zulip_plan_is_not_limited: page_params.zulip_plan_is_not_limited,org_level_message_retention_setting:@@ -1106,7 +1106,9 @@ export function sub_or_unsub(sub, $stream_row) {export function update_web_public_stream_privacy_option_state($container) {const $web_public_stream_elem = $container.find(- `input[value='${CSS.escape(stream_data.stream_privacy_policy_values.web_public.code)}']`,+ `input[value='${CSS.escape(+ settings_config.stream_privacy_policy_values.web_public.code,+ )}']`,);const for_stream_edit_panel = $container.attr("id") === "stream_permission_settings";@@ -1156,7 +1158,7 @@ export function update_web_public_stream_privacy_option_state($container) {export function update_public_stream_privacy_option_state($container) {const $public_stream_elem = $container.find(- `input[value='${CSS.escape(stream_data.stream_privacy_policy_values.public.code)}']`,+ `input[value='${CSS.escape(settings_config.stream_privacy_policy_values.public.code)}']`,);$public_stream_elem.prop("disabled", !settings_data.user_can_create_public_streams());}@@ -1164,11 +1166,11 @@ export function update_public_stream_privacy_option_state($container) {export function update_private_stream_privacy_option_state($container, is_default_stream = false) {// Disable both "Private, shared history" and "Private, protected history" options.const $private_stream_elem = $container.find(- `input[value='${CSS.escape(stream_data.stream_privacy_policy_values.private.code)}']`,+ `input[value='${CSS.escape(settings_config.stream_privacy_policy_values.private.code)}']`,);const $private_with_public_history_elem = $container.find(`input[value='${CSS.escape(- stream_data.stream_privacy_policy_values.private_with_public_history.code,+ settings_config.stream_privacy_policy_values.private_with_public_history.code,)}']`,);diff --git a/web/tests/compose_validate.test.js b/web/tests/compose_validate.test.jsindex 06161c66d8f..debb8259e52 100644--- a/web/tests/compose_validate.test.js+++ b/web/tests/compose_validate.test.js@@ -447,7 +447,7 @@ test_ui(stream_id: 102,name: "stream102",subscribed: true,- stream_post_policy: stream_data.stream_post_policy_values.admins.code,+ stream_post_policy: settings_config.stream_post_policy_values.admins.code,};stream_data.add_sub(sub_stream_102);@@ -496,7 +496,7 @@ test_ui(stream_id: 104,name: "stream104",subscribed: true,- stream_post_policy: stream_data.stream_post_policy_values.moderators.code,+ stream_post_policy: settings_config.stream_post_policy_values.moderators.code,};stream_data.add_sub(sub);@@ -535,7 +535,7 @@ test_ui(stream_id: 103,name: "stream103",subscribed: true,- stream_post_policy: stream_data.stream_post_policy_values.non_new_members.code,+ stream_post_policy: settings_config.stream_post_policy_values.non_new_members.code,};stream_data.add_sub(sub);diff --git a/web/tests/stream_data.test.js b/web/tests/stream_data.test.jsindex 3d931918bb8..f2ea99186bf 100644--- a/web/tests/stream_data.test.js+++ b/web/tests/stream_data.test.js@@ -14,6 +14,7 @@ page_params.development_environment = true;const color_data = zrequire("color_data");const peer_data = zrequire("peer_data");const people = zrequire("people");+const settings_config = zrequire("settings_config");const sub_store = zrequire("sub_store");const stream_data = zrequire("stream_data");const stream_settings_data = zrequire("stream_settings_data");@@ -80,7 +81,7 @@ test("basics", () => {is_muted: false,invite_only: true,history_public_to_subscribers: false,- stream_post_policy: stream_data.stream_post_policy_values.admins.code,+ stream_post_policy: settings_config.stream_post_policy_values.admins.code,};const test = {subscribed: true,@@ -218,7 +219,7 @@ test("get_streams_for_user", () => {is_muted: false,invite_only: false,history_public_to_subscribers: false,- stream_post_policy: stream_data.stream_post_policy_values.admins.code,+ stream_post_policy: settings_config.stream_post_policy_values.admins.code,};const test = {color: "yellow",@@ -234,7 +235,7 @@ test("get_streams_for_user", () => {is_muted: false,invite_only: false,history_public_to_subscribers: false,- stream_post_policy: stream_data.stream_post_policy_values.admins.code,+ stream_post_policy: settings_config.stream_post_policy_values.admins.code,};const subs = [denmark, social, test, world];for (const sub of subs) {@@ -374,7 +375,7 @@ test("stream_settings", () => {subscribed: true,invite_only: true,history_public_to_subscribers: true,- stream_post_policy: stream_data.stream_post_policy_values.admins.code,+ stream_post_policy: settings_config.stream_post_policy_values.admins.code,message_retention_days: 10,can_remove_subscribers_group: admins_group.id,};@@ -397,7 +398,7 @@ test("stream_settings", () => {assert.equal(sub_rows[0].history_public_to_subscribers, true);assert.equal(- sub_rows[0].stream_post_policy === stream_data.stream_post_policy_values.admins.code,+ sub_rows[0].stream_post_policy === settings_config.stream_post_policy_values.admins.code,true,);assert.equal(sub_rows[0].message_retention_days, 10);@@ -412,7 +413,7 @@ test("stream_settings", () => {stream_data.update_can_remove_subscribers_group_id(sub, moderators_group.id);assert.equal(sub.invite_only, false);assert.equal(sub.history_public_to_subscribers, false);- assert.equal(sub.stream_post_policy, stream_data.stream_post_policy_values.everyone.code);+ assert.equal(sub.stream_post_policy, settings_config.stream_post_policy_values.everyone.code);assert.equal(sub.message_retention_days, -1);assert.equal(sub.can_remove_subscribers_group, moderators_group.id);@@ -696,7 +697,7 @@ test("muted_stream_ids", () => {is_muted: false,invite_only: true,history_public_to_subscribers: false,- stream_post_policy: stream_data.stream_post_policy_values.admins.code,+ stream_post_policy: settings_config.stream_post_policy_values.admins.code,};const test = {subscribed: true,@@ -909,7 +910,7 @@ test("can_post_messages_in_stream", () => {is_muted: false,invite_only: true,history_public_to_subscribers: false,- stream_post_policy: stream_data.stream_post_policy_values.admins.code,+ stream_post_policy: settings_config.stream_post_policy_values.admins.code,};page_params.is_admin = false;assert.equal(stream_data.can_post_messages_in_stream(social), false);@@ -917,7 +918,7 @@ test("can_post_messages_in_stream", () => {page_params.is_admin = true;assert.equal(stream_data.can_post_messages_in_stream(social), true);- social.stream_post_policy = stream_data.stream_post_policy_values.moderators.code;+ social.stream_post_policy = settings_config.stream_post_policy_values.moderators.code;page_params.is_moderator = false;page_params.is_admin = false;@@ -926,7 +927,7 @@ test("can_post_messages_in_stream", () => {page_params.is_moderator = true;assert.equal(stream_data.can_post_messages_in_stream(social), true);- social.stream_post_policy = stream_data.stream_post_policy_values.non_new_members.code;+ social.stream_post_policy = settings_config.stream_post_policy_values.non_new_members.code;page_params.is_moderator = false;me.date_joined = new Date(Date.now());page_params.realm_waiting_period_threshold = 10;@@ -938,7 +939,7 @@ test("can_post_messages_in_stream", () => {page_params.is_guest = true;assert.equal(stream_data.can_post_messages_in_stream(social), false);- social.stream_post_policy = stream_data.stream_post_policy_values.everyone.code;+ social.stream_post_policy = settings_config.stream_post_policy_values.everyone.code;assert.equal(stream_data.can_post_messages_in_stream(social), true);page_params.is_spectator = true;@@ -1045,7 +1046,7 @@ test("options for dropdown widget", () => {is_muted: false,invite_only: true,history_public_to_subscribers: false,- stream_post_policy: stream_data.stream_post_policy_values.admins.code,+ stream_post_policy: settings_config.stream_post_policy_values.admins.code,};const test = {subscribed: true,diff --git a/web/tests/stream_events.test.js b/web/tests/stream_events.test.jsindex 2df68901f07..ea7cbedc11a 100644--- a/web/tests/stream_events.test.js+++ b/web/tests/stream_events.test.js@@ -41,6 +41,7 @@ const {Filter} = zrequire("../src/filter");const narrow_state = zrequire("narrow_state");const peer_data = zrequire("peer_data");const people = zrequire("people");+const settings_config = zrequire("settings_config");const stream_data = zrequire("stream_data");const stream_events = zrequire("stream_events");const compose_recipient = zrequire("compose_recipient");@@ -232,12 +233,12 @@ test("update_property", ({override, override_rewire}) => {stream_events.update_property(stream_id,"stream_post_policy",- stream_data.stream_post_policy_values.admins.code,+ settings_config.stream_post_policy_values.admins.code,);assert.equal(stub.num_calls, 1);const args = stub.get_args("sub", "val");assert.equal(args.sub.stream_id, stream_id);- assert.equal(args.val, stream_data.stream_post_policy_values.admins.code);+ assert.equal(args.val, settings_config.stream_post_policy_values.admins.code);}// Test stream message_retention_days change event