Logging, implement account deletion api endpoint

Deleting an account via the API now works
Also some logging
This commit is contained in:
Melody Becker 2024-11-07 10:48:12 +01:00
parent cea3009641
commit 54ccbaa96e

View file

@ -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) {}