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_export: Warn if some accounts will be unusable.

PieterCK0b063878d334
diff --git a/web/src/people.ts b/web/src/people.ts
index 86fba6a91c5..d2d1b63797e 100644
--- a/web/src/people.ts
+++ b/web/src/people.ts
@@ -1975,6 +1975,19 @@ export function fetch_users_from_server(opts: FetchUserDataParams): void {
},
});
}
+export function get_users_that_match_role_ids(
+ user_ids: Set<number>,
+ role_ids: Set<number>,
+): User[] {
+ const users = new Array<User>();
+ for (const user_id of user_ids) {
+ const person = get_by_user_id(user_id);
+ if (person && role_ids.has(person.role)) {
+ users.push(person);
+ }
+ }
+ return users;
+}
export async function fetch_users(user_ids: Set<number>): Promise<UsersFetchResponse["members"]> {
// Requested users outside the set of known valid user IDs likely
diff --git a/web/src/settings_exports.ts b/web/src/settings_exports.ts
index 53439e476e2..b8a02a6f518 100644
--- a/web/src/settings_exports.ts
+++ b/web/src/settings_exports.ts
@@ -3,6 +3,7 @@ import type * as tippy from "tippy.js";
import * as z from "zod/mini";
import render_confirm_delete_data_export from "../templates/confirm_dialog/confirm_delete_data_export.hbs";
+import render_export_modal_warning_notes from "../templates/export_modal_warning_notes.hbs";
import render_allow_private_data_export_banner from "../templates/modal_banner/allow_private_data_export_banner.hbs";
import render_admin_export_consent_list from "../templates/settings/admin_export_consent_list.hbs";
import render_admin_export_list from "../templates/settings/admin_export_list.hbs";
@@ -188,6 +189,24 @@ function get_export_consents_having_consent_value(consent: boolean): ExportConse
return export_consent_list;
}
+function get_export_consents_having_email_visibility_value(
+ email_address_visibility_code: number,
+): ExportConsent[] {
+ const export_consent_list: ExportConsent[] = [];
+ for (const [user_id, user_consent_info] of export_consents.entries()) {
+ const consented = user_consent_info.consented;
+ const email_address_visibility = user_consent_info.email_address_visibility;
+ if (email_address_visibility_code === email_address_visibility) {
+ export_consent_list.push({
+ user_id,
+ consented,
+ email_address_visibility,
+ });
+ }
+ }
+ return export_consent_list;
+}
+
export function redraw_export_consents_list(): void {
let new_list_data;
if (filter_by_consent_dropdown_widget.value() === filter_by_consent_options[0]!.unique_id) {
@@ -297,6 +316,49 @@ export function refresh_allow_private_data_export_banner(): void {
}
}
+function maybe_show_notes_about_unusable_users_if_exported(export_type: number): void {
+ // Show warnings if there are users whose accounts will be inaccessible
+ // once exported. A user account will be inaccessible if they:
+ // - Don’t consent to their private data being exported and “Standard
+ // export” is selected.
+ // - Have set their email visibility to “nobody” and “Public export”
+ // is selected.
+ let unusable_user_ids: number[] = [];
+ const $warning_container = $("div#unusable-user-accounts-warning");
+ $warning_container.empty();
+ if (export_type === settings_config.export_type_values.export_full_with_consent.value) {
+ const non_consenting_users = get_export_consents_having_consent_value(false);
+ unusable_user_ids = non_consenting_users.map((user) => user.user_id);
+ } else if (export_type === settings_config.export_type_values.export_public.value) {
+ const users_with_inaccessible_email = get_export_consents_having_email_visibility_value(
+ settings_config.email_address_visibility_values.nobody.code,
+ );
+ unusable_user_ids = users_with_inaccessible_email.map((user) => user.user_id);
+ } else {
+ return;
+ }
+
+ if (unusable_user_ids.length === 0) {
+ return;
+ }
+
+ // List admins/owners who won’t be able to log in.
+ const admins_or_owners_with_unusable_account = people.get_users_that_match_role_ids(
+ new Set(unusable_user_ids),
+ new Set([
+ settings_config.user_role_values.admin.code,
+ settings_config.user_role_values.owner.code,
+ ]),
+ );
+
+ const $export_warnings = render_export_modal_warning_notes({
+ unusable_user_count: unusable_user_ids.length,
+ unusable_admin_users: admins_or_owners_with_unusable_account,
+ unusable_admin_user_count: admins_or_owners_with_unusable_account.length,
+ });
+ $warning_container.append($export_warnings);
+}
+
function show_start_export_modal(): void {
const html_body = render_start_export_modal({
export_type_values: settings_config.export_type_values,
@@ -359,7 +421,9 @@ function show_start_export_modal(): void {
$("#allow_private_data_export_stats").hide();
$(".allow_private_data_export_warning").hide();
}
+ maybe_show_notes_about_unusable_users_if_exported(selected_export_type);
});
+ $export_type.trigger("change");
}
dialog_widget.launch({
diff --git a/web/templates/export_modal_warning_notes.hbs b/web/templates/export_modal_warning_notes.hbs
new file mode 100644
index 00000000000..16c4ef303d1
--- /dev/null
+++ b/web/templates/export_modal_warning_notes.hbs
@@ -0,0 +1,42 @@
+{{#if unusable_user_count}}
+ <p>
+ {{#tr}}
+ You don't have permission to <z-help-link>access</z-help-link> the
+ email {unusable_user_count, plural, one {address} other {addresses}}
+ of {unusable_user_count, plural, one {# user} other {# users}}.
+ {{#*inline "z-help-link"}}
+ <a target="_blank" rel="noopener noreferrer"
+ href="#/help/configure-email-visibility">
+ {{> @partial-block}}
+ </a>
+ {{/inline}}
+ {{/tr~}}
+ {{~#tr}}
+ Accounts for users whose emails you can't access will be created
+ with placeholder email addresses. A placeholder email must be
+ updated by an administrator for the user to be able to log in.
+ {{/tr}}
+ </p>
+
+ {{#if unusable_admin_user_count}}
+ <p>
+ {{#tr}}
+ The following {unusable_admin_user_count, plural, one
+ {administrator} other {administrators}} will be unable to
+ log in: <z-user-pills></z-user-pills>
+
+ {{#*inline "z-user-pills"}}
+ {{#each unusable_admin_users}}
+ {{> ./user_display_only_pill
+ user_id= this.user_id
+ display_value= this.full_name
+ img_src= this.avatar_url
+ is_active= true
+ }}
+ {{#unless @last}}, {{/unless}}
+ {{/each}}
+ {{/inline}}
+ {{/tr}}
+ </p>
+ {{/if}}
+{{/if}}
diff --git a/web/templates/start_export_modal.hbs b/web/templates/start_export_modal.hbs
index 236ee64b750..0c1cbcbfdf0 100644
--- a/web/templates/start_export_modal.hbs
+++ b/web/templates/start_export_modal.hbs
@@ -21,4 +21,6 @@
</select>
</div>
<p id="allow_private_data_export_stats"></p>
+ <div id="unusable-user-accounts-warning"></div>
</form>
+
diff --git a/web/tests/people.test.cjs b/web/tests/people.test.cjs
index 4c011563e67..c01f591cd42 100644
--- a/web/tests/people.test.cjs
+++ b/web/tests/people.test.cjs
@@ -22,6 +22,7 @@ const channel = mock_esm("../src/channel");
const muted_users = zrequire("muted_users");
const people = zrequire("people");
+const settings_config = zrequire("../src/settings_config.ts");
const {set_current_user, set_realm} = zrequire("state_data");
const user_groups = zrequire("user_groups");
const {initialize_user_settings} = zrequire("user_settings");
@@ -1638,6 +1639,40 @@ test_people("sort_by_username", () => {
]);
});
+test_people("get_users_that_match_role_ids", () => {
+ people.add_active_user(realm_admin);
+ people.add_active_user(realm_owner);
+ people.add_active_user(moderator);
+ people.add_active_user(guest);
+
+ const user_ids = new Set([
+ realm_admin.user_id,
+ realm_owner.user_id,
+ moderator.user_id,
+ guest.user_id,
+ ]);
+ let users = people.get_users_that_match_role_ids(
+ user_ids,
+ new Set([settings_config.user_role_values.admin.code]),
+ );
+ assert.deepEqual(new Set(users), new Set([realm_admin]));
+
+ users = people.get_users_that_match_role_ids(
+ user_ids,
+ new Set([settings_config.user_role_values.moderator.code]),
+ );
+ assert.deepEqual(new Set(users), new Set([moderator]));
+
+ users = people.get_users_that_match_role_ids(
+ user_ids,
+ new Set([
+ settings_config.user_role_values.admin.code,
+ settings_config.user_role_values.owner.code,
+ ]),
+ );
+ assert.deepEqual(new Set(users), new Set([realm_owner, realm_admin]));
+});
+
// reset to native Date()
run_test("reset MockDate", () => {
MockDate.reset();