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 14 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 docs/admin_api/purge_history_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ This API returns a JSON body like the following:
```

The status will be one of `active`, `complete`, or `failed`.
If `status` is `failed` there will be a string `error` with the error message.
dklimpel marked this conversation as resolved.
Show resolved Hide resolved

## Reclaim disk space (Postgres)

Expand Down
88 changes: 65 additions & 23 deletions docs/admin_api/rooms.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,10 @@ as room administrator and will contain a message explaining what happened. Users
to the new room will have power level `-10` by default, and thus be unable to speak.

If `block` is `true`, users will be prevented from joining the old room.
This option can also be used to pre-emptively block a room, even if it's unknown
to this homeserver. In this case, the room will be blocked, and no further action
will be taken. If `block` is `false`, attempting to delete an unknown room is
invalid and will be rejected as a bad request.
This option can in [Version 1](#version-1-old-version) also be used to pre-emptively
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait, what? why are we removing this ability? It's important to be able to pre-emptively block rooms.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That ist not removed. The ability in Version 1 is created in #11228 and there is also an issue #11283.
IMO a simple block of a room with a bg task is not a very good usage. And it is implemented with raise and catching exceptions. I think v1 of this API should be removed after publishing the block API.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hrm. Ok, let's leave it for now.

block a room, even if it's unknown to this homeserver. In this case, the room will be
blocked, and no further action will be taken. If `block` is `false`, attempting to
delete an unknown room is invalid and will be rejected as a bad request.

This API will remove all trace of the old room from your database after removing
all local users. If `purge` is `true` (the default), all traces of the old room will
Expand Down Expand Up @@ -494,7 +494,7 @@ a purge id:

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

Expand All @@ -519,7 +519,8 @@ The following JSON body parameters are available:
is not permitted and rooms in violation will be blocked.`
* `block` - Optional. If set to `true`, this room will be added to a blocking list,
preventing future attempts to join the room. Rooms can be blocked
even if they're not yet known to the homeserver. Defaults to `false`.
even if they're not yet known to the homeserver (only with
[Version 1](#version-1-old-version) of the API). Defaults to `false`.
* `purge` - Optional. If set to `true`, it will remove all traces of the room from your database.
Defaults to `true`.
* `force_purge` - Optional, and ignored unless `purge` is `true`. If set to `true`, it
Expand All @@ -537,9 +538,9 @@ 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).

### Query by `room_id`

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).

The API is:

Expand All @@ -551,20 +552,21 @@ A response body like the following is returned:

```json
{
"delete_status": [
"results": [
{
"purge_id": "purgeid1",
"delete_id": "delete_id1",
"status": "failed",
"result": {
"error": "error message",
"shutdown_room": {
"kicked_users": [],
"failed_to_kick_users": [],
"local_aliases": [],
"new_room_id": null
}
}, {
"purge_id": "purgeid2",
"status": "active",
"result": {
"delete_id": "delete_id2",
"status": "purging",
"shutdown_room": {
"kicked_users": [
"@foobar:example.com"
],
Expand All @@ -586,25 +588,65 @@ The following parameters should be set in the URL:

* `room_id` - The ID of the room.

**Response**
### Query by `delete_id`

With this API you can get the status of one specific task by `delete_id`.

The API is:

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

A response body like the following is returned:

```json
{
"status": "purging",
"shutdown_room": {
"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:

* `delete_id` - The ID for this delete.

### Response

The following fields are returned in the JSON response body:

- `delete_status` - An array of objects, each containing information about one task.
- `results` - An array of objects, each containing information about one task.
This field is omitted from the result when you query by `delete_id`.
Task objects contain the following fields:
- `delete_id` - The ID for this purge if you query by `room_id`.
- `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.
- `shutting_down` - The process is removing users from the room.
- `purging` - The process is purging the room and event data from database.
- `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`.
- `error` - A string that shows an error message if `status` is `failed`.
Otherwise this field is hidden.
- `shutdown_room` - 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.
migrated from the old room to the new.
- `new_room_id` - A string representing the room ID of the new room, or `null` if
no such room was created.

## Undoing room deletions

Expand Down
Loading