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.

api docs: Document DELETE /export/realm/{export_id}.

Agnish Baurib75055c39d8d
diff --git a/api_docs/changelog.md b/api_docs/changelog.md
index ae3f6a219a2..e803ad3351e 100644
--- a/api_docs/changelog.md
+++ b/api_docs/changelog.md
@@ -63,10 +63,10 @@ format used by the Zulip server that they are interacting with.
happened on a previous server, so its tarball is no longer stored
on this server. This change was also backported to the Zulip 12.x
series, at feature level 499.
-* `DELETE /export/realm/{export_id}`: Export records with the
- `export_from_prior_server` field set to `true` cannot be deleted, as the
- server has no exported data to delete for them. This change was also
- backported to the Zulip 12.x series, at feature level 499.
+* [`DELETE /export/realm/{export_id}`](/api/delete-realm-export): Export
+ records with the `export_from_prior_server` field set to `true` cannot
+ be deleted, as the server has no exported data to delete for them. This
+ change was also backported to the Zulip 12.x series, at feature level 499.
**Feature level 505**
@@ -114,10 +114,10 @@ releases.
for records that were carried across a realm import; the export
happened on a previous server, so its tarball is no longer stored
on this server. Backported change from feature level 506.
-* `DELETE /export/realm/{export_id}`: Export records with the
- `export_from_prior_server` field set to `true` cannot be deleted, as the
- server has no exported data to delete for them. Backported change from feature
- level 506.
+* [`DELETE /export/realm/{export_id}`](/api/delete-realm-export): Export
+ records with the `export_from_prior_server` field set to `true` cannot
+ be deleted, as the server has no exported data to delete for them.
+ Backported change from feature level 506.
## Changes in Zulip 12.0
diff --git a/api_docs/include/rest-endpoints.md b/api_docs/include/rest-endpoints.md
index 1cfc347f78c..d437598a929 100644
--- a/api_docs/include/rest-endpoints.md
+++ b/api_docs/include/rest-endpoints.md
@@ -159,6 +159,7 @@
* [Get all data exports](/api/get-realm-exports)
* [Create a data export](/api/export-realm)
* [Get data export consent state](/api/get-realm-export-consents)
+* [Delete a data export](/api/delete-realm-export)
* [Test welcome bot custom message](/api/test-welcome-bot-custom-message)
* [Deactivate an organization](/api/deactivate-realm)
diff --git a/zerver/openapi/curl_param_value_generators.py b/zerver/openapi/curl_param_value_generators.py
index ab9ffb92f1c..133aa806a82 100644
--- a/zerver/openapi/curl_param_value_generators.py
+++ b/zerver/openapi/curl_param_value_generators.py
@@ -27,7 +27,7 @@ from zerver.lib.test_helpers import read_test_image_file
from zerver.lib.upload import upload_message_attachment
from zerver.models import Client, Message, NamedUserGroup, UserPresence
from zerver.models.channel_folders import ChannelFolder
-from zerver.models.realms import get_realm
+from zerver.models.realms import RealmExport, get_realm
from zerver.models.users import UserProfile, get_user
from zerver.openapi.openapi import Parameter
@@ -523,3 +523,17 @@ def remove_bot_storage_bot_auth() -> dict[str, object]:
set_bot_storage(bot, [("foo", "bar")])
AUTHENTICATION_LINE[0] = f"{bot.email}:{bot.api_key}"
return {}
+
+
+@openapi_param_value_generator(["/export/realm/{export_id}:delete"])
+def delete_realm_export() -> dict[str, object]:
+ export = RealmExport.objects.create(
+ realm=get_realm("zulip"),
+ type=RealmExport.EXPORT_PUBLIC,
+ status=RealmExport.SUCCEEDED,
+ date_requested=timezone_now(),
+ date_started=timezone_now(),
+ date_succeeded=timezone_now(),
+ export_path="/dummy",
+ )
+ return {"export_id": export.id}
diff --git a/zerver/openapi/python_examples.py b/zerver/openapi/python_examples.py
index 83ba4b0dc99..985e62e12be 100644
--- a/zerver/openapi/python_examples.py
+++ b/zerver/openapi/python_examples.py
@@ -756,13 +756,14 @@ def get_realm_exports(client: Client) -> None:
@openapi_test_function("/export/realm:post")
-def export_realm(client: Client) -> None:
+def export_realm(client: Client) -> int:
# {code_example|start}
# Create a public data export of the organization.
result = client.call_endpoint(url="/export/realm", method="POST")
# {code_example|end}
assert_success_response(result)
validate_against_openapi_schema(result, "/export/realm", "post", "200")
+ return result["id"]
@openapi_test_function("/export/realm/consents:get")
@@ -775,6 +776,16 @@ def get_realm_export_consents(client: Client) -> None:
validate_against_openapi_schema(result, "/export/realm/consents", "get", "200")
+@openapi_test_function("/export/realm/{export_id}:delete")
+def delete_realm_export(client: Client, export_id: int) -> None:
+ # {code_example|start}
+ # Delete a completed public or standard data export.
+ result = client.call_endpoint(url=f"/export/realm/{export_id}", method="DELETE")
+ # {code_example|end}
+ assert_success_response(result)
+ validate_against_openapi_schema(result, "/export/realm/{export_id}", "delete", "200")
+
+
@openapi_test_function("/users/me:get")
def get_profile(client: Client) -> None:
# {code_example|start}
@@ -2289,9 +2300,10 @@ def test_server_organizations(client: Client) -> None:
get_realm_profile_fields(client)
reorder_realm_profile_fields(client)
create_realm_profile_field(client)
- export_realm(client)
+ export_id = export_realm(client)
get_realm_exports(client)
get_realm_export_consents(client)
+ delete_realm_export(client, export_id)
def test_errors(client: Client) -> None:
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml
index 9510b5d32a2..5bd234cbf44 100644
--- a/zerver/openapi/zulip.yaml
+++ b/zerver/openapi/zulip.yaml
@@ -17319,6 +17319,67 @@ paths:
responses:
"200":
$ref: "#/components/responses/SimpleSuccess"
+ /export/realm/{export_id}:
+ delete:
+ operationId: delete-realm-export
+ summary: Delete a data export
+ tags: ["server_and_organizations"]
+ x-requires-administrator: true
+ description: |
+ Delete a completed public or standard [data export][export-data]
+ of the organization.
+
+ Data exports that happened on a previous server (i.e., an export
+ with `"export_from_prior_server": true` in the
+ [`GET /export/realm`](/api/get-realm-exports#response) response)
+ cannot be deleted using this endpoint, since their tarball is no
+ longer stored on this server; attempting to do so fails with
+ the same error as for an export that has already been deleted.
+
+ This endpoint's success response does not describe the resulting
+ state of the organization's data exports. Clients should rely
+ on the [`realm_export` event](/api/get-events#realm_export),
+ which every organization administrator receives whenever a
+ data export's state changes, for the current state of an
+ organization's data exports.
+
+ **Changes**: Prior to Zulip 13.0 (feature level 506), data
+ exports without a tarball stored on this server had no
+ dedicated status, so attempting to delete one resulted in an
+ unexpected error. Starting at that feature level, such a
+ delete attempt instead fails cleanly, as described above. This
+ change was also backported to the Zulip 12.x series, at
+ feature level 499.
+
+ New in Zulip 2.1.
+
+ [export-data]: /help/export-your-organization#export-data-in-an-importable-format
+ parameters:
+ - name: export_id
+ in: path
+ description: The ID of the data export to be deleted.
+ required: true
+ schema:
+ type: integer
+ example: 1
+ responses:
+ "200":
+ $ref: "#/components/responses/SimpleSuccess"
+ "400":
+ description: Bad request.
+ content:
+ application/json:
+ schema:
+ allOf:
+ - $ref: "#/components/schemas/CodedError"
+ - description: |
+ A typical failed JSON response for an invalid data export ID.
+ example:
+ {
+ "code": "BAD_REQUEST",
+ "msg": "Invalid data export ID",
+ "result": "error",
+ }
/export/realm:
get:
operationId: get-realm-exports
diff --git a/zerver/tests/test_openapi.py b/zerver/tests/test_openapi.py
index a5c34a1e243..773a3afc0cc 100644
--- a/zerver/tests/test_openapi.py
+++ b/zerver/tests/test_openapi.py
@@ -215,8 +215,6 @@ class OpenAPIArgumentsTest(ZulipTestCase):
## This one isn't really representable
# "/user_uploads/{realm_id_str}/{filename}",
#### These realm administration settings are valuable to document:
- # Delete a data export.
- "/export/realm/{export_id}",
# Default stream groups are an unfinished feature and therefore
# shouldn't be added to the documentation until that's completed.
"/default_stream_groups/create",