Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Convert delete room admin API to async endpoint #11223

Merged
merged 28 commits into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c35a367
Convert delete room admin API to async endpoint
dklimpel Oct 31, 2021
69bba24
newsfile
dklimpel Oct 31, 2021
a9f9e3a
disable flaky test
dklimpel Oct 31, 2021
9d381cf
Merge branch 'develop' into delete_room_bg
dklimpel Nov 1, 2021
6ddcc8e
Fix wrong unit test `test_block_room_and_not_purge`
dklimpel Nov 1, 2021
cf8b612
Apply suggestions from code review
dklimpel Nov 1, 2021
a37b09c
update docstrings and mark private fields with `_`
dklimpel Nov 2, 2021
5b24839
Merge remote-tracking branch 'synapse/develop' into delete_room_bg
dklimpel Nov 2, 2021
3f9a4f4
Reuse `RoomShutdownHandler.shutdown_room`
dklimpel Nov 2, 2021
a482170
Merge remote-tracking branch 'synapse/develop' into delete_room_bg
dklimpel Nov 3, 2021
2f1f483
try flaky unit test
dklimpel Nov 3, 2021
60ef11e
rework request of purge status
dklimpel Nov 4, 2021
76a62d5
add error message if delete fails
dklimpel Nov 8, 2021
7de0bf1
Apply suggestions from code review
dklimpel Nov 8, 2021
a618958
add simple unit test for `/purge_history_status`
dklimpel Nov 8, 2021
4f42348
rename response dicts
dklimpel Nov 8, 2021
5a764c8
add new status API `/rooms/delete_status/<purge_id>`
dklimpel Nov 8, 2021
32c0694
update doc
dklimpel Nov 8, 2021
7821ed2
update docstring
dklimpel Nov 8, 2021
fb2019d
Merge remote-tracking branch 'synapse/develop' into delete_room_bg
dklimpel Nov 9, 2021
3b3cf2a
fix merge
dklimpel Nov 9, 2021
bd70ffd
update test response code, introduced in #11228
dklimpel Nov 9, 2021
383d808
Merge remote-tracking branch 'synapse/develop' into delete_room_bg
dklimpel Nov 9, 2021
05dd106
make compatible with #11228
dklimpel Nov 9, 2021
11d9e87
rename status
dklimpel Nov 9, 2021
fea716f
separate `purge` and `delete`
dklimpel Nov 10, 2021
1e5c5a4
Apply suggestions from code review
dklimpel Nov 11, 2021
949e55f
lint and small fixes
dklimpel Nov 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/11223.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a new version of delete room admin API `DELETE /_synapse/admin/v2/rooms/<room_id>` to run it in background. Contributed by @dklimpel.
133 changes: 124 additions & 9 deletions docs/admin_api/rooms.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
- [Room Members API](#room-members-api)
- [Room State API](#room-state-api)
- [Delete Room API](#delete-room-api)
* [Version 1 (old version)](#version-1-old-version)
* [Version 2 (new version)](#version-2-new-version)
* [Status of deleting rooms](#status-of-deleting-rooms)
* [Undoing room shutdowns](#undoing-room-shutdowns)
- [Make Room Admin API](#make-room-admin-api)
- [Forward Extremities Admin API](#forward-extremities-admin-api)
Expand Down Expand Up @@ -408,6 +411,17 @@ several minutes or longer.
The local server will only have the power to move local user and room aliases to
the new room. Users on other servers will be unaffected.

To use it, you will need to authenticate by providing an ``access_token`` for a
server admin: see [Admin API](../usage/administration/admin_api).

## Version 1 (old version)

This version works synchronously. That means you only get the response once the server has
finished the action, which may take a long time. If you request the same action
a second time, and the server has not finished the first one, the second request will block.
This is fixed in version 2 of this API. The parameters are the same in both APIs.
This API will become deprecated in the future.

The API is:

```
Expand All @@ -426,9 +440,6 @@ with a body of:
}
```

To use it, you will need to authenticate by providing an ``access_token`` for a
server admin: see [Admin API](../usage/administration/admin_api).

A response body like the following is returned:

```json
Expand All @@ -445,6 +456,44 @@ A response body like the following is returned:
}
```

The parameters and response values have the same format as
[version 2](#version-2-new-version) of the API.

## Version 2 (new version)

**Note**: This API is new, experimental and "subject to change".

This version works asynchronously, meaning you get the response from server immediately
while the server works on that task in background. You can then request the status of the action
to check if it has completed.

The API is:

```
DELETE /_synapse/admin/v2/rooms/<room_id>
```

with a body of:

```json
{
"new_room_user_id": "@someuser:example.com",
"room_name": "Content Violation Notification",
"message": "Bad Room has been shutdown due to content violations on this server. Please review our Terms of Service.",
"block": true,
"purge": true
}
```

The API starts the shut down and purge running, and returns immediately with a JSON body with
a purge id:

```json
{
"purge_id": "<opaque id>"
}
```

**Parameters**

The following parameters should be set in the URL:
Expand Down Expand Up @@ -475,16 +524,82 @@ The following JSON body parameters are available:

The JSON body must not be empty. The body must be at least `{}`.

## Status of deleting rooms

**Note**: This API is new, experimental and "subject to change".

It is possible to query the status of the background task for deleting rooms.
The status can be queried up to 24 hours after completion of the task,
or until Synapse is restarted (whichever happens first).

With this API you can get the status of all tasks the last 24h for this `room_id`.
dklimpel marked this conversation as resolved.
Show resolved Hide resolved
If you want only get the status of one specific task, you can also use
the [Purge status query API](purge_history_api.md#Purge-status-query).
dklimpel marked this conversation as resolved.
Show resolved Hide resolved

The API is:

```
GET /_synapse/admin/v2/rooms/<room_id>/delete_status
```

A response body like the following is returned:

```json
{
"delete_status": [
dklimpel marked this conversation as resolved.
Show resolved Hide resolved
{
"purge_id": "purgeid1",
"status": "failed",
"result": {
dklimpel marked this conversation as resolved.
Show resolved Hide resolved
"kicked_users": [],
"failed_to_kick_users": [],
"local_aliases": [],
"new_room_id": null
}
}, {
"purge_id": "purgeid2",
"status": "active",
"result": {
"kicked_users": [
"@foobar:example.com"
],
"failed_to_kick_users": [],
"local_aliases": [
"#badroom:example.com",
"#evilsaloon:example.com"
],
"new_room_id": "!newroomid:example.com"
}
}
]
}
```

**Parameters**

The following parameters should be set in the URL:

* `room_id` - The ID of the room.

**Response**

The following fields are returned in the JSON response body:

* `kicked_users` - An array of users (`user_id`) that were kicked.
* `failed_to_kick_users` - An array of users (`user_id`) that that were not kicked.
* `local_aliases` - An array of strings representing the local aliases that were migrated from
the old room to the new.
* `new_room_id` - A string representing the room ID of the new room.

- `delete_status` - An array of objects, each containing information about one task.
Task objects contain the following fields:
- `status` - The status will be one of:
- `remove members` - The process is removing users from the `room_id`.
- `active` - The process is purging the room from database.
dklimpel marked this conversation as resolved.
Show resolved Hide resolved
- `complete` - The process has completed successfully.
- `failed` - The process is aborted, an error has occurred.
- `result` - An object containing information about the result of shutting down the room.
*Note:* The result is shown after removing the room members. The delete process can
still be running. Please pay attention to the `status`.
- `kicked_users` - An array of users (`user_id`) that were kicked.
- `failed_to_kick_users` - An array of users (`user_id`) that that were not kicked.
- `local_aliases` - An array of strings representing the local aliases that were
migrated from the old room to the new.
- `new_room_id` - A string representing the room ID of the new room.

## Undoing room deletions

Expand Down
Loading