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.

confirm_deactivate_user: Provide additional information about user.

Nikhil Maske249d2a5d5513
diff --git a/frontend_tests/node_tests/bot_data.js b/frontend_tests/node_tests/bot_data.js
index 38ed75cb2c7..6dc1105e016 100644
--- a/frontend_tests/node_tests/bot_data.js
+++ b/frontend_tests/node_tests/bot_data.js
@@ -169,4 +169,10 @@ test("test_basics", () => {
assert.equal(bots[0].email, "[email protected]");
assert.equal(bots[1].email, "[email protected]");
})();
+
+ (function test_get_number_of_bots_owned_by_user() {
+ const bots_owned_by_user = bot_data.get_all_bots_owned_by_user(3);
+
+ assert.equal(bots_owned_by_user[0].email, "[email protected]");
+ })();
});
diff --git a/static/js/bot_data.js b/static/js/bot_data.js
index 381691d0f0c..06f6352bdf0 100644
--- a/static/js/bot_data.js
+++ b/static/js/bot_data.js
@@ -73,6 +73,16 @@ export function get_editable() {
return ret;
}
+export function get_all_bots_owned_by_user(user_id) {
+ const ret = [];
+ for (const bot of bots.values()) {
+ if (bot.owner_id === user_id && bot.is_active) {
+ ret.push(bot);
+ }
+ }
+ return ret;
+}
+
export function get(bot_id) {
return bots.get(bot_id);
}
diff --git a/static/js/settings_users.js b/static/js/settings_users.js
index d19e16cbf3b..98c672bfb90 100644
--- a/static/js/settings_users.js
+++ b/static/js/settings_users.js
@@ -428,19 +428,43 @@ function get_human_profile_data(fields_user_pills) {
}
export function confirm_deactivation(user_id, handle_confirm, loading_spinner) {
- const user = people.get_by_user_id(user_id);
- const opts = {
- username: user.full_name,
- email: settings_data.email_for_user_settings(user),
- };
- const html_body = render_settings_deactivation_user_modal(opts);
+ // Knowing the number of invites requires making this request. If the request fails,
+ // we won't have the accurate number of invites. So, we don't show the modal if the
+ // request fails.
+ channel.get({
+ url: "/json/invites",
+ idempotent: true,
+ timeout: 10 * 1000,
+ success(data) {
+ let number_of_invites_by_user = 0;
+ for (const invite of data.invites) {
+ if (invite.invited_by_user_id === user_id) {
+ number_of_invites_by_user = number_of_invites_by_user + 1;
+ }
+ }
- confirm_dialog.launch({
- html_heading: $t_html({defaultMessage: "Deactivate {name}"}, {name: user.full_name}),
- help_link: "/help/deactivate-or-reactivate-a-user#deactivate-ban-a-user",
- html_body,
- on_click: handle_confirm,
- loading_spinner,
+ const bots_owned_by_user = bot_data.get_all_bots_owned_by_user(user_id);
+ const user = people.get_by_user_id(user_id);
+ const opts = {
+ username: user.full_name,
+ email: settings_data.email_for_user_settings(user),
+ bots_owned_by_user,
+ number_of_invites_by_user,
+ };
+ const html_body = render_settings_deactivation_user_modal(opts);
+
+ confirm_dialog.launch({
+ html_heading: $t_html(
+ {defaultMessage: "Deactivate {name}"},
+ {name: user.full_name},
+ ),
+ help_link: "/help/deactivate-or-reactivate-a-user#deactivate-ban-a-user",
+ html_body,
+ id: "deactivate-user-modal",
+ on_click: handle_confirm,
+ loading_spinner,
+ });
+ },
});
}
diff --git a/static/templates/confirm_dialog/confirm_deactivate_user.hbs b/static/templates/confirm_dialog/confirm_deactivate_user.hbs
index 51e40e6a512..c019fb35b62 100644
--- a/static/templates/confirm_dialog/confirm_deactivate_user.hbs
+++ b/static/templates/confirm_dialog/confirm_deactivate_user.hbs
@@ -5,3 +5,16 @@
{{/tr}}
</p>
<p>{{t "Their password will be cleared from our systems, and any bots they maintain will be disabled." }}</p>
+<p>
+ {{#tr}}
+ <strong>{username}</strong> has {number_of_invites_by_user} unexpired invitations.
+ {{/tr}}
+ {{#if bots_owned_by_user}}
+ {{t "They administer the following bots:"}}
+ <ul>
+ {{#each bots_owned_by_user}}
+ <li>{{this.full_name}}</li>
+ {{/each}}
+ </ul>
+ {{/if}}
+</p>