From ba0ebb115dc77f162d86954de4e286f8bf538f2d Mon Sep 17 00:00:00 2001 From: Till Faelligen <2353100+S7evinK@users.noreply.github.com> Date: Mon, 24 Apr 2023 11:19:01 +0200 Subject: [PATCH] Some maintenance --- clientapi/routing/admin.go | 7 +++++++ roomserver/internal/perform/perform_admin.go | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/clientapi/routing/admin.go b/clientapi/routing/admin.go index 81a110858..1ebec8e74 100644 --- a/clientapi/routing/admin.go +++ b/clientapi/routing/admin.go @@ -3,6 +3,7 @@ package routing import ( "context" "encoding/json" + "errors" "fmt" "net/http" "time" @@ -231,6 +232,12 @@ func AdminDownloadState(req *http.Request, device *api.Device, rsAPI roomserverA } } if err = rsAPI.PerformAdminDownloadState(req.Context(), roomID, device.UserID, spec.ServerName(serverName)); err != nil { + if errors.Is(err, eventutil.ErrRoomNoExists) { + return util.JSONResponse{ + Code: 200, + JSON: jsonerror.NotFound(eventutil.ErrRoomNoExists.Error()), + } + } logrus.WithError(err).WithFields(logrus.Fields{ "userID": device.UserID, "serverName": serverName, diff --git a/roomserver/internal/perform/perform_admin.go b/roomserver/internal/perform/perform_admin.go index 6d63d3b02..889568cce 100644 --- a/roomserver/internal/perform/perform_admin.go +++ b/roomserver/internal/perform/perform_admin.go @@ -40,7 +40,7 @@ type Admin struct { Leaver *Leaver } -// PerformEvacuateRoom will remove all local users from the given room. +// PerformAdminEvacuateRoom will remove all local users from the given room. func (r *Admin) PerformAdminEvacuateRoom( ctx context.Context, roomID string, @@ -139,6 +139,7 @@ func (r *Admin) PerformAdminEvacuateRoom( return affected, err } +// PerformAdminEvacuateUser will remove the given user from all rooms. func (r *Admin) PerformAdminEvacuateUser( ctx context.Context, userID string, @@ -184,6 +185,7 @@ func (r *Admin) PerformAdminEvacuateUser( return affected, nil } +// PerformAdminPurgeRoom removes all traces for the given room from the database. func (r *Admin) PerformAdminPurgeRoom( ctx context.Context, roomID string, @@ -193,6 +195,12 @@ func (r *Admin) PerformAdminPurgeRoom( return err } + // Evacuate the room before purging it from the database + if _, err := r.PerformAdminEvacuateRoom(ctx, roomID); err != nil { + logrus.WithField("room_id", roomID).WithError(err).Warn("Failed to evacuate room before purging") + return err + } + logrus.WithField("room_id", roomID).Warn("Purging room from roomserver") if err := r.DB.PurgeRoom(ctx, roomID); err != nil { logrus.WithField("room_id", roomID).WithError(err).Warn("Failed to purge room from roomserver")