Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
demo-orgs: Update modal for realm deactivation for demo conditions.
Lauryn Menard461fb63a071e
diff --git a/web/src/settings_org.ts b/web/src/settings_org.tsindex f706d76b78c..4e75d1984c2 100644--- a/web/src/settings_org.ts+++ b/web/src/settings_org.ts@@ -11,6 +11,7 @@ import * as audible_notifications from "./audible_notifications.ts";import * as blueslip from "./blueslip.ts";import * as channel from "./channel.ts";import {csrf_token} from "./csrf.ts";+import * as demo_organization_ui from "./demo_organizations_ui.ts";import * as dialog_widget from "./dialog_widget.ts";import * as dropdown_widget from "./dropdown_widget.ts";import * as group_permission_settings from "./group_permission_settings.ts";@@ -38,6 +39,7 @@ import {} from "./settings_components.ts";import * as settings_components from "./settings_components.ts";import * as settings_config from "./settings_config.ts";+import * as settings_data from "./settings_data.ts";import * as settings_notifications from "./settings_notifications.ts";import * as settings_realm_domains from "./settings_realm_domains.ts";import * as settings_ui from "./settings_ui.ts";@@ -871,10 +873,25 @@ export function deactivate_organization(e: JQuery.Event): void {e.preventDefault();e.stopPropagation();+ // A demo organization owner may not have configured an email address+ // for their account. If that is the case, then we only allow them to+ // deactivate the demo organization with deletion_delay_days set to 0,+ // i.e., immediate data deletion.+ const is_demo_organization = realm.demo_organization_scheduled_deletion_date !== undefined;+ let can_set_data_deletion = true;+ if (is_demo_organization) {+ can_set_data_deletion = !settings_data.user_email_not_configured();+ }+function do_deactivate_realm(): void {- const raw_delete_in = $<HTMLSelectOneElement>(- "select:not([multiple])#delete-realm-data-in",- ).val()!;+ let raw_delete_in: string;+ if (can_set_data_deletion) {+ raw_delete_in = $<HTMLSelectOneElement>(+ "select:not([multiple])#delete-realm-data-in",+ ).val()!;+ } else {+ raw_delete_in = "0";+ }let delete_in_days: number | null;// See settings_config.realm_deletion_in_values for why we do this conversion.@@ -906,6 +923,11 @@ export function deactivate_organization(e: JQuery.Event): void {let custom_deletion_time_input = realm.server_min_deactivated_realm_deletion_days ?? 0;let custom_deletion_time_unit = settings_config.custom_time_unit_values.days.name;+ if (is_demo_organization) {+ // Always allow for immediate deletion of demo organization data.+ custom_deletion_time_input = 0;+ }+function delete_data_in_text(): string {const $delete_in = $<HTMLSelectOneElement>("select:not([multiple])#delete-realm-data-in");const delete_data_value = $delete_in.val()!;@@ -941,8 +963,21 @@ export function deactivate_organization(e: JQuery.Event): void {return $t({defaultMessage: "Data will be deleted after {date}"}, {date});}- const minimum_allowed_days = realm.server_min_deactivated_realm_deletion_days ?? 0;- const maximum_allowed_days = realm.server_max_deactivated_realm_deletion_days;+ let minimum_allowed_days = realm.server_min_deactivated_realm_deletion_days ?? 0;+ let maximum_allowed_days = realm.server_max_deactivated_realm_deletion_days;++ if (is_demo_organization) {+ // Always allow for immediate deletion of demo organization data.+ minimum_allowed_days = 0;+ maximum_allowed_days =+ demo_organization_ui.get_demo_organization_deadline_days_remaining() - 1;+ // If the demo organization has almost reached the date of its+ // automatic scheduled deletion, then we render the version of+ // the modal that only allows for immediate data deletion.+ if (maximum_allowed_days <= 0) {+ can_set_data_deletion = false;+ }+ }function is_valid_time_period(time_period: string | number): boolean {if (time_period === "custom") {@@ -1004,23 +1039,7 @@ export function deactivate_organization(e: JQuery.Event): void {}function deactivate_realm_modal_post_render(): void {- settings_components.set_custom_time_inputs_visibility(- $("#delete-realm-data-in"),- custom_deletion_time_unit,- custom_deletion_time_input,- );- settings_components.set_time_input_formatted_text(- $("#delete-realm-data-in"),- delete_data_in_text(),- );-- $("#delete-realm-data-in").on("change", () => {- // If the user navigates away and back to the custom- // time input, we show a better value than "NaN" if- // the previous value was invalid.- if (!util.validate_custom_time_input(custom_deletion_time_input)) {- custom_deletion_time_input = 0;- }+ if (can_set_data_deletion) {settings_components.set_custom_time_inputs_visibility($("#delete-realm-data-in"),custom_deletion_time_unit,@@ -1030,46 +1049,79 @@ export function deactivate_organization(e: JQuery.Event): void {$("#delete-realm-data-in"),delete_data_in_text(),);- toggle_deactivate_submit_button();- });- $("#custom-deletion-time-input").on("keydown", (e) => {- if (e.key === "Enter") {- // Prevent submitting the realm deactivation form via Enter.- e.preventDefault();- return;- }- });-- $("#custom-realm-deletion-time").on(- "input",- ".custom-time-input-value, .custom-time-input-unit",- () => {- custom_deletion_time_input = util.check_time_input(- $<HTMLInputElement>("input#custom-deletion-time-input").val()!,+ $("#delete-realm-data-in").on("change", () => {+ // If the user navigates away and back to the custom+ // time input, we show a better value than "NaN" if+ // the previous value was invalid.+ if (!util.validate_custom_time_input(custom_deletion_time_input)) {+ custom_deletion_time_input = 0;+ }+ settings_components.set_custom_time_inputs_visibility(+ $("#delete-realm-data-in"),+ custom_deletion_time_unit,+ custom_deletion_time_input,);- custom_deletion_time_unit = $<HTMLSelectOneElement>(- "select:not([multiple])#custom-deletion-time-unit",- ).val()!;settings_components.set_time_input_formatted_text($("#delete-realm-data-in"),delete_data_in_text(),);toggle_deactivate_submit_button();- },- );+ });++ $("#custom-deletion-time-input").on("keydown", (e) => {+ if (e.key === "Enter") {+ // Prevent submitting the realm deactivation form via Enter.+ e.preventDefault();+ return;+ }+ });++ $("#custom-realm-deletion-time").on(+ "input",+ ".custom-time-input-value, .custom-time-input-unit",+ () => {+ custom_deletion_time_input = util.check_time_input(+ $<HTMLInputElement>("input#custom-deletion-time-input").val()!,+ );+ custom_deletion_time_unit = $<HTMLSelectOneElement>(+ "select:not([multiple])#custom-deletion-time-unit",+ ).val()!;+ settings_components.set_time_input_formatted_text(+ $("#delete-realm-data-in"),+ delete_data_in_text(),+ );+ toggle_deactivate_submit_button();+ },+ );+ }}const all_delete_options = Object.values(settings_config.realm_deletion_in_values);const valid_delete_options = all_delete_options.filter((option) =>is_valid_time_period(option.value),);++ // If there is only one valid option, the make sure that it is set as+ // the default when the modal is rendered. This will likely only be+ // true for demo organizations.+ if (valid_delete_options.length === 1) {+ valid_delete_options[0]!.default = true;+ }+const time_unit_choices = [settings_config.custom_time_unit_values.days,settings_config.custom_time_unit_values.weeks,];+ // If the demo organization is two weeks or less away from its+ // scheduled deletion date, then limit time unit choices to days.+ if (is_demo_organization && maximum_allowed_days !== null && maximum_allowed_days <= 14) {+ time_unit_choices.pop();+ }+const html_body = render_settings_deactivate_realm_modal({+ can_set_data_deletion,delete_in_options: valid_delete_options,custom_deletion_input_label: get_custom_deletion_input_text(),time_choices: time_unit_choices,diff --git a/web/templates/confirm_dialog/confirm_deactivate_realm.hbs b/web/templates/confirm_dialog/confirm_deactivate_realm.hbsindex c51c0c7c70f..cf49632ff85 100644--- a/web/templates/confirm_dialog/confirm_deactivate_realm.hbs+++ b/web/templates/confirm_dialog/confirm_deactivate_realm.hbs@@ -1,3 +1,4 @@+{{#if can_set_data_deletion}}<form id="realm-data-deletion-form"><div class="input-group"><label for="delete-realm-data-in" class="modal-field-label">{{t "After how much time should all data for this organization be permanently deleted (users, channels, messages, etc.)?" }}</label>@@ -20,3 +21,6 @@</div></form><p>{{t "Are you sure you want to deactivate this organization? All users will lose access to their Zulip accounts." }}</p>+{{else}}+<p>{{t "Are you sure you want to deactivate this organization? All data will be immediately deleted." }}</p>+{{/if}}