mirror of
https://github.com/zulip/zulip.git
synced 2025-11-11 09:27:43 +00:00
streams: Add frontend to set/update message_retention_days of a stream.
This commit adds frontend support for setting and updating message retention days of a stream from stream settings. Message retention days can be changed from stream privacy modal of the stream and can be set from stream_creation_form while creating streams. Only admins can create streams with message_retention_days value other than realm_default. This commit also contains relevant changes to docs.
This commit is contained in:
@@ -474,6 +474,7 @@ run_test('stream_settings', () => {
|
|||||||
invite_only: true,
|
invite_only: true,
|
||||||
history_public_to_subscribers: true,
|
history_public_to_subscribers: true,
|
||||||
stream_post_policy: stream_data.stream_post_policy_values.admins.code,
|
stream_post_policy: stream_data.stream_post_policy_values.admins.code,
|
||||||
|
message_retention_days: 10,
|
||||||
};
|
};
|
||||||
stream_data.clear_subscriptions();
|
stream_data.clear_subscriptions();
|
||||||
stream_data.add_sub(cinnamon);
|
stream_data.add_sub(cinnamon);
|
||||||
@@ -496,6 +497,7 @@ run_test('stream_settings', () => {
|
|||||||
assert.equal(sub_rows[0].history_public_to_subscribers, true);
|
assert.equal(sub_rows[0].history_public_to_subscribers, true);
|
||||||
assert.equal(sub_rows[0].stream_post_policy ===
|
assert.equal(sub_rows[0].stream_post_policy ===
|
||||||
stream_data.stream_post_policy_values.admins.code, true);
|
stream_data.stream_post_policy_values.admins.code, true);
|
||||||
|
assert.equal(sub_rows[0].message_retention_days, 10);
|
||||||
|
|
||||||
const sub = stream_data.get_sub('a');
|
const sub = stream_data.get_sub('a');
|
||||||
stream_data.update_stream_privacy(sub, {
|
stream_data.update_stream_privacy(sub, {
|
||||||
@@ -503,11 +505,13 @@ run_test('stream_settings', () => {
|
|||||||
history_public_to_subscribers: false,
|
history_public_to_subscribers: false,
|
||||||
});
|
});
|
||||||
stream_data.update_stream_post_policy(sub, 1);
|
stream_data.update_stream_post_policy(sub, 1);
|
||||||
|
stream_data.update_message_retention_setting(sub, -1);
|
||||||
stream_data.update_calculated_fields(sub);
|
stream_data.update_calculated_fields(sub);
|
||||||
assert.equal(sub.invite_only, false);
|
assert.equal(sub.invite_only, false);
|
||||||
assert.equal(sub.history_public_to_subscribers, false);
|
assert.equal(sub.history_public_to_subscribers, false);
|
||||||
assert.equal(sub.stream_post_policy,
|
assert.equal(sub.stream_post_policy,
|
||||||
stream_data.stream_post_policy_values.everyone.code);
|
stream_data.stream_post_policy_values.everyone.code);
|
||||||
|
assert.equal(sub.message_retention_days, -1);
|
||||||
|
|
||||||
// For guest user only retrieve subscribed streams
|
// For guest user only retrieve subscribed streams
|
||||||
sub_rows = stream_data.get_updated_unsorted_subs();
|
sub_rows = stream_data.get_updated_unsorted_subs();
|
||||||
|
|||||||
@@ -156,6 +156,17 @@ run_test('update_property', () => {
|
|||||||
assert.equal(args.val, stream_data.stream_post_policy_values.admins.code);
|
assert.equal(args.val, stream_data.stream_post_policy_values.admins.code);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Test stream message_retention_days change event
|
||||||
|
with_overrides(function (override) {
|
||||||
|
global.with_stub(function (stub) {
|
||||||
|
override('stream_data.update_message_retention_setting', stub.f);
|
||||||
|
stream_events.update_property(1, 'message_retention_days', 20);
|
||||||
|
const args = stub.get_args('sub', 'val');
|
||||||
|
assert.equal(args.sub.stream_id, 1);
|
||||||
|
assert.equal(args.val, 20);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test('marked_subscribed', () => {
|
run_test('marked_subscribed', () => {
|
||||||
|
|||||||
@@ -169,6 +169,13 @@ function create_stream() {
|
|||||||
|
|
||||||
data.stream_post_policy = JSON.stringify(stream_post_policy);
|
data.stream_post_policy = JSON.stringify(stream_post_policy);
|
||||||
|
|
||||||
|
let message_retention_selection = $('#stream_creation_form select[name=stream_message_retention_setting]').val();
|
||||||
|
if (message_retention_selection === "retain_for_period") {
|
||||||
|
message_retention_selection = parseInt($('#stream_creation_form input[name=stream-message-retention-days]').val(), 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
data.message_retention_days = JSON.stringify(message_retention_selection);
|
||||||
|
|
||||||
const announce = stream_data.realm_has_notifications_stream() &&
|
const announce = stream_data.realm_has_notifications_stream() &&
|
||||||
$('#announce-new-stream input').prop('checked');
|
$('#announce-new-stream input').prop('checked');
|
||||||
data.announce = JSON.stringify(announce);
|
data.announce = JSON.stringify(announce);
|
||||||
@@ -266,6 +273,8 @@ exports.show_new_stream_modal = function () {
|
|||||||
// Make the options default to the same each time:
|
// Make the options default to the same each time:
|
||||||
// public, "announce stream" on.
|
// public, "announce stream" on.
|
||||||
$('#make-invite-only input:radio[value=public]').prop('checked', true);
|
$('#make-invite-only input:radio[value=public]').prop('checked', true);
|
||||||
|
$("#stream_creation_form .stream-message-retention-days-input").hide();
|
||||||
|
$("#stream_creation_form select[name=stream_message_retention_setting]").val("realm_default");
|
||||||
|
|
||||||
if (stream_data.realm_has_notifications_stream()) {
|
if (stream_data.realm_has_notifications_stream()) {
|
||||||
$('#announce-new-stream').show();
|
$('#announce-new-stream').show();
|
||||||
|
|||||||
@@ -427,6 +427,10 @@ exports.update_stream_privacy = function (sub, values) {
|
|||||||
sub.history_public_to_subscribers = values.history_public_to_subscribers;
|
sub.history_public_to_subscribers = values.history_public_to_subscribers;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.update_message_retention_setting = function (sub, message_retention_days) {
|
||||||
|
sub.message_retention_days = message_retention_days;
|
||||||
|
};
|
||||||
|
|
||||||
exports.receives_notifications = function (stream_name, notification_name) {
|
exports.receives_notifications = function (stream_name, notification_name) {
|
||||||
const sub = exports.get_sub(stream_name);
|
const sub = exports.get_sub(stream_name);
|
||||||
if (sub === undefined) {
|
if (sub === undefined) {
|
||||||
|
|||||||
@@ -63,6 +63,34 @@ exports.get_users_from_subscribers = function (subscribers) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.get_display_text_for_realm_message_retention_setting = function () {
|
||||||
|
const realm_message_retention_days = page_params.realm_message_retention_days;
|
||||||
|
if (realm_message_retention_days === -1 || realm_message_retention_days === null) {
|
||||||
|
return i18n.t("(forever)");
|
||||||
|
}
|
||||||
|
return i18n.t("(__message_retention_days__ days)", {message_retention_days: realm_message_retention_days});
|
||||||
|
};
|
||||||
|
|
||||||
|
function change_stream_message_retention_days_block_display_property(value) {
|
||||||
|
if (value === "retain_for_period") {
|
||||||
|
$('.stream-message-retention-days-input').show();
|
||||||
|
} else {
|
||||||
|
$('.stream-message-retention-days-input').hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_stream_message_retention_setting_dropdown(stream) {
|
||||||
|
let value = "retain_for_period";
|
||||||
|
if (stream.message_retention_days === null) {
|
||||||
|
value = "realm_default";
|
||||||
|
} else if (stream.message_retention_days === -1) {
|
||||||
|
value = "forever";
|
||||||
|
}
|
||||||
|
|
||||||
|
$(".stream_message_retention_setting").val(value);
|
||||||
|
change_stream_message_retention_days_block_display_property(value);
|
||||||
|
}
|
||||||
|
|
||||||
function clear_edit_panel() {
|
function clear_edit_panel() {
|
||||||
$(".display-type #add_new_stream_title").hide();
|
$(".display-type #add_new_stream_title").hide();
|
||||||
$(".display-type #stream_settings_title, .right .settings").show();
|
$(".display-type #stream_settings_title, .right .settings").show();
|
||||||
@@ -380,6 +408,7 @@ function change_stream_privacy(e) {
|
|||||||
|
|
||||||
const privacy_setting = $('#stream_privacy_modal input[name=privacy]:checked').val();
|
const privacy_setting = $('#stream_privacy_modal input[name=privacy]:checked').val();
|
||||||
const stream_post_policy = parseInt($('#stream_privacy_modal input[name=stream-post-policy]:checked').val(), 10);
|
const stream_post_policy = parseInt($('#stream_privacy_modal input[name=stream-post-policy]:checked').val(), 10);
|
||||||
|
let message_retention_days = $('#stream_privacy_modal select[name=stream_message_retention_setting]').val();
|
||||||
|
|
||||||
let invite_only;
|
let invite_only;
|
||||||
let history_public_to_subscribers;
|
let history_public_to_subscribers;
|
||||||
@@ -395,6 +424,10 @@ function change_stream_privacy(e) {
|
|||||||
history_public_to_subscribers = true;
|
history_public_to_subscribers = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (message_retention_days === 'retain_for_period') {
|
||||||
|
message_retention_days = parseInt($('#stream_privacy_modal input[name=stream-message-retention-days]').val(), 10);
|
||||||
|
}
|
||||||
|
|
||||||
$(".stream_change_property_info").hide();
|
$(".stream_change_property_info").hide();
|
||||||
const data = {
|
const data = {
|
||||||
stream_name: sub.name,
|
stream_name: sub.name,
|
||||||
@@ -402,6 +435,7 @@ function change_stream_privacy(e) {
|
|||||||
is_private: JSON.stringify(invite_only),
|
is_private: JSON.stringify(invite_only),
|
||||||
stream_post_policy: JSON.stringify(stream_post_policy),
|
stream_post_policy: JSON.stringify(stream_post_policy),
|
||||||
history_public_to_subscribers: JSON.stringify(history_public_to_subscribers),
|
history_public_to_subscribers: JSON.stringify(history_public_to_subscribers),
|
||||||
|
message_retention_days: JSON.stringify(message_retention_days),
|
||||||
};
|
};
|
||||||
|
|
||||||
channel.patch({
|
channel.patch({
|
||||||
@@ -523,10 +557,17 @@ exports.initialize = function () {
|
|||||||
is_private_with_public_history: stream.invite_only &&
|
is_private_with_public_history: stream.invite_only &&
|
||||||
stream.history_public_to_subscribers,
|
stream.history_public_to_subscribers,
|
||||||
is_admin: page_params.is_admin,
|
is_admin: page_params.is_admin,
|
||||||
|
zulip_plan_is_not_limited: page_params.zulip_plan_is_not_limited,
|
||||||
|
stream_message_retention_days: stream.message_retention_days,
|
||||||
|
realm_message_retention_setting:
|
||||||
|
exports.get_display_text_for_realm_message_retention_setting(),
|
||||||
|
upgrade_text_for_wide_organization_logo:
|
||||||
|
page_params.upgrade_text_for_wide_organization_logo,
|
||||||
};
|
};
|
||||||
const change_privacy_modal = render_subscription_stream_privacy_modal(template_data);
|
const change_privacy_modal = render_subscription_stream_privacy_modal(template_data);
|
||||||
$("#stream_privacy_modal").remove();
|
$("#stream_privacy_modal").remove();
|
||||||
$("#subscriptions_table").append(change_privacy_modal);
|
$("#subscriptions_table").append(change_privacy_modal);
|
||||||
|
set_stream_message_retention_setting_dropdown(stream);
|
||||||
overlays.open_modal('#stream_privacy_modal');
|
overlays.open_modal('#stream_privacy_modal');
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
@@ -687,6 +728,11 @@ exports.initialize = function () {
|
|||||||
exports.open_edit_panel_for_row(this);
|
exports.open_edit_panel_for_row(this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("#subscriptions_table").on("change", ".stream_message_retention_setting", function (e) {
|
||||||
|
const dropdown_value = e.target.value;
|
||||||
|
change_stream_message_retention_days_block_display_property(dropdown_value);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
window.stream_edit = exports;
|
window.stream_edit = exports;
|
||||||
|
|||||||
@@ -55,6 +55,9 @@ exports.update_property = function (stream_id, property, value, other_values) {
|
|||||||
case 'stream_post_policy':
|
case 'stream_post_policy':
|
||||||
subs.update_stream_post_policy(sub, value);
|
subs.update_stream_post_policy(sub, value);
|
||||||
break;
|
break;
|
||||||
|
case 'message_retention_days':
|
||||||
|
stream_data.update_message_retention_setting(sub, value);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
blueslip.warn("Unexpected subscription property type", {property: property,
|
blueslip.warn("Unexpected subscription property type", {property: property,
|
||||||
value: value});
|
value: value});
|
||||||
|
|||||||
@@ -586,6 +586,11 @@ exports.setup_page = function (callback) {
|
|||||||
is_admin: page_params.is_admin,
|
is_admin: page_params.is_admin,
|
||||||
stream_post_policy_values: stream_data.stream_post_policy_values,
|
stream_post_policy_values: stream_data.stream_post_policy_values,
|
||||||
stream_post_policy: stream_data.stream_post_policy_values.everyone.code,
|
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,
|
||||||
|
upgrade_text_for_wide_organization_logo:
|
||||||
|
page_params.upgrade_text_for_wide_organization_logo,
|
||||||
};
|
};
|
||||||
|
|
||||||
const rendered = render_subscription_table_body(template_data);
|
const rendered = render_subscription_table_body(template_data);
|
||||||
|
|||||||
@@ -1061,6 +1061,20 @@ ul.grey-box {
|
|||||||
margin-right: 5px;
|
margin-right: 5px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input[type=text] {
|
||||||
|
width: 5ch;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
label.dropdown-title {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
width: auto;
|
||||||
|
margin-bottom: 0px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,4 +31,33 @@
|
|||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
{{#if is_admin}}
|
||||||
|
<h4>{{t "Message retention for stream" }}</h4>
|
||||||
|
|
||||||
|
{{> settings/upgrade_tip_widget}}
|
||||||
|
|
||||||
|
<li>
|
||||||
|
<div class="input-group inline-block">
|
||||||
|
<label for="stream_message_retention_setting" class="dropdown-title">{{t "Message retention period" }}</label>
|
||||||
|
<select name="stream_message_retention_setting"
|
||||||
|
class="stream_message_retention_setting" class="prop-element"
|
||||||
|
{{#unless zulip_plan_is_not_limited}}disabled{{/unless}}>
|
||||||
|
<option value="realm_default">{{t 'Use organization level settings '}}{{realm_message_retention_setting}} </option>
|
||||||
|
<option value="forever">{{t 'Retain forever' }}</option>
|
||||||
|
<option value="retain_for_period">{{t 'Retain for N days after posting' }}</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<div class="dependent-inline-block stream-message-retention-days-input">
|
||||||
|
<label class="inline-block">
|
||||||
|
{{t 'N' }}:
|
||||||
|
</label>
|
||||||
|
<input type="text" autocomplete="off"
|
||||||
|
name="stream-message-retention-days"
|
||||||
|
class="stream-message-retention-days"
|
||||||
|
value="{{ stream_message_retention_days }}"
|
||||||
|
{{#unless zulip_plan_is_not_limited}}disabled{{/unless}}/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
{{/if}}
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
Reference in New Issue
Block a user