domain blocky block block

This commit is contained in:
tsmethurst 2021-07-02 15:52:16 +02:00
commit 6f20eaee75
16 changed files with 193 additions and 29 deletions

View file

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

View file

@ -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,
}

View 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
}