From b2f177689be39befa0e2d1fb0fc9c1c436bd4aaa Mon Sep 17 00:00:00 2001 From: Till Faelligen <2353100+S7evinK@users.noreply.github.com> Date: Mon, 6 Feb 2023 10:16:06 +0100 Subject: [PATCH] Evacuate room before purging --- docs/administration/4_adminapi.md | 2 +- roomserver/internal/perform/perform_admin.go | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/administration/4_adminapi.md b/docs/administration/4_adminapi.md index 6bf44483a..f7b1e24eb 100644 --- a/docs/administration/4_adminapi.md +++ b/docs/administration/4_adminapi.md @@ -68,7 +68,7 @@ This endpoint instructs Dendrite to immediately query `/devices/{userID}` on a f ## POST `/_dendrite/admin/purgeRoom/{roomID}` -This endpoint instructs Dendrite to remove the given room from its database. It does **NOT** remove media files. Depending on the size of the room, this may take a while. Will return an empty JSON once other components were instructed to delete the room. +This endpoint instructs Dendrite to remove the given room from its database. Before doing so, it will evacuate all local users from the room. It does **NOT** remove media files. Depending on the size of the room, this may take a while. Will return an empty JSON once other components were instructed to delete the room. ## POST `/_synapse/admin/v1/send_server_notice` diff --git a/roomserver/internal/perform/perform_admin.go b/roomserver/internal/perform/perform_admin.go index 3256162b4..b406cf558 100644 --- a/roomserver/internal/perform/perform_admin.go +++ b/roomserver/internal/perform/perform_admin.go @@ -257,7 +257,20 @@ func (r *Admin) PerformAdminPurgeRoom( return nil } - logrus.WithField("room_id", req.RoomID).Warn("Purging room from roomserver") + evacResp := &api.PerformAdminEvacuateRoomResponse{} + if err := r.PerformAdminEvacuateRoom(ctx, &api.PerformAdminEvacuateRoomRequest{RoomID: req.RoomID}, evacResp); err != nil { + res.Error = &api.PerformError{ + Code: api.PerformErrorBadRequest, + Msg: fmt.Sprintf("failed to evacuate room: %s", err), + } + return nil + } + + logrus.WithFields(logrus.Fields{ + "room_id": req.RoomID, + "evacuated_users": len(evacResp.Affected), + }).Warn("Evacuated room, purging room from roomserver now") + if err := r.DB.PurgeRoom(ctx, req.RoomID); err != nil { logrus.WithField("room_id", req.RoomID).WithError(err).Warn("Failed to purge room from roomserver") res.Error = &api.PerformError{