Remove deprecated delete room admin API (#11213)

Remove deprecated delete room admin API,
`POST /_synapse/admin/v1/rooms/<room_id>/delete`
This commit is contained in:
Dirk Klimpel 2021-11-01 16:11:24 +01:00 committed by GitHub
parent 71f9966f27
commit 66bdca3e31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 79 additions and 124 deletions

View File

@ -0,0 +1 @@
Remove deprecated admin API to delete rooms (`POST /_synapse/admin/v1/rooms/<room_id>/delete`).

View File

@ -520,16 +520,6 @@ With all that being said, if you still want to try and recover the room:
4. If `new_room_user_id` was given, a 'Content Violation' will have been 4. If `new_room_user_id` was given, a 'Content Violation' will have been
created. Consider whether you want to delete that roomm. created. Consider whether you want to delete that roomm.
## Deprecated endpoint
The previous deprecated API will be removed in a future release, it was:
```
POST /_synapse/admin/v1/rooms/<room_id>/delete
```
It behaves the same way than the current endpoint except the path and the method.
# Make Room Admin API # Make Room Admin API
Grants another user the highest power available to a local user who is in the room. Grants another user the highest power available to a local user who is in the room.

View File

@ -87,6 +87,16 @@ process, for example:
# Upgrading to v1.47.0 # Upgrading to v1.47.0
## Removal of old Room Admin API
The following admin APIs were deprecated in [Synapse 1.34](https://github.com/matrix-org/synapse/blob/v1.34.0/CHANGES.md#deprecations-and-removals)
(released on 2021-05-17) and have now been removed:
- `POST /_synapse/admin/v1/<room_id>/delete`
Any scripts still using the above APIs should be converted to use the
[Delete Room API](https://matrix-org.github.io/synapse/latest/admin_api/rooms.html#delete-room-api).
## Deprecation of the `user_may_create_room_with_invites` module callback ## Deprecation of the `user_may_create_room_with_invites` module callback
The `user_may_create_room_with_invites` is deprecated and will be removed in a future The `user_may_create_room_with_invites` is deprecated and will be removed in a future

View File

@ -42,7 +42,6 @@ from synapse.rest.admin.registration_tokens import (
RegistrationTokenRestServlet, RegistrationTokenRestServlet,
) )
from synapse.rest.admin.rooms import ( from synapse.rest.admin.rooms import (
DeleteRoomRestServlet,
ForwardExtremitiesRestServlet, ForwardExtremitiesRestServlet,
JoinRoomAliasServlet, JoinRoomAliasServlet,
ListRoomRestServlet, ListRoomRestServlet,
@ -221,7 +220,6 @@ def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None:
RoomStateRestServlet(hs).register(http_server) RoomStateRestServlet(hs).register(http_server)
RoomRestServlet(hs).register(http_server) RoomRestServlet(hs).register(http_server)
RoomMembersRestServlet(hs).register(http_server) RoomMembersRestServlet(hs).register(http_server)
DeleteRoomRestServlet(hs).register(http_server)
JoinRoomAliasServlet(hs).register(http_server) JoinRoomAliasServlet(hs).register(http_server)
VersionServlet(hs).register(http_server) VersionServlet(hs).register(http_server)
UserAdminServlet(hs).register(http_server) UserAdminServlet(hs).register(http_server)

View File

@ -46,41 +46,6 @@ if TYPE_CHECKING:
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class DeleteRoomRestServlet(RestServlet):
"""Delete a room from server.
It is a combination and improvement of shutdown and purge room.
Shuts down a room by removing all local users from the room.
Blocking all future invites and joins to the room is optional.
If desired any local aliases will be repointed to a new room
created by `new_room_user_id` and kicked users will be auto-
joined to the new room.
If 'purge' is true, it will remove all traces of a room from the database.
"""
PATTERNS = admin_patterns("/rooms/(?P<room_id>[^/]+)/delete$")
def __init__(self, hs: "HomeServer"):
self.hs = hs
self.auth = hs.get_auth()
self.room_shutdown_handler = hs.get_room_shutdown_handler()
self.pagination_handler = hs.get_pagination_handler()
async def on_POST(
self, request: SynapseRequest, room_id: str
) -> Tuple[int, JsonDict]:
return await _delete_room(
request,
room_id,
self.auth,
self.room_shutdown_handler,
self.pagination_handler,
)
class ListRoomRestServlet(RestServlet): class ListRoomRestServlet(RestServlet):
""" """
List all rooms that are known to the homeserver. Results are returned List all rooms that are known to the homeserver. Results are returned
@ -218,7 +183,7 @@ class RoomRestServlet(RestServlet):
async def on_DELETE( async def on_DELETE(
self, request: SynapseRequest, room_id: str self, request: SynapseRequest, room_id: str
) -> Tuple[int, JsonDict]: ) -> Tuple[int, JsonDict]:
return await _delete_room( return await self._delete_room(
request, request,
room_id, room_id,
self.auth, self.auth,
@ -226,6 +191,58 @@ class RoomRestServlet(RestServlet):
self.pagination_handler, self.pagination_handler,
) )
async def _delete_room(
self,
request: SynapseRequest,
room_id: str,
auth: "Auth",
room_shutdown_handler: "RoomShutdownHandler",
pagination_handler: "PaginationHandler",
) -> Tuple[int, JsonDict]:
requester = await auth.get_user_by_req(request)
await assert_user_is_admin(auth, requester.user)
content = parse_json_object_from_request(request)
block = content.get("block", False)
if not isinstance(block, bool):
raise SynapseError(
HTTPStatus.BAD_REQUEST,
"Param 'block' must be a boolean, if given",
Codes.BAD_JSON,
)
purge = content.get("purge", True)
if not isinstance(purge, bool):
raise SynapseError(
HTTPStatus.BAD_REQUEST,
"Param 'purge' must be a boolean, if given",
Codes.BAD_JSON,
)
force_purge = content.get("force_purge", False)
if not isinstance(force_purge, bool):
raise SynapseError(
HTTPStatus.BAD_REQUEST,
"Param 'force_purge' must be a boolean, if given",
Codes.BAD_JSON,
)
ret = await room_shutdown_handler.shutdown_room(
room_id=room_id,
new_room_user_id=content.get("new_room_user_id"),
new_room_name=content.get("room_name"),
message=content.get("message"),
requester_user_id=requester.user.to_string(),
block=block,
)
# Purge room
if purge:
await pagination_handler.purge_room(room_id, force=force_purge)
return 200, ret
class RoomMembersRestServlet(RestServlet): class RoomMembersRestServlet(RestServlet):
""" """
@ -617,55 +634,3 @@ class RoomEventContextServlet(RestServlet):
) )
return 200, results return 200, results
async def _delete_room(
request: SynapseRequest,
room_id: str,
auth: "Auth",
room_shutdown_handler: "RoomShutdownHandler",
pagination_handler: "PaginationHandler",
) -> Tuple[int, JsonDict]:
requester = await auth.get_user_by_req(request)
await assert_user_is_admin(auth, requester.user)
content = parse_json_object_from_request(request)
block = content.get("block", False)
if not isinstance(block, bool):
raise SynapseError(
HTTPStatus.BAD_REQUEST,
"Param 'block' must be a boolean, if given",
Codes.BAD_JSON,
)
purge = content.get("purge", True)
if not isinstance(purge, bool):
raise SynapseError(
HTTPStatus.BAD_REQUEST,
"Param 'purge' must be a boolean, if given",
Codes.BAD_JSON,
)
force_purge = content.get("force_purge", False)
if not isinstance(force_purge, bool):
raise SynapseError(
HTTPStatus.BAD_REQUEST,
"Param 'force_purge' must be a boolean, if given",
Codes.BAD_JSON,
)
ret = await room_shutdown_handler.shutdown_room(
room_id=room_id,
new_room_user_id=content.get("new_room_user_id"),
new_room_name=content.get("room_name"),
message=content.get("message"),
requester_user_id=requester.user.to_string(),
block=block,
)
# Purge room
if purge:
await pagination_handler.purge_room(room_id, force=force_purge)
return 200, ret

View File

@ -17,8 +17,6 @@ import urllib.parse
from typing import List, Optional from typing import List, Optional
from unittest.mock import Mock from unittest.mock import Mock
from parameterized import parameterized_class
import synapse.rest.admin import synapse.rest.admin
from synapse.api.constants import EventTypes, Membership from synapse.api.constants import EventTypes, Membership
from synapse.api.errors import Codes from synapse.api.errors import Codes
@ -29,13 +27,6 @@ from tests import unittest
"""Tests admin REST events for /rooms paths.""" """Tests admin REST events for /rooms paths."""
@parameterized_class(
("method", "url_template"),
[
("POST", "/_synapse/admin/v1/rooms/%s/delete"),
("DELETE", "/_synapse/admin/v1/rooms/%s"),
],
)
class DeleteRoomTestCase(unittest.HomeserverTestCase): class DeleteRoomTestCase(unittest.HomeserverTestCase):
servlets = [ servlets = [
synapse.rest.admin.register_servlets, synapse.rest.admin.register_servlets,
@ -67,7 +58,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
self.room_id = self.helper.create_room_as( self.room_id = self.helper.create_room_as(
self.other_user, tok=self.other_user_tok self.other_user, tok=self.other_user_tok
) )
self.url = self.url_template % self.room_id self.url = "/_synapse/admin/v1/rooms/%s" % self.room_id
def test_requester_is_no_admin(self): def test_requester_is_no_admin(self):
""" """
@ -75,7 +66,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
""" """
channel = self.make_request( channel = self.make_request(
self.method, "DELETE",
self.url, self.url,
json.dumps({}), json.dumps({}),
access_token=self.other_user_tok, access_token=self.other_user_tok,
@ -88,10 +79,10 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
""" """
Check that unknown rooms/server return error 404. Check that unknown rooms/server return error 404.
""" """
url = self.url_template % "!unknown:test" url = "/_synapse/admin/v1/rooms/%s" % "!unknown:test"
channel = self.make_request( channel = self.make_request(
self.method, "DELETE",
url, url,
json.dumps({}), json.dumps({}),
access_token=self.admin_user_tok, access_token=self.admin_user_tok,
@ -104,10 +95,10 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
""" """
Check that invalid room names, return an error 400. Check that invalid room names, return an error 400.
""" """
url = self.url_template % "invalidroom" url = "/_synapse/admin/v1/rooms/%s" % "invalidroom"
channel = self.make_request( channel = self.make_request(
self.method, "DELETE",
url, url,
json.dumps({}), json.dumps({}),
access_token=self.admin_user_tok, access_token=self.admin_user_tok,
@ -126,7 +117,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
body = json.dumps({"new_room_user_id": "@unknown:test"}) body = json.dumps({"new_room_user_id": "@unknown:test"})
channel = self.make_request( channel = self.make_request(
self.method, "DELETE",
self.url, self.url,
content=body.encode(encoding="utf_8"), content=body.encode(encoding="utf_8"),
access_token=self.admin_user_tok, access_token=self.admin_user_tok,
@ -145,7 +136,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
body = json.dumps({"new_room_user_id": "@not:exist.bla"}) body = json.dumps({"new_room_user_id": "@not:exist.bla"})
channel = self.make_request( channel = self.make_request(
self.method, "DELETE",
self.url, self.url,
content=body.encode(encoding="utf_8"), content=body.encode(encoding="utf_8"),
access_token=self.admin_user_tok, access_token=self.admin_user_tok,
@ -164,7 +155,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
body = json.dumps({"block": "NotBool"}) body = json.dumps({"block": "NotBool"})
channel = self.make_request( channel = self.make_request(
self.method, "DELETE",
self.url, self.url,
content=body.encode(encoding="utf_8"), content=body.encode(encoding="utf_8"),
access_token=self.admin_user_tok, access_token=self.admin_user_tok,
@ -180,7 +171,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
body = json.dumps({"purge": "NotBool"}) body = json.dumps({"purge": "NotBool"})
channel = self.make_request( channel = self.make_request(
self.method, "DELETE",
self.url, self.url,
content=body.encode(encoding="utf_8"), content=body.encode(encoding="utf_8"),
access_token=self.admin_user_tok, access_token=self.admin_user_tok,
@ -206,7 +197,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
body = json.dumps({"block": True, "purge": True}) body = json.dumps({"block": True, "purge": True})
channel = self.make_request( channel = self.make_request(
self.method, "DELETE",
self.url.encode("ascii"), self.url.encode("ascii"),
content=body.encode(encoding="utf_8"), content=body.encode(encoding="utf_8"),
access_token=self.admin_user_tok, access_token=self.admin_user_tok,
@ -239,7 +230,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
body = json.dumps({"block": False, "purge": True}) body = json.dumps({"block": False, "purge": True})
channel = self.make_request( channel = self.make_request(
self.method, "DELETE",
self.url.encode("ascii"), self.url.encode("ascii"),
content=body.encode(encoding="utf_8"), content=body.encode(encoding="utf_8"),
access_token=self.admin_user_tok, access_token=self.admin_user_tok,
@ -273,7 +264,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
body = json.dumps({"block": False, "purge": False}) body = json.dumps({"block": False, "purge": False})
channel = self.make_request( channel = self.make_request(
self.method, "DELETE",
self.url.encode("ascii"), self.url.encode("ascii"),
content=body.encode(encoding="utf_8"), content=body.encode(encoding="utf_8"),
access_token=self.admin_user_tok, access_token=self.admin_user_tok,
@ -319,7 +310,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
# Test that the admin can still send shutdown # Test that the admin can still send shutdown
channel = self.make_request( channel = self.make_request(
self.method, "DELETE",
self.url, self.url,
json.dumps({"new_room_user_id": self.admin_user}), json.dumps({"new_room_user_id": self.admin_user}),
access_token=self.admin_user_tok, access_token=self.admin_user_tok,
@ -365,7 +356,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
# Test that the admin can still send shutdown # Test that the admin can still send shutdown
channel = self.make_request( channel = self.make_request(
self.method, "DELETE",
self.url, self.url,
json.dumps({"new_room_user_id": self.admin_user}), json.dumps({"new_room_user_id": self.admin_user}),
access_token=self.admin_user_tok, access_token=self.admin_user_tok,