mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-18 14:23:00 -06:00
domain blocky block block
This commit is contained in:
parent
72a2bef878
commit
6f20eaee75
16 changed files with 193 additions and 29 deletions
|
|
@ -54,7 +54,7 @@ func (p *processor) Delete(account *gtsmodel.Account, deletedBy string) error {
|
|||
"username": account.Username,
|
||||
})
|
||||
|
||||
l.Debug("beginning account delete process")
|
||||
l.Debugf("beginning account delete process for username %s", account.Username)
|
||||
|
||||
// 1. Delete account's application(s), clients, and oauth tokens
|
||||
// we only need to do this step for local account since remote ones won't have any tokens or applications on our server
|
||||
|
|
@ -85,6 +85,7 @@ func (p *processor) Delete(account *gtsmodel.Account, deletedBy string) error {
|
|||
}
|
||||
|
||||
// 2. Delete account's blocks
|
||||
l.Debug("deleting account blocks")
|
||||
// first delete any blocks that this account created
|
||||
if err := p.db.DeleteWhere([]db.Where{{Key: "account_id", Value: account.ID}}, &[]*gtsmodel.Block{}); err != nil {
|
||||
l.Errorf("error deleting blocks created by account: %s", err)
|
||||
|
|
@ -99,6 +100,7 @@ func (p *processor) Delete(account *gtsmodel.Account, deletedBy string) error {
|
|||
// nothing to do here
|
||||
|
||||
// 4. Delete account's follow requests
|
||||
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 {
|
||||
l.Errorf("error deleting follow requests created by account: %s", err)
|
||||
|
|
@ -110,6 +112,7 @@ func (p *processor) Delete(account *gtsmodel.Account, deletedBy string) error {
|
|||
}
|
||||
|
||||
// 5. Delete account's follows
|
||||
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 {
|
||||
l.Errorf("error deleting follows created by account: %s", err)
|
||||
|
|
@ -121,6 +124,7 @@ func (p *processor) Delete(account *gtsmodel.Account, deletedBy string) error {
|
|||
}
|
||||
|
||||
// 6. Delete account's statuses
|
||||
l.Debug("deleting account 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.
|
||||
|
|
@ -130,7 +134,7 @@ selectStatusesLoop:
|
|||
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
|
||||
// no statuses left for this instance so we're done
|
||||
l.Infof("Delete: done iterating through statuses for account %s", account.Username)
|
||||
break selectStatusesLoop
|
||||
}
|
||||
|
|
@ -142,6 +146,7 @@ selectStatusesLoop:
|
|||
for i, s := range statuses {
|
||||
// pass the status delete through the client api channel for processing
|
||||
s.GTSAuthorAccount = account
|
||||
l.Debug("putting status in the client api channel")
|
||||
p.fromClientAPI <- gtsmodel.FromClientAPI{
|
||||
APObjectType: gtsmodel.ActivityStreamsNote,
|
||||
APActivityType: gtsmodel.ActivityStreamsDelete,
|
||||
|
|
@ -158,29 +163,67 @@ selectStatusesLoop:
|
|||
}
|
||||
}
|
||||
|
||||
// if there are any boosts of this status, delete them as well
|
||||
boosts := []*gtsmodel.Status{}
|
||||
if err := p.db.GetWhere([]db.Where{{Key: "boost_of_id", Value: s.ID}}, &boosts); err != nil {
|
||||
if _, ok := err.(db.ErrNoEntries); !ok {
|
||||
// an actual error has occurred
|
||||
l.Errorf("Delete: db error selecting boosts of status %s for account %s: %s", s.ID, account.Username, err)
|
||||
break selectStatusesLoop
|
||||
}
|
||||
}
|
||||
|
||||
for _, b := range boosts {
|
||||
oa := >smodel.Account{}
|
||||
if err := p.db.GetByID(b.AccountID, oa); err == nil {
|
||||
|
||||
l.Debug("putting boost undo in the client api channel")
|
||||
p.fromClientAPI <- gtsmodel.FromClientAPI{
|
||||
APObjectType: gtsmodel.ActivityStreamsAnnounce,
|
||||
APActivityType: gtsmodel.ActivityStreamsUndo,
|
||||
GTSModel: s,
|
||||
OriginAccount: oa,
|
||||
TargetAccount: account,
|
||||
}
|
||||
}
|
||||
|
||||
if err := p.db.DeleteByID(b.ID, b); err != nil {
|
||||
if _, ok := err.(db.ErrNoEntries); !ok {
|
||||
// actual error has occurred
|
||||
l.Errorf("Delete: db error deleting boost with id %s: %s", b.ID, 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
|
||||
}
|
||||
}
|
||||
}
|
||||
l.Debug("done deleting statuses")
|
||||
|
||||
// 10. Delete account's notifications
|
||||
l.Debug("deleting account 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)
|
||||
}
|
||||
|
||||
// 11. Delete account's bookmarks
|
||||
l.Debug("deleting account bookmarks")
|
||||
if err := p.db.DeleteWhere([]db.Where{{Key: "account_id", Value: account.ID}}, &[]*gtsmodel.StatusBookmark{}); err != nil {
|
||||
l.Errorf("error deleting bookmarks created by account: %s", err)
|
||||
}
|
||||
|
||||
// 12. Delete account's faves
|
||||
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)
|
||||
}
|
||||
|
||||
// 13. Delete account's mutes
|
||||
l.Debug("deleting account mutes")
|
||||
if err := p.db.DeleteWhere([]db.Where{{Key: "account_id", Value: account.ID}}, &[]*gtsmodel.StatusMute{}); err != nil {
|
||||
l.Errorf("error deleting status mutes created by account: %s", err)
|
||||
}
|
||||
|
|
@ -191,6 +234,7 @@ selectStatusesLoop:
|
|||
// TODO
|
||||
|
||||
// 16. Delete account's user
|
||||
l.Debug("deleting account user")
|
||||
if err := p.db.DeleteWhere([]db.Where{{Key: "account_id", Value: account.ID}}, >smodel.User{}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -217,5 +261,10 @@ selectStatusesLoop:
|
|||
account.SuspendedAt = time.Now()
|
||||
account.SuspensionOrigin = deletedBy
|
||||
|
||||
return p.db.UpdateByID(account.ID, account)
|
||||
if err := p.db.UpdateByID(account.ID, account); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
l.Infof("deleted account with username %s from domain %s", account.Username, account.Domain)
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,10 +47,7 @@ func (p *processor) StatusesGet(requestingAccount *gtsmodel.Account, targetAccou
|
|||
|
||||
for _, s := range statuses {
|
||||
visible, err := p.filter.StatusVisible(s, requestingAccount)
|
||||
if err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(fmt.Errorf("error checking status visibility: %s", err))
|
||||
}
|
||||
if !visible {
|
||||
if err != nil || !visible {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,3 +31,7 @@ func (p *processor) AdminEmojiCreate(authed *oauth.Auth, form *apimodel.EmojiCre
|
|||
func (p *processor) AdminDomainBlockCreate(authed *oauth.Auth, form *apimodel.DomainBlockCreateRequest) (*apimodel.DomainBlock, gtserror.WithCode) {
|
||||
return p.adminProcessor.DomainBlockCreate(authed.Account, form)
|
||||
}
|
||||
|
||||
func (p *processor) AdminDomainBlocksGet(authed *oauth.Auth, export bool) ([]*apimodel.DomainBlock, gtserror.WithCode) {
|
||||
return p.adminProcessor.DomainBlocksGet(authed.Account, export)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import (
|
|||
// Processor wraps a bunch of functions for processing admin actions.
|
||||
type Processor interface {
|
||||
DomainBlockCreate(account *gtsmodel.Account, form *apimodel.DomainBlockCreateRequest) (*apimodel.DomainBlock, gtserror.WithCode)
|
||||
DomainBlocksGet(account *gtsmodel.Account, export bool) ([]*apimodel.DomainBlock, gtserror.WithCode)
|
||||
EmojiCreate(account *gtsmodel.Account, user *gtsmodel.User, form *apimodel.EmojiCreateRequest) (*apimodel.Emoji, error)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,10 +65,10 @@ func (p *processor) DomainBlockCreate(account *gtsmodel.Account, form *apimodel.
|
|||
}
|
||||
|
||||
// process the side effects of the domain block asynchronously since it might take a while
|
||||
go p.initiateDomainBlockSideEffects(domainBlock) // TODO: add this to a queuing system so it can retry/resume
|
||||
go p.initiateDomainBlockSideEffects(account, domainBlock) // TODO: add this to a queuing system so it can retry/resume
|
||||
}
|
||||
|
||||
mastoDomainBlock, err := p.tc.DomainBlockToMasto(domainBlock)
|
||||
mastoDomainBlock, err := p.tc.DomainBlockToMasto(domainBlock, false)
|
||||
if err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(fmt.Errorf("DomainBlockCreate: error converting domain block to frontend/masto representation %s: %s", form.Domain, err))
|
||||
}
|
||||
|
|
@ -81,7 +81,7 @@ func (p *processor) DomainBlockCreate(account *gtsmodel.Account, form *apimodel.
|
|||
// 1. Strip most info away from the instance entry for the domain.
|
||||
// 2. Delete the instance account for that instance if it exists.
|
||||
// 3. Select all accounts from this instance and pass them through the delete functionality of the processor.
|
||||
func (p *processor) initiateDomainBlockSideEffects(block *gtsmodel.DomainBlock) {
|
||||
func (p *processor) initiateDomainBlockSideEffects(account *gtsmodel.Account, block *gtsmodel.DomainBlock) {
|
||||
l := p.log.WithFields(logrus.Fields{
|
||||
"func": "domainBlockProcessSideEffects",
|
||||
"domain": block.Domain,
|
||||
|
|
@ -134,12 +134,14 @@ selectAccountsLoop:
|
|||
}
|
||||
|
||||
for i, a := range accounts {
|
||||
l.Debugf("putting delete for account %s in the clientAPI channel", a.Username)
|
||||
|
||||
// pass the account delete through the client api channel for processing
|
||||
p.fromClientAPI <- gtsmodel.FromClientAPI{
|
||||
APObjectType: gtsmodel.ActivityStreamsPerson,
|
||||
APActivityType: gtsmodel.ActivityStreamsDelete,
|
||||
GTSModel: a,
|
||||
OriginAccount: a,
|
||||
OriginAccount: account,
|
||||
TargetAccount: a,
|
||||
}
|
||||
|
||||
30
internal/processing/admin/getdomainblocks.go
Normal file
30
internal/processing/admin/getdomainblocks.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package admin
|
||||
|
||||
import (
|
||||
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
)
|
||||
|
||||
func (p *processor) DomainBlocksGet(account *gtsmodel.Account, export bool) ([]*apimodel.DomainBlock, gtserror.WithCode) {
|
||||
domainBlocks := []*gtsmodel.DomainBlock{}
|
||||
|
||||
if err := p.db.GetAll(&domainBlocks); err != nil {
|
||||
if _, ok := err.(db.ErrNoEntries); !ok {
|
||||
// something has gone really wrong
|
||||
return nil, gtserror.NewErrorInternalError(err)
|
||||
}
|
||||
}
|
||||
|
||||
mastoDomainBlocks := []*apimodel.DomainBlock{}
|
||||
for _, b := range domainBlocks {
|
||||
mastoDomainBlock, err := p.tc.DomainBlockToMasto(b, export)
|
||||
if err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(err)
|
||||
}
|
||||
mastoDomainBlocks = append(mastoDomainBlocks, mastoDomainBlock)
|
||||
}
|
||||
|
||||
return mastoDomainBlocks, nil
|
||||
}
|
||||
|
|
@ -185,7 +185,6 @@ func (p *processor) processFromClientAPI(clientMsg gtsmodel.FromClientAPI) error
|
|||
return err
|
||||
}
|
||||
|
||||
|
||||
// delete this status from any and all timelines
|
||||
if err := p.deleteStatusFromTimelines(statusToDelete); err != nil {
|
||||
return err
|
||||
|
|
@ -393,6 +392,11 @@ func (p *processor) federateUnfave(fave *gtsmodel.StatusFave, originAccount *gts
|
|||
}
|
||||
|
||||
func (p *processor) federateUnannounce(boost *gtsmodel.Status, originAccount *gtsmodel.Account, targetAccount *gtsmodel.Account) error {
|
||||
if originAccount.Domain != "" {
|
||||
// nothing to do here
|
||||
return nil
|
||||
}
|
||||
|
||||
asAnnounce, err := p.tc.BoostToAS(boost, originAccount, targetAccount)
|
||||
if err != nil {
|
||||
return fmt.Errorf("federateUnannounce: error converting status to announce: %s", err)
|
||||
|
|
|
|||
|
|
@ -87,6 +87,8 @@ type Processor interface {
|
|||
AdminEmojiCreate(authed *oauth.Auth, form *apimodel.EmojiCreateRequest) (*apimodel.Emoji, error)
|
||||
// AdminDomainBlockCreate handles the creation of a new domain block by an admin, using the given form.
|
||||
AdminDomainBlockCreate(authed *oauth.Auth, form *apimodel.DomainBlockCreateRequest) (*apimodel.DomainBlock, gtserror.WithCode)
|
||||
// AdminDomainBlocksGet returns a list of currently blocked domains.
|
||||
AdminDomainBlocksGet(authed *oauth.Auth, export bool) ([]*apimodel.DomainBlock, gtserror.WithCode)
|
||||
|
||||
// AppCreate processes the creation of a new API application
|
||||
AppCreate(authed *oauth.Auth, form *apimodel.ApplicationCreateRequest) (*apimodel.Application, error)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue