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.

subscriptions: Refactor template rendering of `stream_privacy_policy`.

Ryan Rehmanb4888c1251d9
diff --git a/frontend_tests/node_tests/stream_data.js b/frontend_tests/node_tests/stream_data.js
index a3ac443bf88..53ccf0e29d1 100644
--- a/frontend_tests/node_tests/stream_data.js
+++ b/frontend_tests/node_tests/stream_data.js
@@ -47,6 +47,8 @@ run_test("basics", () => {
name: "Denmark",
stream_id: 1,
is_muted: true,
+ invite_only: true,
+ history_public_to_subscribers: true,
};
const social = {
subscribed: true,
@@ -55,6 +57,7 @@ run_test("basics", () => {
stream_id: 2,
is_muted: false,
invite_only: true,
+ history_public_to_subscribers: false,
stream_post_policy: stream_data.stream_post_policy_values.admins.code,
};
const test = {
@@ -84,6 +87,10 @@ run_test("basics", () => {
assert(!stream_data.is_subscribed("Denmark"));
assert(!stream_data.is_subscribed("Rome"));
+ assert(stream_data.get_stream_privacy_policy(test.stream_id), "public");
+ assert(stream_data.get_stream_privacy_policy(social.stream_id), "invite-only");
+ assert(stream_data.get_stream_privacy_policy(denmark.stream_id), "invite-only-public-history");
+
assert(stream_data.get_invite_only("social"));
assert(!stream_data.get_invite_only("unknown"));
diff --git a/static/js/stream_data.js b/static/js/stream_data.js
index 00d80af889a..117822269c2 100644
--- a/static/js/stream_data.js
+++ b/static/js/stream_data.js
@@ -92,6 +92,30 @@ let filter_out_inactives = false;
const stream_ids_by_name = new FoldDict();
const default_stream_ids = new Set();
+exports.stream_privacy_policy_values = {
+ public: {
+ code: "public",
+ name: i18n.t("Public"),
+ description: i18n.t(
+ "Anyone can join; anyone can view complete message history without joining",
+ ),
+ },
+ private_with_public_history: {
+ code: "invite-only-public-history",
+ name: i18n.t("Private, shared history"),
+ description: i18n.t(
+ "Must be invited by a member; new members can view complete message history; hidden from non-administrator users",
+ ),
+ },
+ private: {
+ code: "invite-only",
+ name: i18n.t("Private, protected history"),
+ description: i18n.t(
+ "Must be invited by a member; new members can only see messages sent after they join; hidden from non-administrator users",
+ ),
+ },
+};
+
exports.stream_post_policy_values = {
everyone: {
code: 1,
@@ -569,6 +593,18 @@ exports.id_is_subscribed = function (stream_id) {
return sub !== undefined && sub.subscribed;
};
+exports.get_stream_privacy_policy = function (stream_id) {
+ const sub = exports.get_sub_by_id(stream_id);
+
+ if (!sub.invite_only) {
+ return exports.stream_privacy_policy_values.public.code;
+ }
+ if (sub.invite_only && !sub.history_public_to_subscribers) {
+ return exports.stream_privacy_policy_values.private.code;
+ }
+ return exports.stream_privacy_policy_values.private_with_public_history.code;
+};
+
exports.get_invite_only = function (stream_name) {
const sub = exports.get_sub(stream_name);
if (sub === undefined) {
diff --git a/static/js/stream_edit.js b/static/js/stream_edit.js
index 9d7df80faff..11082621858 100644
--- a/static/js/stream_edit.js
+++ b/static/js/stream_edit.js
@@ -474,14 +474,14 @@ function change_stream_privacy(e) {
let invite_only;
let history_public_to_subscribers;
- if (privacy_setting === "invite-only") {
+ if (privacy_setting === stream_data.stream_privacy_policy_values.public.code) {
+ invite_only = false;
+ history_public_to_subscribers = true;
+ } else if (privacy_setting === stream_data.stream_privacy_policy_values.private.code) {
invite_only = true;
history_public_to_subscribers = false;
- } else if (privacy_setting === "invite-only-public-history") {
- invite_only = true;
- history_public_to_subscribers = true;
} else {
- invite_only = false;
+ invite_only = true;
history_public_to_subscribers = true;
}
@@ -621,15 +621,14 @@ exports.initialize = function () {
$("#subscriptions_table").on("click", ".change-stream-privacy", (e) => {
const stream_id = get_stream_id(e.target);
const stream = stream_data.get_sub_by_id(stream_id);
+
const template_data = {
stream_id,
stream_name: stream.name,
+ stream_privacy_policy_values: stream_data.stream_privacy_policy_values,
+ stream_privacy_policy: stream_data.get_stream_privacy_policy(stream_id),
stream_post_policy_values: stream_data.stream_post_policy_values,
stream_post_policy: stream.stream_post_policy,
- is_public: !stream.invite_only,
- is_private: stream.invite_only && !stream.history_public_to_subscribers,
- is_private_with_public_history:
- stream.invite_only && stream.history_public_to_subscribers,
is_owner: page_params.is_owner,
zulip_plan_is_not_limited: page_params.zulip_plan_is_not_limited,
disable_message_retention_setting:
diff --git a/static/js/subs.js b/static/js/subs.js
index f97cae2a34a..5cabe1a0fd6 100644
--- a/static/js/subs.js
+++ b/static/js/subs.js
@@ -611,8 +611,8 @@ exports.setup_page = function (callback) {
max_name_length: page_params.stream_name_max_length,
max_description_length: page_params.stream_description_max_length,
is_owner: page_params.is_owner,
+ stream_privacy_policy_values: stream_data.stream_privacy_policy_values,
stream_post_policy_values: stream_data.stream_post_policy_values,
- stream_post_policy: stream_data.stream_post_policy_values.everyone.code,
zulip_plan_is_not_limited: page_params.zulip_plan_is_not_limited,
realm_message_retention_setting:
stream_edit.get_display_text_for_realm_message_retention_setting,
diff --git a/static/templates/stream_creation_form.hbs b/static/templates/stream_creation_form.hbs
index 87af1573416..1e60c037723 100644
--- a/static/templates/stream_creation_form.hbs
+++ b/static/templates/stream_creation_form.hbs
@@ -27,7 +27,10 @@
{{t 'These settings are explained in detail in the <a target="_blank" rel="noopener noreferrer" href="/help/stream-permissions">help center</a>.'}}
</div>
- {{> stream_types is_public=true stream_post_policy=stream_post_policy_values.everyone.code is_stream_edit=false}}
+ {{> stream_types
+ stream_privacy_policy=stream_privacy_policy_values.everyone.code
+ stream_post_policy=stream_post_policy_values.everyone.code
+ is_stream_edit=false }}
<div id="announce-new-stream">
<label class="checkbox">
diff --git a/static/templates/stream_types.hbs b/static/templates/stream_types.hbs
index bde4669fbae..27acc60cbd7 100644
--- a/static/templates/stream_types.hbs
+++ b/static/templates/stream_types.hbs
@@ -2,24 +2,14 @@
<h4>{{t 'Who can access the stream?'}}
{{> help_link_widget link="/help/stream-permissions" }}
</h4>
+ {{#each stream_privacy_policy_values}}
<li>
<label class="radio">
- <input type="radio" name="privacy" value="public" {{#if is_public}}checked{{/if}} />
- {{t '<b>Public:</b> anyone can join; anyone can view complete message history without joining' }}
- </label>
- </li>
- <li>
- <label class="radio">
- <input type="radio" name="privacy" value="invite-only-public-history" {{#if is_private_with_public_history}}checked{{/if}} />
- {{t '<b>Private, shared history:</b> must be invited by a member; new members can view complete message history; hidden from non-administrator users' }}
- </label>
- </li>
- <li>
- <label class="radio">
- <input type="radio" name="privacy" value="invite-only" {{#if is_private}}checked{{/if}} />
- {{t '<b>Private, protected history:</b> must be invited by a member; new members can only see messages sent after they join; hidden from non-administrator users' }}
+ <input type="radio" name="privacy" value="{{ this.code }}" {{#if (eq this.code ../stream_privacy_policy) }}checked{{/if}} />
+ <b>{{ this.name }}:</b> {{ this.description }}
</label>
</li>
+ {{/each}}
<h4>{{t 'Who can post to the stream?'}}
{{> help_link_widget link="/help/stream-sending-policy" }}
</h4>