2019-11-20 04:49:11 -07:00
|
|
|
# Copyright 2019 The Matrix.org Foundation C.I.C.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
import logging
|
2021-11-29 15:19:45 -07:00
|
|
|
from http import HTTPStatus
|
2021-06-07 08:12:34 -06:00
|
|
|
from typing import TYPE_CHECKING, Tuple
|
2019-11-20 04:49:11 -07:00
|
|
|
|
|
|
|
from synapse.api.errors import SynapseError
|
|
|
|
from synapse.http.servlet import RestServlet
|
2021-06-07 08:12:34 -06:00
|
|
|
from synapse.http.site import SynapseRequest
|
2020-11-25 14:26:11 -07:00
|
|
|
from synapse.rest.admin._base import admin_patterns, assert_user_is_admin
|
2021-06-07 08:12:34 -06:00
|
|
|
from synapse.types import JsonDict
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
from synapse.server import HomeServer
|
2019-11-20 04:49:11 -07:00
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class DeleteGroupAdminRestServlet(RestServlet):
|
|
|
|
"""Allows deleting of local groups"""
|
|
|
|
|
2021-12-08 09:59:40 -07:00
|
|
|
PATTERNS = admin_patterns("/delete_group/(?P<group_id>[^/]*)$")
|
2019-11-20 04:49:11 -07:00
|
|
|
|
2021-06-07 08:12:34 -06:00
|
|
|
def __init__(self, hs: "HomeServer"):
|
2019-11-20 04:49:11 -07:00
|
|
|
self.group_server = hs.get_groups_server_handler()
|
|
|
|
self.is_mine_id = hs.is_mine_id
|
|
|
|
self.auth = hs.get_auth()
|
|
|
|
|
2021-06-07 08:12:34 -06:00
|
|
|
async def on_POST(
|
|
|
|
self, request: SynapseRequest, group_id: str
|
|
|
|
) -> Tuple[int, JsonDict]:
|
2019-11-20 04:49:11 -07:00
|
|
|
requester = await self.auth.get_user_by_req(request)
|
|
|
|
await assert_user_is_admin(self.auth, requester.user)
|
|
|
|
|
|
|
|
if not self.is_mine_id(group_id):
|
2021-11-29 15:19:45 -07:00
|
|
|
raise SynapseError(HTTPStatus.BAD_REQUEST, "Can only delete local groups")
|
2019-11-20 04:49:11 -07:00
|
|
|
|
|
|
|
await self.group_server.delete_group(group_id, requester.user.to_string())
|
2021-11-29 15:19:45 -07:00
|
|
|
return HTTPStatus.OK, {}
|