Logging, implement account deletion api endpoint
Deleting an account via the API now works Also some logging
This commit is contained in:
parent
cea3009641
commit
54ccbaa96e
1 changed files with 45 additions and 4 deletions
|
@ -171,9 +171,14 @@ func linstromDeleteAccount(w http.ResponseWriter, r *http.Request) {
|
||||||
store := StorageFromRequest(r)
|
store := StorageFromRequest(r)
|
||||||
targetAccountId := AccountIdFromRequest(r)
|
targetAccountId := AccountIdFromRequest(r)
|
||||||
if targetAccountId != actorId {
|
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)
|
other.HttpErr(w, HttpErrIdNotAuthenticated, "Action forbidden", http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
log.Info().Str("account-id", actorId).Msg("Deleting account")
|
||||||
acc, err := store.FindAccountById(targetAccountId)
|
acc, err := store.FindAccountById(targetAccountId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Str("account-id", actorId).Msg("Failed to get account for deletion")
|
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
|
// TODO: Start job of sending out deletion messages to all federated servers
|
||||||
|
|
||||||
// Clean up related data first
|
// Clean up related data first
|
||||||
// User role
|
// TODO: Also delete media files
|
||||||
// Custom fields
|
err = store.DeleteRoleByName(acc.ID)
|
||||||
_ = acc
|
if err != nil {
|
||||||
store.DeleteAccount(actorId)
|
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) {}
|
func linstromIsFollowingAccount(w http.ResponseWriter, r *http.Request) {}
|
||||||
|
|
Loading…
Reference in a new issue