mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-10 11:19:50 +00:00
[bugfix] Fix new domain block date (#893)
This commit is contained in:
parent
f8528aa689
commit
5cf0f9950a
4 changed files with 11 additions and 14 deletions
|
@ -47,7 +47,7 @@ func normalizeDomain(domain string) (out string, err error) {
|
||||||
return out, err
|
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)
|
domain, err := normalizeDomain(block.Domain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -56,13 +56,13 @@ func (d *domainDB) CreateDomainBlock(ctx context.Context, block gtsmodel.DomainB
|
||||||
|
|
||||||
// Attempt to insert new domain block
|
// Attempt to insert new domain block
|
||||||
if _, err := d.conn.NewInsert().
|
if _, err := d.conn.NewInsert().
|
||||||
Model(&block).
|
Model(block).
|
||||||
Exec(ctx, &block); err != nil {
|
Exec(ctx); err != nil {
|
||||||
return d.conn.ProcessError(err)
|
return d.conn.ProcessError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache this domain block
|
// Cache this domain block
|
||||||
d.cache.Put(block.Domain, &block)
|
d.cache.Put(block.Domain, block)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,13 +34,9 @@ type DomainTestSuite struct {
|
||||||
func (suite *DomainTestSuite) TestIsDomainBlocked() {
|
func (suite *DomainTestSuite) TestIsDomainBlocked() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
now := time.Now()
|
|
||||||
|
|
||||||
domainBlock := >smodel.DomainBlock{
|
domainBlock := >smodel.DomainBlock{
|
||||||
ID: "01G204214Y9TNJEBX39C7G88SW",
|
ID: "01G204214Y9TNJEBX39C7G88SW",
|
||||||
Domain: "some.bad.apples",
|
Domain: "some.bad.apples",
|
||||||
CreatedAt: now,
|
|
||||||
UpdatedAt: now,
|
|
||||||
CreatedByAccountID: suite.testAccounts["admin_account"].ID,
|
CreatedByAccountID: suite.testAccounts["admin_account"].ID,
|
||||||
CreatedByAccount: suite.testAccounts["admin_account"],
|
CreatedByAccount: suite.testAccounts["admin_account"],
|
||||||
}
|
}
|
||||||
|
@ -50,13 +46,14 @@ func (suite *DomainTestSuite) TestIsDomainBlocked() {
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
suite.False(blocked)
|
suite.False(blocked)
|
||||||
|
|
||||||
err = suite.db.CreateDomainBlock(ctx, *domainBlock)
|
err = suite.db.CreateDomainBlock(ctx, domainBlock)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
// domain block now exists
|
// domain block now exists
|
||||||
blocked, err = suite.db.IsDomainBlocked(ctx, domainBlock.Domain)
|
blocked, err = suite.db.IsDomainBlocked(ctx, domainBlock.Domain)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
suite.True(blocked)
|
suite.True(blocked)
|
||||||
|
suite.WithinDuration(time.Now(), domainBlock.CreatedAt, 10*time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *DomainTestSuite) TestIsDomainBlockedNonASCII() {
|
func (suite *DomainTestSuite) TestIsDomainBlockedNonASCII() {
|
||||||
|
@ -82,7 +79,7 @@ func (suite *DomainTestSuite) TestIsDomainBlockedNonASCII() {
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
suite.False(blocked)
|
suite.False(blocked)
|
||||||
|
|
||||||
err = suite.db.CreateDomainBlock(ctx, *domainBlock)
|
err = suite.db.CreateDomainBlock(ctx, domainBlock)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
// domain block now exists
|
// domain block now exists
|
||||||
|
@ -118,7 +115,7 @@ func (suite *DomainTestSuite) TestIsDomainBlockedNonASCII2() {
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
suite.False(blocked)
|
suite.False(blocked)
|
||||||
|
|
||||||
err = suite.db.CreateDomainBlock(ctx, *domainBlock)
|
err = suite.db.CreateDomainBlock(ctx, domainBlock)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
// domain block now exists
|
// domain block now exists
|
||||||
|
|
|
@ -28,7 +28,7 @@ import (
|
||||||
// Domain contains DB functions related to domains and domain blocks.
|
// Domain contains DB functions related to domains and domain blocks.
|
||||||
type Domain interface {
|
type Domain interface {
|
||||||
// CreateDomainBlock ...
|
// CreateDomainBlock ...
|
||||||
CreateDomainBlock(ctx context.Context, block gtsmodel.DomainBlock) Error
|
CreateDomainBlock(ctx context.Context, block *gtsmodel.DomainBlock) Error
|
||||||
|
|
||||||
// GetDomainBlock ...
|
// GetDomainBlock ...
|
||||||
GetDomainBlock(ctx context.Context, domain string) (*gtsmodel.DomainBlock, Error)
|
GetDomainBlock(ctx context.Context, domain string) (*gtsmodel.DomainBlock, Error)
|
||||||
|
|
|
@ -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))
|
return nil, gtserror.NewErrorInternalError(fmt.Errorf("error creating id for new domain block %s: %s", domain, err))
|
||||||
}
|
}
|
||||||
|
|
||||||
newBlock := gtsmodel.DomainBlock{
|
newBlock := >smodel.DomainBlock{
|
||||||
ID: blockID,
|
ID: blockID,
|
||||||
Domain: domain,
|
Domain: domain,
|
||||||
CreatedByAccountID: account.ID,
|
CreatedByAccountID: account.ID,
|
||||||
|
@ -72,7 +72,7 @@ func (p *processor) DomainBlockCreate(ctx context.Context, account *gtsmodel.Acc
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the newly created block
|
// Set the newly created block
|
||||||
block = &newBlock
|
block = newBlock
|
||||||
|
|
||||||
// Process the side effects of the domain block asynchronously since it might take a while
|
// Process the side effects of the domain block asynchronously since it might take a while
|
||||||
go func() {
|
go func() {
|
||||||
|
|
Loading…
Reference in a new issue