Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
realm_export: Do export without consent if owner_full_content_access.
Shubham Padia6f5274e3c3e0
diff --git a/api_docs/unmerged.d/ZF-712cf1.md b/api_docs/unmerged.d/ZF-712cf1.mdnew file mode 100644index 00000000000..83254e5343a--- /dev/null+++ b/api_docs/unmerged.d/ZF-712cf1.md@@ -0,0 +1,7 @@+* [`POST /export/realm`](/api/export-realm): Added support for+ `export_type=3`, which requests a full export that includes private data for+ all users. This option requires the organization to have the+ `owner_full_content_access` flag set to True.+* [`GET /export/realm`](/api/get-realm-exports), [`GET /events`](/api/get-events):+ These endpoints now report `export_type=3` for a full export that includes+ private data for all users.diff --git a/docs/overview/changelog.md b/docs/overview/changelog.mdindex 16864723b48..44fa0926a66 100644--- a/docs/overview/changelog.md+++ b/docs/overview/changelog.md@@ -2291,7 +2291,7 @@ _Released 2022-07-21__Released 2022-07-11_- CVE-2022-31134: Exclude private file uploads from [exports of public- data](https://zulip.com/help/export-your-organization#export-for-migrating-to-zulip-cloud-or-a-self-hosted-server).+ data](https://zulip.com/help/export-your-organization#export-data-in-an-importable-format).We would like to thank Antoine Benoist for bringing this issue to our attention.- Upgraded python requirements.- Improved documentation for load balancers to mention CIDR addressdiff --git a/starlight_help/src/content/docs/export-your-organization.mdx b/starlight_help/src/content/docs/export-your-organization.mdxindex 8e84cb357e1..257b9dcfd79 100644--- a/starlight_help/src/content/docs/export-your-organization.mdx+++ b/starlight_help/src/content/docs/export-your-organization.mdx@@ -2,13 +2,13 @@title: Export your organization----import {Steps} from "@astrojs/starlight/components";+import {Steps, TabItem, Tabs} from "@astrojs/starlight/components";import FlattenedSteps from "../../components/FlattenedSteps.astro";import NavigationSteps from "../../components/NavigationSteps.astro";import ZulipNote from "../../components/ZulipNote.astro";import AdminOnly from "../include/_AdminOnly.mdx";-import ExportWithoutConsentRequirements from "../include/_ExportWithoutConsentRequirements.mdx";+import ExportAllPublicAndPrivateDataRequirements from "../include/_ExportAllPublicAndPrivateDataRequirements.mdx";import NotHumanExportFormat from "../include/_NotHumanExportFormat.mdx";import OwnerOnly from "../include/_OwnerOnly.mdx";@@ -19,79 +19,73 @@ import OwnerOnly from "../include/_OwnerOnly.mdx";</ZulipNote>Zulip has high quality export tools that can be used to migrate between the-hosted Zulip Cloud service and your own servers. Two types of data exports are-available for all Zulip organizations:+hosted Zulip Cloud service and your own servers. Zulip offers the following+options for exporting data in an importable format:-* [**Export of public- data**](#export-for-migrating-to-zulip-cloud-or-a-self-hosted-server):+* [**Public data+ only**](#export-data-in-an-importable-format):Complete data for your organization *other than* [privatechannel](/help/channel-permissions#private-channels) messages and [directmessages](/help/direct-messages). This export includes user settings andchannel subscriptions.-* [**Standard- export**](#export-for-migrating-to-zulip-cloud-or-a-self-hosted-server):+* [**Public and private data (with+ consent)**](#export-data-in-an-importable-format):Everything in the export of public data, plus all the [privatechannel](/help/channel-permissions#private-channels) messages and [directmessages](/help/direct-messages) that members who have[allowed](#configure-whether-administrators-can-export-your-private-data)administrators to export their private data can access.+* [**All public and private data**](#export-of-all-public-and-private-data).+ This option is only available to **corporate** [Zulip Cloud Standard][plans]+ and [Zulip Cloud Plus][plans] customers.-Two additional types of data exports are available to **corporate** [Zulip Cloud-Standard][plans] and [Zulip Cloud Plus][plans] customers:+In addition, [Zulip Cloud Standard][plans] and [Zulip Cloud Plus][plans]+customers can request a compliance export:-[plans]: https://zulip.com/plans/--* [**Full export without member consent**](#full-export-without-member-consent):- All the data in the organization.* [**Compliance export**](#compliance-export): A targeted, human-readable exportof messages matching some combination of criteria (e.g., sender, recipient,message keyword, or timestamp).-## Export for migrating to Zulip Cloud or a self-hosted server+[plans]: https://zulip.com/plans/++## Export data in an importable format<AdminOnly /><NotHumanExportFormat />-<FlattenedSteps>- <NavigationSteps target="settings/data-exports-admin" />-- 1. Click **Start export**.- 1. Select the desired **Export type**.- 1. Click **Start export** to begin the export process. After a few minutes,- you'll be able to download the exported data from the list of- data exports.- 1. Use [Zulip's logical data import tool][import-only] to import your data into- a self-hosted server. For Zulip Cloud imports, contact- [[email protected]](mailto:[email protected]).-</FlattenedSteps>--<ZulipNote>- Generating the export can take up to an hour for organizations- with a large number of messages or uploaded files.-</ZulipNote>--## Full export without member consent+<Tabs>+ <TabItem label="Desktop/Web">+ <FlattenedSteps>+ <NavigationSteps target="settings/data-exports-admin" />++ 1. Click **Start export**.+ 1. Select the desired **Export type**.+ 1. Click **Start export** to begin the export process. After a few minutes,+ you'll be able to download the exported data from the list of+ data exports.+ 1. Use [Zulip's logical data import tool][import-only] to import your data into+ a self-hosted server. For Zulip Cloud imports, contact+ [[email protected]](mailto:[email protected]).+ </FlattenedSteps>++ <ZulipNote>+ Generating the export can take up to an hour for organizations+ with a large number of messages or uploaded files.+ </ZulipNote>+ </TabItem>+</Tabs>++### Export of all public and private data<OwnerOnly />-<NotHumanExportFormat />+<ExportAllPublicAndPrivateDataRequirements />-<ExportWithoutConsentRequirements />--<Steps>- 1. Email [[email protected]](mailto:[email protected]) with your- organization's `zulipchat.com` URL, asking for a **full export without- member consent**. Please send the email from the same address- that you use to sign in to Zulip, so that Zulip Support can verify- that you are an owner of the organization.- 1. Once your authority to request the export has been verified, you will receive- an archive in the `.tar.gz` format containing all the information for your- organization.- 1. Import the tarball using [Zulip's logical data import tool][import-only].-</Steps>+Contact [[email protected]](mailto:[email protected]) to request access to this export+type, then follow the export instructions above.-If you self-host Zulip, a full export without member consent can be performed+If you self-host Zulip, an export of all public and private data can be performed[by your server's administrator][export-and-import].## Compliance export@@ -102,7 +96,7 @@ This type of export is recommended if you plan to work with the exported datadirectly (e.g., reading messages or processing them with a script), rather thanimporting the export into a new Zulip organization.-<ExportWithoutConsentRequirements />+<ExportAllPublicAndPrivateDataRequirements /><Steps>1. Email [[email protected]](mailto:[email protected]) asking for a **compliancediff --git a/starlight_help/src/content/include/_ExportWithoutConsentRequirements.mdx b/starlight_help/src/content/include/_ExportAllPublicAndPrivateDataRequirements.mdxsimilarity index 92%rename from starlight_help/src/content/include/_ExportWithoutConsentRequirements.mdxrename to starlight_help/src/content/include/_ExportAllPublicAndPrivateDataRequirements.mdxindex a902d205433..4f275809006 100644--- a/starlight_help/src/content/include/_ExportWithoutConsentRequirements.mdx+++ b/starlight_help/src/content/include/_ExportAllPublicAndPrivateDataRequirements.mdx@@ -7,7 +7,7 @@ To perform this export, your organization must meet the following requirements:Typically, this will be because your Zulip organization is administered by acorporation, and you are an official representative of that corporation.-By requesting and approving this export, you will assume full legal+By requesting and executing this export, you will assume full legalresponsibility that the appropriate employment agreements and corporate policyfor this type of export are in place. Note that many countries have laws thatrequire employers to notify employees of their use of such an export.diff --git a/starlight_help/src/content/include/_NotHumanExportFormat.mdx b/starlight_help/src/content/include/_NotHumanExportFormat.mdxindex 0dd69be035e..98f70d05577 100644--- a/starlight_help/src/content/include/_NotHumanExportFormat.mdx+++ b/starlight_help/src/content/include/_NotHumanExportFormat.mdx@@ -1,6 +1,2 @@-import ZulipNote from "../../components/ZulipNote.astro";--<ZulipNote>- This export is formatted for importing into Zulip Cloud or a self-hosted- installation of Zulip. It is not designed to be human-readable.-</ZulipNote>+This export is formatted for importing into Zulip Cloud or a self-hosted+installation of Zulip. It is not designed to be human-readable.diff --git a/web/src/settings_config.ts b/web/src/settings_config.tsindex 083b9815481..86988c7460e 100644--- a/web/src/settings_config.ts+++ b/web/src/settings_config.ts@@ -1337,19 +1337,24 @@ export type ExportTypeOption = {default: boolean;};-export type ExportTypeSlug = "public" | "full_with_consent";+export type ExportTypeSlug = "public" | "full_with_consent" | "full_without_consent";export const export_type_values: Record<ExportTypeSlug, ExportTypeOption> = {public: {value: 1,- description: $t({defaultMessage: "Public data"}),+ description: $t({defaultMessage: "Public data only"}),default: false,},full_with_consent: {value: 2,- description: $t({defaultMessage: "Standard"}),+ description: $t({defaultMessage: "Public and private data (with consent)"}),default: true,},+ full_without_consent: {+ value: 3,+ description: $t({defaultMessage: "All public and private data"}),+ default: false,+ },};export const bot_type_values = {diff --git a/web/src/settings_exports.ts b/web/src/settings_exports.tsindex 9c0b5a1b201..adc754482dd 100644--- a/web/src/settings_exports.ts+++ b/web/src/settings_exports.ts@@ -23,6 +23,7 @@ import * as loading from "./loading.ts";import * as people from "./people.ts";import * as scroll_util from "./scroll_util.ts";import * as settings_config from "./settings_config.ts";+import {current_user, realm} from "./state_data.ts";import * as timerender from "./timerender.ts";import type {HTMLSelectOneElement} from "./types.ts";import * as ui_report from "./ui_report.ts";@@ -51,6 +52,14 @@ const meta = {loaded: false,};+function get_export_type_options_to_render(): settings_config.ExportTypeOption[] {+ const standard_option =+ realm.realm_owner_full_content_access && current_user.is_owner+ ? settings_config.export_type_values.full_without_consent+ : settings_config.export_type_values.full_with_consent;+ return [settings_config.export_type_values.public, standard_option];+}+let users_consented_for_export_count: number;let total_users_count: number;@@ -95,9 +104,11 @@ export function populate_exports_table(exports: RealmExport[]): void {}let export_type_description = settings_config.export_type_values.public.description;- if (data.export_type !== settings_config.export_type_values.public.value) {- export_type_description =- settings_config.export_type_values.full_with_consent.description;+ const export_type_value = Object.values(settings_config.export_type_values).find(+ (element) => element.value === data.export_type,+ );+ if (export_type_value) {+ export_type_description = export_type_value.description;}return render_admin_export_list({@@ -361,7 +372,8 @@ function maybe_show_notes_about_unusable_users_if_exported(export_type: number):function show_start_export_modal(): void {const html_body = render_start_export_modal({- export_type_values: settings_config.export_type_values,+ export_type_values: get_export_type_options_to_render(),+ realm_owner_full_content_access: realm.realm_owner_full_content_access,});function start_export(): void {diff --git a/web/templates/start_export_modal.hbs b/web/templates/start_export_modal.hbsindex 0c1cbcbfdf0..dca446b594e 100644--- a/web/templates/start_export_modal.hbs+++ b/web/templates/start_export_modal.hbs@@ -1,19 +1,7 @@<p id="allow_private_data_export_banner_container"></p>-<p>- {{#tr}}- A public data export is a complete data export for your organization other than- <z-private-channel-link>private channel</z-private-channel-link> messages and- <z-direct-messages-link>direct messages</z-direct-messages-link>.- {{#*inline "z-private-channel-link"}}<a href="/help/channel-permissions#private-channels" target="_blank" rel="noopener noreferrer">{{> @partial-block}}</a>{{/inline}}- {{#*inline "z-direct-messages-link"}}<a href="/help/direct-messages" target="_blank" rel="noopener noreferrer">{{> @partial-block}}</a>{{/inline}}- {{/tr}}-</p>-<p>- {{t 'A standard export additionally includes private data accessible to users who have allowed administrators to export their private data.' }}-</p><form id="start-export-form"><div class="input-group">- <label for="export_type" class="modal-field-label">{{t "Export type" }}</label>+ <label for="export_type" class="modal-field-label">{{t "Data to export" }} {{> help_link_widget link="/help/export-your-organization" }}</label><select id="export_type" class="modal_select bootstrap-focus-style">{{#each export_type_values}}<option {{#if this.default }}selected{{/if}} value="{{this.value}}">{{this.description}}</option>@@ -23,4 +11,3 @@<p id="allow_private_data_export_stats"></p><div id="unusable-user-accounts-warning"></div></form>-diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yamlindex a8cd14d6dc1..db7c64e9986 100644--- a/zerver/openapi/zulip.yaml+++ b/zerver/openapi/zulip.yaml@@ -15453,7 +15453,7 @@ paths:New in Zulip 2.1.- [export-data]: /help/export-your-organization#export-for-migrating-to-zulip-cloud-or-a-self-hosted-server+ [export-data]: /help/export-your-organization#export-data-in-an-importable-formatresponses:"200":description: Success.@@ -15511,7 +15511,7 @@ paths:New in Zulip 2.1.- [export-data]: /help/export-your-organization#export-for-migrating-to-zulip-cloud-or-a-self-hosted-server+ [export-data]: /help/export-your-organization#export-data-in-an-importable-format[data-export]: https://zulip.readthedocs.io/en/stable/production/export-and-import.html#data-export[backups]: https://zulip.readthedocs.io/en/stable/production/export-and-import.html#backupsrequestBody:@@ -15523,19 +15523,28 @@ paths:properties:export_type:description: |- Whether to create a public or a standard data export.+ Whether the data export should be public, full with consent,+ or full without consent.- - 1 = Public data export.- - 2 = Standard data export.+ - 1 = Public data only export.+ - 2 = Public and private data export (with consent), which includes+ private data for users who have granted consent.+ - 3 = All public and private data export, which includes private data for+ all users. This option requires the organization to have+ the `owner_full_content_access` feature enabled.If not specified, defaults to 1.+ **Changes**: Zulip 12.0 (feature level ZF-712cf1) added the value 3+ option for data export of all public and private data.+**Changes**: New in Zulip 10.0 (feature level 304). Previously,all export requests were public data exports.type: integerenum:- 1- 2+ - 3default: 1example: 2responses:@@ -26038,10 +26047,15 @@ components:export_type:type: integerdescription: |- Whether the data export is a public or a standard data export.+ Whether the data export is public, full with consent, or full without consent.++ - 1 = Public data only export.+ - 2 = Public and private data export (with consent), which includes private data+ for users who have granted consent.+ - 3 = All public and private data, which includes private data for all users.- - 1 = Public data export.- - 2 = Standard data export.+ **Changes**: Zulip 12.0 (feature level ZF-712cf1) added the value 3 option+ for data export of all public and private data.**Changes**: New in Zulip 10.0 (feature level 304). Previously,the export type was not included in these objects because onlydiff --git a/zerver/tests/test_realm_export.py b/zerver/tests/test_realm_export.pyindex 795ec23d19f..50cb1536fd7 100644--- a/zerver/tests/test_realm_export.py+++ b/zerver/tests/test_realm_export.py@@ -363,6 +363,26 @@ class RealmExportTest(ZulipTestCase):continueself.assertFalse(export_consent["consented"])+ def check_success_realm_export(self, acting_user: UserProfile, export_type: int) -> None:+ with patch("zerver.views.realm_export.queue_event_on_commit") as mock_event_on_commit:+ result = self.client_post(+ "/json/export/realm",+ {+ "export_type": export_type,+ },+ )+ self.assert_json_success(result)+ response = orjson.loads(result.content)+ realm_export_id = response["id"]+ expected_event = {+ "type": "realm_export",+ "user_profile_id": acting_user.id,+ "realm_export_id": realm_export_id,+ }+ mock_event_on_commit.assert_called_once_with("deferred_work", expected_event)+ realm_export = RealmExport.objects.get(id=realm_export_id)+ self.assertEqual(realm_export.type, export_type)+def test_allow_export_with_no_usable_user_accounts(self) -> None:"""Generating export with no usable accounts should be allowed.@@ -370,26 +390,6 @@ class RealmExportTest(ZulipTestCase):admin = self.example_user("iago")self.login_user(admin)- def check_success_realm_export(acting_user: UserProfile, export_type: int) -> None:- with patch("zerver.views.realm_export.queue_event_on_commit") as mock_event_on_commit:- result = self.client_post(- "/json/export/realm",- {- "export_type": export_type,- },- )- self.assert_json_success(result)- response = orjson.loads(result.content)- realm_export_id = response["id"]- expected_event = {- "type": "realm_export",- "user_profile_id": acting_user.id,- "realm_export_id": realm_export_id,- }- mock_event_on_commit.assert_called_once_with("deferred_work", expected_event)- realm_export = RealmExport.objects.get(id=realm_export_id)- self.assertEqual(realm_export.type, export_type)-# For standard export, this means no one consented to their# private data being shared.UserProfile.objects.filter(@@ -398,7 +398,7 @@ class RealmExportTest(ZulipTestCase):).update(allow_private_data_export=False,)- check_success_realm_export(admin, RealmExport.EXPORT_FULL_WITH_CONSENT)+ self.check_success_realm_export(admin, RealmExport.EXPORT_FULL_WITH_CONSENT)# For public export, this means everyone has set their email# address visibility policy to nobody.@@ -409,4 +409,35 @@ class RealmExportTest(ZulipTestCase):email_address_visibility=UserProfile.EMAIL_ADDRESS_VISIBILITY_NOBODY,)- check_success_realm_export(admin, RealmExport.EXPORT_PUBLIC)+ self.check_success_realm_export(admin, RealmExport.EXPORT_PUBLIC)++ def test_full_without_consent_export_requires_org_permission(self) -> None:+ admin = self.example_user("iago")+ owner = self.example_user("desdemona")+ self.login_user(admin)++ admin.realm.owner_full_content_access = False+ admin.realm.save(update_fields=["owner_full_content_access"])+ result = self.client_post(+ "/json/export/realm",+ {+ "export_type": RealmExport.EXPORT_FULL_WITHOUT_CONSENT,+ },+ )+ self.assert_json_error(+ result,+ "Exports of all public and private data are not enabled for this organization.",+ )++ admin.realm.owner_full_content_access = True+ admin.realm.save(update_fields=["owner_full_content_access"])+ result = self.client_post(+ "/json/export/realm",+ {+ "export_type": RealmExport.EXPORT_FULL_WITHOUT_CONSENT,+ },+ )+ self.assert_json_error(result, "Must be an organization owner")++ self.login_user(owner)+ self.check_success_realm_export(owner, RealmExport.EXPORT_FULL_WITHOUT_CONSENT)diff --git a/zerver/views/realm_export.py b/zerver/views/realm_export.pyindex 6fb00d505d5..9eb39fb79b8 100644--- a/zerver/views/realm_export.py+++ b/zerver/views/realm_export.py@@ -10,7 +10,7 @@ from pydantic import Jsonfrom analytics.models import RealmCountfrom zerver.actions.realm_export import do_delete_realm_export, notify_realm_exportfrom zerver.decorator import require_realm_admin-from zerver.lib.exceptions import JsonableError+from zerver.lib.exceptions import JsonableError, OrganizationOwnerRequiredErrorfrom zerver.lib.export import get_realm_exports_serializedfrom zerver.lib.queue import queue_event_on_commitfrom zerver.lib.response import json_success@@ -31,7 +31,11 @@ def export_realm(Annotated[int,check_int_in_validator(- [RealmExport.EXPORT_PUBLIC, RealmExport.EXPORT_FULL_WITH_CONSENT]+ [+ RealmExport.EXPORT_PUBLIC,+ RealmExport.EXPORT_FULL_WITH_CONSENT,+ RealmExport.EXPORT_FULL_WITHOUT_CONSENT,+ ]),]] = RealmExport.EXPORT_PUBLIC,@@ -39,6 +43,21 @@ def export_realm(realm = user.realmEXPORT_LIMIT = 5+ if (+ export_type == RealmExport.EXPORT_FULL_WITHOUT_CONSENT+ and not realm.owner_full_content_access+ ):+ raise JsonableError(+ _("Exports of all public and private data are not enabled for this organization.")+ )++ if (+ export_type == RealmExport.EXPORT_FULL_WITHOUT_CONSENT+ and realm.owner_full_content_access+ and not user.is_realm_owner+ ):+ raise OrganizationOwnerRequiredError+# Exporting organizations with a huge amount of history can# potentially consume a lot of disk or otherwise have accidental# DoS risk; for that reason, we require large exports to be done