mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-18 23:23:00 -06:00
delete more stuff when an account is gone
This commit is contained in:
parent
c2db321861
commit
80924744d1
20 changed files with 682 additions and 284 deletions
|
|
@ -40,7 +40,7 @@ type Processor interface {
|
|||
// Create processes the given form for creating a new account, returning an oauth token for that account if successful.
|
||||
Create(applicationToken oauth2.TokenInfo, application *gtsmodel.Application, form *apimodel.AccountCreateRequest) (*apimodel.Token, error)
|
||||
// Delete deletes an account, and all of that account's statuses, media, follows, notifications, etc etc etc.
|
||||
Delete(account *gtsmodel.Account) error
|
||||
Delete(account *gtsmodel.Account, deletedBy string) error
|
||||
// Get processes the given request for account information.
|
||||
Get(requestingAccount *gtsmodel.Account, targetAccountID string) (*apimodel.Account, error)
|
||||
// Update processes the update of an account with the given form
|
||||
|
|
|
|||
|
|
@ -19,13 +19,15 @@
|
|||
package account
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
||||
)
|
||||
|
||||
func (p *processor) Delete(account *gtsmodel.Account) error {
|
||||
func (p *processor) Delete(account *gtsmodel.Account, deletedBy string) error {
|
||||
l := p.log.WithFields(logrus.Fields{
|
||||
"func": "Delete",
|
||||
"username": account.Username,
|
||||
|
|
@ -39,11 +41,11 @@ func (p *processor) Delete(account *gtsmodel.Account) error {
|
|||
// 3. Delete account's emoji
|
||||
// 4. Delete account's follow requests
|
||||
// 5. Delete account's follows
|
||||
// 6. Delete account's media attachments
|
||||
// 7. Delete account's mentions
|
||||
// 8. Delete account's notifications
|
||||
// 6. Delete account's statuses
|
||||
// 7. Delete account's media attachments
|
||||
// 8. Delete account's mentions
|
||||
// 9. Delete account's polls
|
||||
// 10. Delete account's statuses
|
||||
// 10. Delete account's notifications
|
||||
// 11. Delete account's bookmarks
|
||||
// 12. Delete account's faves
|
||||
// 13. Delete account's mutes
|
||||
|
|
@ -117,5 +119,74 @@ func (p *processor) Delete(account *gtsmodel.Account) error {
|
|||
l.Errorf("error deleting follows targeting account: %s", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
// 6. Delete account's statuses
|
||||
// we'll select statuses 20 at a time so we don't wreck the db, and pass them through to the client api channel
|
||||
// Deleting the statuses in this way also handles 7. Delete account's media attachments, 8. Delete account's mentions, and 9. Delete account's polls,
|
||||
// since these are all attached to statuses.
|
||||
var maxID string
|
||||
selectStatusesLoop:
|
||||
for {
|
||||
statuses, err := p.db.GetStatusesForAccount(account.ID, 20, false, maxID, false, false)
|
||||
if err != nil {
|
||||
if _, ok := err.(db.ErrNoEntries); ok {
|
||||
// no accounts left for this instance so we're done
|
||||
l.Infof("Delete: done iterating through statuses for account %s", account.Username)
|
||||
break selectStatusesLoop
|
||||
}
|
||||
// an actual error has occurred
|
||||
l.Errorf("Delete: db error selecting statuses for account %s: %s", account.Username, err)
|
||||
break selectStatusesLoop
|
||||
}
|
||||
|
||||
for i, s := range statuses {
|
||||
// pass the status delete through the client api channel for processing
|
||||
s.GTSAuthorAccount = account
|
||||
p.fromClientAPI <- gtsmodel.FromClientAPI{
|
||||
APObjectType: gtsmodel.ActivityStreamsNote,
|
||||
APActivityType: gtsmodel.ActivityStreamsDelete,
|
||||
GTSModel: s,
|
||||
OriginAccount: account,
|
||||
TargetAccount: account,
|
||||
}
|
||||
|
||||
if err := p.db.DeleteByID(s.ID, s); err != nil {
|
||||
if _, ok := err.(db.ErrNoEntries); !ok {
|
||||
// actual error has occurred
|
||||
l.Errorf("Delete: db error status %s for account %s: %s", s.ID, account.Username, err)
|
||||
break selectStatusesLoop
|
||||
}
|
||||
}
|
||||
|
||||
// if this is the last status in the slice, set the maxID appropriately for the next query
|
||||
if i == len(statuses)-1 {
|
||||
maxID = s.ID
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 10. Delete account's notifications
|
||||
if err := p.db.DeleteWhere([]db.Where{{Key: "origin_account_id", Value: account.ID}}, &[]*gtsmodel.Notification{}); err != nil {
|
||||
l.Errorf("error deleting notifications created by account: %s", err)
|
||||
}
|
||||
|
||||
// to prevent the account being created again, set all these fields and update it in the db
|
||||
// the account won't actually be *removed* from the database but it will be set to just a stub
|
||||
|
||||
account.Note = ""
|
||||
account.DisplayName = ""
|
||||
account.AvatarMediaAttachmentID = ""
|
||||
account.AvatarRemoteURL = ""
|
||||
account.HeaderMediaAttachmentID = ""
|
||||
account.HeaderRemoteURL = ""
|
||||
account.Reason = ""
|
||||
account.Fields = []gtsmodel.Field{}
|
||||
account.HideCollections = true
|
||||
account.Discoverable = false
|
||||
|
||||
account.UpdatedAt = time.Now()
|
||||
|
||||
account.SuspendedAt = time.Now()
|
||||
account.SuspensionOrigin = deletedBy
|
||||
|
||||
return p.db.UpdateByID(account.ID, account)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import (
|
|||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
)
|
||||
|
||||
func (p *processor) StatusesGet(requestingAccount *gtsmodel.Account, targetAccountID string, limit int, excludeReplies bool, maxID string, pinned bool, mediaOnly bool) ([]apimodel.Status, gtserror.WithCode) {
|
||||
func (p *processor) StatusesGet(requestingAccount *gtsmodel.Account, targetAccountID string, limit int, excludeReplies bool, maxID string, pinnedOnly bool, mediaOnly bool) ([]apimodel.Status, gtserror.WithCode) {
|
||||
targetAccount := >smodel.Account{}
|
||||
if err := p.db.GetByID(targetAccountID, targetAccount); err != nil {
|
||||
if _, ok := err.(db.ErrNoEntries); ok {
|
||||
|
|
@ -36,9 +36,9 @@ func (p *processor) StatusesGet(requestingAccount *gtsmodel.Account, targetAccou
|
|||
return nil, gtserror.NewErrorInternalError(err)
|
||||
}
|
||||
|
||||
statuses := []gtsmodel.Status{}
|
||||
apiStatuses := []apimodel.Status{}
|
||||
if err := p.db.GetStatusesByTimeDescending(targetAccountID, &statuses, limit, excludeReplies, maxID, pinned, mediaOnly); err != nil {
|
||||
statuses, err := p.db.GetStatusesForAccount(targetAccountID, limit, excludeReplies, maxID, pinnedOnly, mediaOnly)
|
||||
if err != nil {
|
||||
if _, ok := err.(db.ErrNoEntries); ok {
|
||||
return apiStatuses, nil
|
||||
}
|
||||
|
|
@ -46,7 +46,7 @@ func (p *processor) StatusesGet(requestingAccount *gtsmodel.Account, targetAccou
|
|||
}
|
||||
|
||||
for _, s := range statuses {
|
||||
visible, err := p.filter.StatusVisible(&s, requestingAccount)
|
||||
visible, err := p.filter.StatusVisible(s, requestingAccount)
|
||||
if err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(fmt.Errorf("error checking status visibility: %s", err))
|
||||
}
|
||||
|
|
@ -54,7 +54,7 @@ func (p *processor) StatusesGet(requestingAccount *gtsmodel.Account, targetAccou
|
|||
continue
|
||||
}
|
||||
|
||||
apiStatus, err := p.tc.StatusToMasto(&s, requestingAccount)
|
||||
apiStatus, err := p.tc.StatusToMasto(s, requestingAccount)
|
||||
if err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status to masto: %s", err))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue