Skip to content

Commit

Permalink
[bugfix] Fix new domain block date (#893)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmethurst authored Oct 6, 2022
1 parent f8528aa commit 5cf0f99
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
8 changes: 4 additions & 4 deletions internal/db/bundb/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func normalizeDomain(domain string) (out string, err error) {
return out, err
}

func (d *domainDB) CreateDomainBlock(ctx context.Context, block gtsmodel.DomainBlock) db.Error {
func (d *domainDB) CreateDomainBlock(ctx context.Context, block *gtsmodel.DomainBlock) db.Error {
domain, err := normalizeDomain(block.Domain)
if err != nil {
return err
Expand All @@ -56,13 +56,13 @@ func (d *domainDB) CreateDomainBlock(ctx context.Context, block gtsmodel.DomainB

// Attempt to insert new domain block
if _, err := d.conn.NewInsert().
Model(&block).
Exec(ctx, &block); err != nil {
Model(block).
Exec(ctx); err != nil {
return d.conn.ProcessError(err)
}

// Cache this domain block
d.cache.Put(block.Domain, &block)
d.cache.Put(block.Domain, block)

return nil
}
Expand Down
11 changes: 4 additions & 7 deletions internal/db/bundb/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,9 @@ type DomainTestSuite struct {
func (suite *DomainTestSuite) TestIsDomainBlocked() {
ctx := context.Background()

now := time.Now()

domainBlock := &gtsmodel.DomainBlock{
ID: "01G204214Y9TNJEBX39C7G88SW",
Domain: "some.bad.apples",
CreatedAt: now,
UpdatedAt: now,
CreatedByAccountID: suite.testAccounts["admin_account"].ID,
CreatedByAccount: suite.testAccounts["admin_account"],
}
Expand All @@ -50,13 +46,14 @@ func (suite *DomainTestSuite) TestIsDomainBlocked() {
suite.NoError(err)
suite.False(blocked)

err = suite.db.CreateDomainBlock(ctx, *domainBlock)
err = suite.db.CreateDomainBlock(ctx, domainBlock)
suite.NoError(err)

// domain block now exists
blocked, err = suite.db.IsDomainBlocked(ctx, domainBlock.Domain)
suite.NoError(err)
suite.True(blocked)
suite.WithinDuration(time.Now(), domainBlock.CreatedAt, 10*time.Second)
}

func (suite *DomainTestSuite) TestIsDomainBlockedNonASCII() {
Expand All @@ -82,7 +79,7 @@ func (suite *DomainTestSuite) TestIsDomainBlockedNonASCII() {
suite.NoError(err)
suite.False(blocked)

err = suite.db.CreateDomainBlock(ctx, *domainBlock)
err = suite.db.CreateDomainBlock(ctx, domainBlock)
suite.NoError(err)

// domain block now exists
Expand Down Expand Up @@ -118,7 +115,7 @@ func (suite *DomainTestSuite) TestIsDomainBlockedNonASCII2() {
suite.NoError(err)
suite.False(blocked)

err = suite.db.CreateDomainBlock(ctx, *domainBlock)
err = suite.db.CreateDomainBlock(ctx, domainBlock)
suite.NoError(err)

// domain block now exists
Expand Down
2 changes: 1 addition & 1 deletion internal/db/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
// Domain contains DB functions related to domains and domain blocks.
type Domain interface {
// CreateDomainBlock ...
CreateDomainBlock(ctx context.Context, block gtsmodel.DomainBlock) Error
CreateDomainBlock(ctx context.Context, block *gtsmodel.DomainBlock) Error

// GetDomainBlock ...
GetDomainBlock(ctx context.Context, domain string) (*gtsmodel.DomainBlock, Error)
Expand Down
4 changes: 2 additions & 2 deletions internal/processing/admin/createdomainblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (p *processor) DomainBlockCreate(ctx context.Context, account *gtsmodel.Acc
return nil, gtserror.NewErrorInternalError(fmt.Errorf("error creating id for new domain block %s: %s", domain, err))
}

newBlock := gtsmodel.DomainBlock{
newBlock := &gtsmodel.DomainBlock{
ID: blockID,
Domain: domain,
CreatedByAccountID: account.ID,
Expand All @@ -72,7 +72,7 @@ func (p *processor) DomainBlockCreate(ctx context.Context, account *gtsmodel.Acc
}

// Set the newly created block
block = &newBlock
block = newBlock

// Process the side effects of the domain block asynchronously since it might take a while
go func() {
Expand Down

0 comments on commit 5cf0f99

Please sign in to comment.