From 54ccbaa96e0c3e4c4890884feaaf01535bf7b7d2 Mon Sep 17 00:00:00 2001 From: mStar Date: Thu, 7 Nov 2024 10:48:12 +0100 Subject: [PATCH] Logging, implement account deletion api endpoint Deleting an account via the API now works Also some logging --- server/apiLinstromAccounts.go | 49 ++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/server/apiLinstromAccounts.go b/server/apiLinstromAccounts.go index 5476546..16a7b5e 100644 --- a/server/apiLinstromAccounts.go +++ b/server/apiLinstromAccounts.go @@ -171,9 +171,14 @@ func linstromDeleteAccount(w http.ResponseWriter, r *http.Request) { store := StorageFromRequest(r) targetAccountId := AccountIdFromRequest(r) if targetAccountId != actorId { + log.Debug(). + Str("actor-id", actorId). + Str("target-id", targetAccountId). + Msg("Invalid attempt to delete account") other.HttpErr(w, HttpErrIdNotAuthenticated, "Action forbidden", http.StatusForbidden) return } + log.Info().Str("account-id", actorId).Msg("Deleting account") acc, err := store.FindAccountById(targetAccountId) if err != nil { log.Error().Err(err).Str("account-id", actorId).Msg("Failed to get account for deletion") @@ -191,10 +196,46 @@ func linstromDeleteAccount(w http.ResponseWriter, r *http.Request) { // TODO: Start job of sending out deletion messages to all federated servers // Clean up related data first - // User role - // Custom fields - _ = acc - store.DeleteAccount(actorId) + // TODO: Also delete media files + err = store.DeleteRoleByName(acc.ID) + if err != nil { + log.Error(). + Err(err). + Str("role-name", acc.ID). + Msg("Failed to delete user role for account deletion request") + other.HttpErr( + w, + HttpErrIdDbFailure, + "Failed to delete user role", + http.StatusInternalServerError, + ) + return + } + err = store.DeleteAllUserFieldsForAccountId(acc.ID) + if err != nil { + log.Error(). + Err(err). + Str("account-id", acc.ID). + Msg("Failed to delete custom info fields for account deletion") + other.HttpErr( + w, + HttpErrIdDbFailure, + "Failed to delete custom info fields", + http.StatusInternalServerError, + ) + return + } + err = store.DeleteAccount(actorId) + if err != nil { + log.Error().Err(err).Str("account-id", acc.ID).Msg("Failed to delete account") + other.HttpErr( + w, + HttpErrIdDbFailure, + "Failed to delete account from db", + http.StatusInternalServerError, + ) + return + } } func linstromIsFollowingAccount(w http.ResponseWriter, r *http.Request) {}