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

Commit 8840a7b

Browse files
authored
Convert delete room admin API to async endpoint (#11223)
Signed-off-by: Dirk Klimpel [email protected]
1 parent c99da2d commit 8840a7b

File tree

9 files changed

+1317
-91
lines changed

9 files changed

+1317
-91
lines changed

changelog.d/11223.feature

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

docs/admin_api/purge_history_api.md

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ This API returns a JSON body like the following:
7070

7171
The status will be one of `active`, `complete`, or `failed`.
7272

73+
If `status` is `failed` there will be a string `error` with the error message.
74+
7375
## Reclaim disk space (Postgres)
7476

7577
To reclaim the disk space and return it to the operating system, you need to run

docs/admin_api/rooms.md

+173-16
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
- [Room Members API](#room-members-api)
55
- [Room State API](#room-state-api)
66
- [Delete Room API](#delete-room-api)
7+
* [Version 1 (old version)](#version-1-old-version)
8+
* [Version 2 (new version)](#version-2-new-version)
9+
* [Status of deleting rooms](#status-of-deleting-rooms)
710
* [Undoing room shutdowns](#undoing-room-shutdowns)
811
- [Make Room Admin API](#make-room-admin-api)
912
- [Forward Extremities Admin API](#forward-extremities-admin-api)
@@ -397,10 +400,10 @@ as room administrator and will contain a message explaining what happened. Users
397400
to the new room will have power level `-10` by default, and thus be unable to speak.
398401

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

405408
This API will remove all trace of the old room from your database after removing
406409
all local users. If `purge` is `true` (the default), all traces of the old room will
@@ -412,6 +415,17 @@ several minutes or longer.
412415
The local server will only have the power to move local user and room aliases to
413416
the new room. Users on other servers will be unaffected.
414417

418+
To use it, you will need to authenticate by providing an ``access_token`` for a
419+
server admin: see [Admin API](../usage/administration/admin_api).
420+
421+
## Version 1 (old version)
422+
423+
This version works synchronously. That means you only get the response once the server has
424+
finished the action, which may take a long time. If you request the same action
425+
a second time, and the server has not finished the first one, the second request will block.
426+
This is fixed in version 2 of this API. The parameters are the same in both APIs.
427+
This API will become deprecated in the future.
428+
415429
The API is:
416430

417431
```
@@ -430,9 +444,6 @@ with a body of:
430444
}
431445
```
432446

433-
To use it, you will need to authenticate by providing an ``access_token`` for a
434-
server admin: see [Admin API](../usage/administration/admin_api).
435-
436447
A response body like the following is returned:
437448

438449
```json
@@ -449,6 +460,44 @@ A response body like the following is returned:
449460
}
450461
```
451462

463+
The parameters and response values have the same format as
464+
[version 2](#version-2-new-version) of the API.
465+
466+
## Version 2 (new version)
467+
468+
**Note**: This API is new, experimental and "subject to change".
469+
470+
This version works asynchronously, meaning you get the response from server immediately
471+
while the server works on that task in background. You can then request the status of the action
472+
to check if it has completed.
473+
474+
The API is:
475+
476+
```
477+
DELETE /_synapse/admin/v2/rooms/<room_id>
478+
```
479+
480+
with a body of:
481+
482+
```json
483+
{
484+
"new_room_user_id": "@someuser:example.com",
485+
"room_name": "Content Violation Notification",
486+
"message": "Bad Room has been shutdown due to content violations on this server. Please review our Terms of Service.",
487+
"block": true,
488+
"purge": true
489+
}
490+
```
491+
492+
The API starts the shut down and purge running, and returns immediately with a JSON body with
493+
a purge id:
494+
495+
```json
496+
{
497+
"delete_id": "<opaque id>"
498+
}
499+
```
500+
452501
**Parameters**
453502

454503
The following parameters should be set in the URL:
@@ -470,7 +519,8 @@ The following JSON body parameters are available:
470519
is not permitted and rooms in violation will be blocked.`
471520
* `block` - Optional. If set to `true`, this room will be added to a blocking list,
472521
preventing future attempts to join the room. Rooms can be blocked
473-
even if they're not yet known to the homeserver. Defaults to `false`.
522+
even if they're not yet known to the homeserver (only with
523+
[Version 1](#version-1-old-version) of the API). Defaults to `false`.
474524
* `purge` - Optional. If set to `true`, it will remove all traces of the room from your database.
475525
Defaults to `true`.
476526
* `force_purge` - Optional, and ignored unless `purge` is `true`. If set to `true`, it
@@ -480,17 +530,124 @@ The following JSON body parameters are available:
480530

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

483-
**Response**
533+
## Status of deleting rooms
484534

485-
The following fields are returned in the JSON response body:
535+
**Note**: This API is new, experimental and "subject to change".
536+
537+
It is possible to query the status of the background task for deleting rooms.
538+
The status can be queried up to 24 hours after completion of the task,
539+
or until Synapse is restarted (whichever happens first).
540+
541+
### Query by `room_id`
486542

487-
* `kicked_users` - An array of users (`user_id`) that were kicked.
488-
* `failed_to_kick_users` - An array of users (`user_id`) that that were not kicked.
489-
* `local_aliases` - An array of strings representing the local aliases that were migrated from
490-
the old room to the new.
491-
* `new_room_id` - A string representing the room ID of the new room, or `null` if
492-
no such room was created.
543+
With this API you can get the status of all active deletion tasks, and all those completed in the last 24h,
544+
for the given `room_id`.
545+
546+
The API is:
547+
548+
```
549+
GET /_synapse/admin/v2/rooms/<room_id>/delete_status
550+
```
551+
552+
A response body like the following is returned:
553+
554+
```json
555+
{
556+
"results": [
557+
{
558+
"delete_id": "delete_id1",
559+
"status": "failed",
560+
"error": "error message",
561+
"shutdown_room": {
562+
"kicked_users": [],
563+
"failed_to_kick_users": [],
564+
"local_aliases": [],
565+
"new_room_id": null
566+
}
567+
}, {
568+
"delete_id": "delete_id2",
569+
"status": "purging",
570+
"shutdown_room": {
571+
"kicked_users": [
572+
"@foobar:example.com"
573+
],
574+
"failed_to_kick_users": [],
575+
"local_aliases": [
576+
"#badroom:example.com",
577+
"#evilsaloon:example.com"
578+
],
579+
"new_room_id": "!newroomid:example.com"
580+
}
581+
}
582+
]
583+
}
584+
```
585+
586+
**Parameters**
587+
588+
The following parameters should be set in the URL:
589+
590+
* `room_id` - The ID of the room.
591+
592+
### Query by `delete_id`
593+
594+
With this API you can get the status of one specific task by `delete_id`.
595+
596+
The API is:
597+
598+
```
599+
GET /_synapse/admin/v2/rooms/delete_status/<delete_id>
600+
```
601+
602+
A response body like the following is returned:
603+
604+
```json
605+
{
606+
"status": "purging",
607+
"shutdown_room": {
608+
"kicked_users": [
609+
"@foobar:example.com"
610+
],
611+
"failed_to_kick_users": [],
612+
"local_aliases": [
613+
"#badroom:example.com",
614+
"#evilsaloon:example.com"
615+
],
616+
"new_room_id": "!newroomid:example.com"
617+
}
618+
}
619+
```
620+
621+
**Parameters**
622+
623+
The following parameters should be set in the URL:
624+
625+
* `delete_id` - The ID for this delete.
626+
627+
### Response
628+
629+
The following fields are returned in the JSON response body:
493630

631+
- `results` - An array of objects, each containing information about one task.
632+
This field is omitted from the result when you query by `delete_id`.
633+
Task objects contain the following fields:
634+
- `delete_id` - The ID for this purge if you query by `room_id`.
635+
- `status` - The status will be one of:
636+
- `shutting_down` - The process is removing users from the room.
637+
- `purging` - The process is purging the room and event data from database.
638+
- `complete` - The process has completed successfully.
639+
- `failed` - The process is aborted, an error has occurred.
640+
- `error` - A string that shows an error message if `status` is `failed`.
641+
Otherwise this field is hidden.
642+
- `shutdown_room` - An object containing information about the result of shutting down the room.
643+
*Note:* The result is shown after removing the room members.
644+
The delete process can still be running. Please pay attention to the `status`.
645+
- `kicked_users` - An array of users (`user_id`) that were kicked.
646+
- `failed_to_kick_users` - An array of users (`user_id`) that that were not kicked.
647+
- `local_aliases` - An array of strings representing the local aliases that were
648+
migrated from the old room to the new.
649+
- `new_room_id` - A string representing the room ID of the new room, or `null` if
650+
no such room was created.
494651

495652
## Undoing room deletions
496653

0 commit comments

Comments
 (0)