From 3160c3cce0ef39117a5e6f6620954f1970162cf2 Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Tue, 16 May 2023 17:14:14 +0000 Subject: [PATCH] realm_export: Return export id from POST which create it. --- api_docs/changelog.md | 5 +++++ version.py | 2 +- zerver/tests/test_realm_export.py | 8 +++++--- zerver/views/realm_export.py | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/api_docs/changelog.md b/api_docs/changelog.md index fb82a8d988..834b2121a1 100644 --- a/api_docs/changelog.md +++ b/api_docs/changelog.md @@ -20,6 +20,11 @@ format used by the Zulip server that they are interacting with. ## Changes in Zulip 7.0 +**Feature level 182** + +* `POST /export/realm`: This endpoint now returns the ID of the data + export object created by the request. + **Feature level 181** * [`GET /scheduled_messages`](/api/get-scheduled-messages), [`GET diff --git a/version.py b/version.py index b7575017ef..c772168cbb 100644 --- a/version.py +++ b/version.py @@ -33,7 +33,7 @@ DESKTOP_WARNING_VERSION = "5.4.3" # Changes should be accompanied by documentation explaining what the # new level means in api_docs/changelog.md, as well as "**Changes**" # entries in the endpoint's documentation in `zulip.yaml`. -API_FEATURE_LEVEL = 181 +API_FEATURE_LEVEL = 182 # Bump the minor PROVISION_VERSION to indicate that folks should provision # only when going from an old version of the code to a newer version. Bump diff --git a/zerver/tests/test_realm_export.py b/zerver/tests/test_realm_export.py index 4129c6608e..783f9e0804 100644 --- a/zerver/tests/test_realm_export.py +++ b/zerver/tests/test_realm_export.py @@ -159,7 +159,7 @@ class RealmExportTest(ZulipTestCase): result = self.client_post("/json/export/realm") self.assertTrue("INFO:root:Completed data export for zulip in " in info_logs.output[0]) mock_export.assert_called_once() - self.assert_json_success(result) + data = self.assert_json_success(result) self.assertFalse(os.path.exists(tarball_path)) # Get the entry and test that iago initiated it. @@ -167,6 +167,7 @@ class RealmExportTest(ZulipTestCase): event_type=RealmAuditLog.REALM_EXPORTED ).first() assert audit_log_entry is not None + self.assertEqual(audit_log_entry.id, data["id"]) self.assertEqual(audit_log_entry.acting_user_id, admin.id) # Test that the file is hosted, and the contents are as expected. @@ -226,14 +227,15 @@ class RealmExportTest(ZulipTestCase): ) mock_export.assert_called_once() # This is a success because the failure is swallowed in the queue worker - self.assert_json_success(result) + data = self.assert_json_success(result) + export_id = data["id"] # Check that the export shows up as failed result = self.client_get("/json/export/realm") response_dict = self.assert_json_success(result) export_dict = response_dict["exports"] self.assert_length(export_dict, 1) - export_id = export_dict[0]["id"] + self.assertEqual(export_dict[0]["id"], export_id) self.assertEqual(export_dict[0]["pending"], False) self.assertIsNone(export_dict[0]["export_url"]) self.assertIsNone(export_dict[0]["deleted_timestamp"]) diff --git a/zerver/views/realm_export.py b/zerver/views/realm_export.py index 2911c92ce9..40a4b717dd 100644 --- a/zerver/views/realm_export.py +++ b/zerver/views/realm_export.py @@ -85,7 +85,7 @@ def export_realm(request: HttpRequest, user: UserProfile) -> HttpResponse: "id": row.id, } transaction.on_commit(lambda: queue_json_publish("deferred_work", event)) - return json_success(request) + return json_success(request, data={"id": row.id}) @require_realm_admin