invite: Add frontend support to send an invite which never expires.

Fixes part of #20337.
This commit is contained in:
Sahil Batra 2021-12-01 16:40:58 +05:30 committed by Tim Abbott
parent 392b17da5f
commit 9be82356cb
4 changed files with 25 additions and 8 deletions

View File

@ -34,7 +34,15 @@ function reset_error_messages() {
function get_common_invitation_data() {
const invite_as = Number.parseInt($("#invite_as").val(), 10);
const expires_in = Number.parseFloat($("#expires_in").val());
let expires_in = $("#expires_in").val();
// See settings_config.expires_in_values for why we do this conversion.
if (expires_in === "null") {
expires_in = JSON.stringify(null);
} else {
expires_in = Number.parseFloat($("#expires_in").val());
}
const stream_ids = [];
$("#invite-stream-checkboxes input:checked").each(function () {
const stream_id = Number.parseInt($(this).val(), 10);

View File

@ -467,12 +467,15 @@ export const expires_in_values = {
description: $t({defaultMessage: "30 days"}),
default: false,
},
// Backend support for this configuration is not available yet.
// never: {
// value: "never",
// description: $t({defaultMessage: "Never expires"}),
// default: false,
// }
never: {
// Ideally we'd just store `null`, not the string `"null"`, but
// .val() will read null back as `""`. Custom logic in
// get_common_invitation_data converts this back to `null`
// before sending to the server.
value: "null",
description: $t({defaultMessage: "Never expires"}),
default: false,
},
};
const user_role_array = Object.values(user_role_values);

View File

@ -62,7 +62,9 @@ function populate_invites(invites_data) {
name: "admin_invites_list",
modifier(item) {
item.invited_absolute_time = timerender.absolute_time(item.invited * 1000);
if (item.expiry_date !== null) {
item.expiry_date_absolute_time = timerender.absolute_time(item.expiry_date * 1000);
}
item.is_admin = page_params.is_admin;
item.disable_buttons =
item.invited_as === settings_config.user_role_values.owner.code &&

View File

@ -22,7 +22,11 @@
<span class="invited_at">{{invited_absolute_time}}</span>
</td>
<td>
{{#if expiry_date_absolute_time}}
<span class="expires_at">{{expiry_date_absolute_time}}</span>
{{else}}
<span class="expires_at">{{t "Never expires"}}</span>
{{/if}}
</td>
<td>
<span>{{invited_as_text}}</span>