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.

settings: Add UI setting option for controlling invite expiration time.

Johan Ehinger4207f0a299ba
diff --git a/static/js/invite.js b/static/js/invite.js
index a6c7dbf3c9c..a336c119631 100644
--- a/static/js/invite.js
+++ b/static/js/invite.js
@@ -1,5 +1,6 @@
import autosize from "autosize";
import ClipboardJS from "clipboard";
+import {addDays} from "date-fns";
import $ from "jquery";
import copy_invite_link from "../templates/copy_invite_link.hbs";
@@ -33,6 +34,7 @@ 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());
const stream_ids = [];
$("#invite-stream-checkboxes input:checked").each(function () {
const stream_id = Number.parseInt($(this).val(), 10);
@@ -42,6 +44,7 @@ function get_common_invitation_data() {
csrfmiddlewaretoken: $('input[name="csrfmiddlewaretoken"]').attr("value"),
invite_as,
stream_ids: JSON.stringify(stream_ids),
+ invite_expires_in_days: expires_in,
};
return data;
}
@@ -192,12 +195,22 @@ export function launch() {
});
}
+function valid_to() {
+ const time_valid = Number.parseFloat($("#expires_in").val());
+ if (!time_valid) {
+ return $t({defaultMessage: "Never expires"});
+ }
+ const valid_to = addDays(new Date(), time_valid);
+ return $t({defaultMessage: "Expires on {date}"}, {date: valid_to.toLocaleDateString()});
+}
+
export function initialize() {
const rendered = render_invite_user({
is_admin: page_params.is_admin,
is_owner: page_params.is_owner,
development_environment: page_params.development_environment,
invite_as_options: settings_config.user_role_values,
+ expires_in_options: settings_config.expires_in_values,
});
$(".app").append(rendered);
@@ -237,4 +250,9 @@ export function initialize() {
$("#invite-method-choice").show();
reset_error_messages();
});
+
+ $("#expires_on").text(valid_to());
+ $("#expires_in").on("change", () => {
+ $("#expires_on").text(valid_to());
+ });
}
diff --git a/static/js/settings_config.ts b/static/js/settings_config.ts
index bafa7b2c9d3..734c0756ec6 100644
--- a/static/js/settings_config.ts
+++ b/static/js/settings_config.ts
@@ -417,6 +417,41 @@ export const user_role_values = {
},
};
+export const expires_in_values = {
+ // Backend support for this configuration is not available yet.
+ // hour: {
+ // value: 1,
+ // description: $t({defaultMessage: "1 hour"}),
+ // default: false,
+ // },
+ day: {
+ value: 1,
+ description: $t({defaultMessage: "1 day"}),
+ default: false,
+ },
+ threeDays: {
+ value: 3,
+ description: $t({defaultMessage: "3 days"}),
+ default: false,
+ },
+ tenDays: {
+ value: 10,
+ description: $t({defaultMessage: "10 days"}),
+ default: true,
+ },
+ thirtyDays: {
+ value: 30,
+ 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,
+ // }
+};
+
const user_role_array = Object.values(user_role_values);
export const user_role_map = new Map(user_role_array.map((role) => [role.code, role.description]));
diff --git a/static/templates/invite_user.hbs b/static/templates/invite_user.hbs
index a3f290e86c4..e7a952985cc 100644
--- a/static/templates/invite_user.hbs
+++ b/static/templates/invite_user.hbs
@@ -29,6 +29,17 @@
{{/if}}
</div>
</div>
+ <div class="input-group">
+ <label for="expires_in">{{t "Invitation expires after" }}</label>
+ <div>
+ <select id="expires_in">
+ {{#each expires_in_options}}
+ <option {{#if this.default }}selected{{/if}} name="expires_in" value="{{this.value}}">{{this.description}}</option>
+ {{/each}}
+ </select>
+ </div>
+ <p id="expires_on"></p>
+ </div>
<div class="input-group">
<label for="invite_as">{{t "User(s) join as" }}
<a href="/help/roles-and-permissions" target="_blank" rel="noopener noreferrer">