mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[bugfix] Fix setting bot on/off (#3986)
* [bugfix] Fix setting bot on/off * read client messages in tests * test fix
This commit is contained in:
@@ -431,7 +431,7 @@ func (t AccountActorType) String() string {
|
|||||||
case AccountActorTypeService:
|
case AccountActorTypeService:
|
||||||
return "Service"
|
return "Service"
|
||||||
default:
|
default:
|
||||||
panic("invalid notification type")
|
panic("invalid actor type")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -77,8 +77,16 @@ func (p *Processor) Update(ctx context.Context, account *gtsmodel.Account, form
|
|||||||
acctColumns = append(acctColumns, "discoverable")
|
acctColumns = append(acctColumns, "discoverable")
|
||||||
}
|
}
|
||||||
|
|
||||||
if form.Bot != nil {
|
if bot := form.Bot; bot != nil {
|
||||||
account.ActorType = gtsmodel.AccountActorTypeService
|
if *bot {
|
||||||
|
// Mark account as an Application.
|
||||||
|
// See: https://www.w3.org/TR/activitystreams-vocabulary/#dfn-application
|
||||||
|
account.ActorType = gtsmodel.AccountActorTypeApplication
|
||||||
|
} else {
|
||||||
|
// Mark account as a Person.
|
||||||
|
// See: https://www.w3.org/TR/activitystreams-vocabulary/#dfn-person
|
||||||
|
account.ActorType = gtsmodel.AccountActorTypePerson
|
||||||
|
}
|
||||||
acctColumns = append(acctColumns, "actor_type")
|
acctColumns = append(acctColumns, "actor_type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
||||||
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AccountUpdateTestSuite struct {
|
type AccountUpdateTestSuite struct {
|
||||||
@@ -331,6 +332,64 @@ func (suite *AccountUpdateTestSuite) TestAccountUpdateNoteNotFields() {
|
|||||||
suite.Equal(fieldsBefore, len(dbAccount.Fields))
|
suite.Equal(fieldsBefore, len(dbAccount.Fields))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *AccountUpdateTestSuite) TestAccountUpdateBotNotBot() {
|
||||||
|
testAccount := >smodel.Account{}
|
||||||
|
*testAccount = *suite.testAccounts["local_account_1"]
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
// Call update function to set bot = true.
|
||||||
|
apiAccount, errWithCode := suite.accountProcessor.Update(
|
||||||
|
ctx,
|
||||||
|
testAccount,
|
||||||
|
&apimodel.UpdateCredentialsRequest{
|
||||||
|
Bot: util.Ptr(true),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if errWithCode != nil {
|
||||||
|
suite.FailNow(errWithCode.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returned profile should be updated.
|
||||||
|
suite.True(apiAccount.Bot)
|
||||||
|
|
||||||
|
// We should have an update in the client api channel.
|
||||||
|
msg, _ := suite.getClientMsg(5 * time.Second)
|
||||||
|
suite.NotNil(msg)
|
||||||
|
|
||||||
|
// Check database model of account as well.
|
||||||
|
dbAccount, err := suite.db.GetAccountByID(ctx, testAccount.ID)
|
||||||
|
if err != nil {
|
||||||
|
suite.FailNow(err.Error())
|
||||||
|
}
|
||||||
|
suite.True(dbAccount.ActorType.IsBot())
|
||||||
|
|
||||||
|
// Call update function to set bot = false.
|
||||||
|
apiAccount, errWithCode = suite.accountProcessor.Update(
|
||||||
|
ctx,
|
||||||
|
testAccount,
|
||||||
|
&apimodel.UpdateCredentialsRequest{
|
||||||
|
Bot: util.Ptr(false),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if errWithCode != nil {
|
||||||
|
suite.FailNow(errWithCode.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returned profile should be updated.
|
||||||
|
suite.False(apiAccount.Bot)
|
||||||
|
|
||||||
|
// We should have an update in the client api channel.
|
||||||
|
msg, _ = suite.getClientMsg(5 * time.Second)
|
||||||
|
suite.NotNil(msg)
|
||||||
|
|
||||||
|
// Check database model of account as well.
|
||||||
|
dbAccount, err = suite.db.GetAccountByID(ctx, testAccount.ID)
|
||||||
|
if err != nil {
|
||||||
|
suite.FailNow(err.Error())
|
||||||
|
}
|
||||||
|
suite.False(dbAccount.ActorType.IsBot())
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccountUpdateTestSuite(t *testing.T) {
|
func TestAccountUpdateTestSuite(t *testing.T) {
|
||||||
suite.Run(t, new(AccountUpdateTestSuite))
|
suite.Run(t, new(AccountUpdateTestSuite))
|
||||||
}
|
}
|
||||||
|
@@ -39,20 +39,32 @@ import (
|
|||||||
"github.com/superseriousbusiness/gotosocial/internal/util/xslices"
|
"github.com/superseriousbusiness/gotosocial/internal/util/xslices"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AccountToAS converts a gts model account
|
func accountableForActorType(actorType gtsmodel.AccountActorType) ap.Accountable {
|
||||||
// into an activity streams person or service.
|
switch actorType {
|
||||||
|
case gtsmodel.AccountActorTypeApplication:
|
||||||
|
return streams.NewActivityStreamsApplication()
|
||||||
|
case gtsmodel.AccountActorTypeGroup:
|
||||||
|
return streams.NewActivityStreamsGroup()
|
||||||
|
case gtsmodel.AccountActorTypeOrganization:
|
||||||
|
return streams.NewActivityStreamsOrganization()
|
||||||
|
case gtsmodel.AccountActorTypePerson:
|
||||||
|
return streams.NewActivityStreamsPerson()
|
||||||
|
case gtsmodel.AccountActorTypeService:
|
||||||
|
return streams.NewActivityStreamsService()
|
||||||
|
default:
|
||||||
|
panic("invalid actor type")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AccountToAS converts a gts model
|
||||||
|
// account into an accountable.
|
||||||
func (c *Converter) AccountToAS(
|
func (c *Converter) AccountToAS(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
a *gtsmodel.Account,
|
a *gtsmodel.Account,
|
||||||
) (ap.Accountable, error) {
|
) (ap.Accountable, error) {
|
||||||
// accountable is a service if this
|
// Use appropriate underlying
|
||||||
// is a bot account, otherwise a person.
|
// actor type of accountable.
|
||||||
var accountable ap.Accountable
|
accountable := accountableForActorType(a.ActorType)
|
||||||
if a.ActorType.IsBot() {
|
|
||||||
accountable = streams.NewActivityStreamsService()
|
|
||||||
} else {
|
|
||||||
accountable = streams.NewActivityStreamsPerson()
|
|
||||||
}
|
|
||||||
|
|
||||||
// id should be the activitypub URI of this user
|
// id should be the activitypub URI of this user
|
||||||
// something like https://example.org/users/example_user
|
// something like https://example.org/users/example_user
|
||||||
@@ -389,14 +401,9 @@ func (c *Converter) AccountToASMinimal(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
a *gtsmodel.Account,
|
a *gtsmodel.Account,
|
||||||
) (ap.Accountable, error) {
|
) (ap.Accountable, error) {
|
||||||
// accountable is a service if this
|
// Use appropriate underlying
|
||||||
// is a bot account, otherwise a person.
|
// actor type of accountable.
|
||||||
var accountable ap.Accountable
|
accountable := accountableForActorType(a.ActorType)
|
||||||
if a.ActorType.IsBot() {
|
|
||||||
accountable = streams.NewActivityStreamsService()
|
|
||||||
} else {
|
|
||||||
accountable = streams.NewActivityStreamsPerson()
|
|
||||||
}
|
|
||||||
|
|
||||||
// id should be the activitypub URI of this user
|
// id should be the activitypub URI of this user
|
||||||
// something like https://example.org/users/example_user
|
// something like https://example.org/users/example_user
|
||||||
|
@@ -99,7 +99,7 @@ func (suite *InternalToASTestSuite) TestAccountToASBot() {
|
|||||||
*testAccount = *suite.testAccounts["local_account_1"] // take zork for this test
|
*testAccount = *suite.testAccounts["local_account_1"] // take zork for this test
|
||||||
|
|
||||||
// Update zork to be a bot.
|
// Update zork to be a bot.
|
||||||
testAccount.ActorType = gtsmodel.AccountActorTypeService
|
testAccount.ActorType = gtsmodel.AccountActorTypeApplication
|
||||||
if err := suite.state.DB.UpdateAccount(context.Background(), testAccount); err != nil {
|
if err := suite.state.DB.UpdateAccount(context.Background(), testAccount); err != nil {
|
||||||
suite.FailNow(err.Error())
|
suite.FailNow(err.Error())
|
||||||
}
|
}
|
||||||
@@ -155,7 +155,7 @@ func (suite *InternalToASTestSuite) TestAccountToASBot() {
|
|||||||
"published": "2022-05-20T11:09:18Z",
|
"published": "2022-05-20T11:09:18Z",
|
||||||
"summary": "\u003cp\u003ehey yo this is my profile!\u003c/p\u003e",
|
"summary": "\u003cp\u003ehey yo this is my profile!\u003c/p\u003e",
|
||||||
"tag": [],
|
"tag": [],
|
||||||
"type": "Service",
|
"type": "Application",
|
||||||
"url": "http://localhost:8080/@the_mighty_zork"
|
"url": "http://localhost:8080/@the_mighty_zork"
|
||||||
}`, string(bytes))
|
}`, string(bytes))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user