unblock domains properly

This commit is contained in:
tsmethurst 2021-07-06 13:16:30 +02:00
commit e8f1c33b48
15 changed files with 316 additions and 130 deletions

View file

@ -40,7 +40,8 @@ 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, deletedBy string) error
// The origin passed here should be either the ID of the account doing the delete (can be itself), or the ID of a domain block.
Delete(account *gtsmodel.Account, origin 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

View file

@ -48,7 +48,7 @@ import (
// 16. Delete account's user
// 17. Delete account's timeline
// 18. Delete account itself
func (p *processor) Delete(account *gtsmodel.Account, deletedBy string) error {
func (p *processor) Delete(account *gtsmodel.Account, origin string) error {
l := p.log.WithFields(logrus.Fields{
"func": "Delete",
"username": account.Username,
@ -100,6 +100,7 @@ func (p *processor) Delete(account *gtsmodel.Account, deletedBy string) error {
// nothing to do here
// 4. Delete account's follow requests
// TODO: federate these if necessary
l.Debug("deleting account follow requests")
// first delete any follow requests that this account created
if err := p.db.DeleteWhere([]db.Where{{Key: "account_id", Value: account.ID}}, &[]*gtsmodel.FollowRequest{}); err != nil {
@ -112,6 +113,7 @@ func (p *processor) Delete(account *gtsmodel.Account, deletedBy string) error {
}
// 5. Delete account's follows
// TODO: federate these if necessary
l.Debug("deleting account follows")
// first delete any follows that this account created
if err := p.db.DeleteWhere([]db.Where{{Key: "account_id", Value: account.ID}}, &[]*gtsmodel.Follow{}); err != nil {
@ -217,6 +219,7 @@ selectStatusesLoop:
}
// 12. Delete account's faves
// TODO: federate these if necessary
l.Debug("deleting account faves")
if err := p.db.DeleteWhere([]db.Where{{Key: "account_id", Value: account.ID}}, &[]*gtsmodel.StatusFave{}); err != nil {
l.Errorf("error deleting faves created by account: %s", err)
@ -229,6 +232,7 @@ selectStatusesLoop:
}
// 14. Delete account's streams
// TODO
// 15. Delete account's tags
// TODO
@ -240,6 +244,7 @@ selectStatusesLoop:
}
// 17. Delete account's timeline
// TODO
// 18. Delete account itself
// to prevent the account being created again, set all these fields and update it in the db
@ -259,7 +264,7 @@ selectStatusesLoop:
account.UpdatedAt = time.Now()
account.SuspendedAt = time.Now()
account.SuspensionOrigin = deletedBy
account.SuspensionOrigin = origin
if err := p.db.UpdateByID(account.ID, account); err != nil {
return err

View file

@ -33,7 +33,7 @@ func (p *processor) AdminDomainBlockCreate(authed *oauth.Auth, form *apimodel.Do
}
func (p *processor) AdminDomainBlocksImport(authed *oauth.Auth, form *apimodel.DomainBlockCreateRequest) ([]*apimodel.DomainBlock, gtserror.WithCode) {
return p.adminProcessor.DomainBlocksImport(authed.Account, form.Domains)
return p.adminProcessor.DomainBlocksImport(authed.Account, form.Domains)
}
func (p *processor) AdminDomainBlocksGet(authed *oauth.Auth, export bool) ([]*apimodel.DomainBlock, gtserror.WithCode) {

View file

@ -54,6 +54,7 @@ func (p *processor) DomainBlockCreate(account *gtsmodel.Account, domain string,
PrivateComment: privateComment,
PublicComment: publicComment,
Obfuscate: obfuscate,
SubscriptionID: subscriptionID,
}
// put the new block in the database
@ -140,7 +141,7 @@ selectAccountsLoop:
p.fromClientAPI <- gtsmodel.FromClientAPI{
APObjectType: gtsmodel.ActivityStreamsPerson,
APActivityType: gtsmodel.ActivityStreamsDelete,
GTSModel: a,
GTSModel: block,
OriginAccount: account,
TargetAccount: a,
}

View file

@ -64,5 +64,20 @@ func (p *processor) DomainBlockDelete(account *gtsmodel.Account, id string) (*ap
}
}
// unsuspend all accounts whose suspension origin was this domain block
// 1. remove the 'suspended_at' entry from their accounts
if err := p.db.UpdateWhere([]db.Where{
{Key: "suspension_origin", Value: domainBlock.ID},
}, "suspended_at", nil, &[]*gtsmodel.Account{}); err != nil {
return nil, gtserror.NewErrorInternalError(fmt.Errorf("database error removing suspended_at from accounts: %s", err))
}
// 2. remove the 'suspension_origin' entry from their accounts
if err := p.db.UpdateWhere([]db.Where{
{Key: "suspension_origin", Value: domainBlock.ID},
}, "suspension_origin", nil, &[]*gtsmodel.Account{}); err != nil {
return nil, gtserror.NewErrorInternalError(fmt.Errorf("database error removing suspension_origin from accounts: %s", err))
}
return mastoDomainBlock, nil
}

View file

@ -193,17 +193,17 @@ func (p *processor) processFromClientAPI(clientMsg gtsmodel.FromClientAPI) error
return p.federateStatusDelete(statusToDelete)
case gtsmodel.ActivityStreamsProfile, gtsmodel.ActivityStreamsPerson:
// DELETE ACCOUNT/PROFILE
accountToDelete, ok := clientMsg.GTSModel.(*gtsmodel.Account)
if !ok {
return errors.New("account was not parseable as *gtsmodel.Account")
}
var deletedBy string
if clientMsg.OriginAccount != nil {
deletedBy = clientMsg.OriginAccount.ID
// the origin of the delete could be either a domain block, or an action by another (or this) account
var origin string
if domainBlock, ok := clientMsg.GTSModel.(*gtsmodel.DomainBlock); ok {
// origin is a domain block
origin = domainBlock.ID
} else {
// origin is whichever account caused this message
origin = clientMsg.OriginAccount.ID
}
return p.accountProcessor.Delete(accountToDelete, deletedBy)
return p.accountProcessor.Delete(clientMsg.TargetAccount, origin)
}
}
return nil