From 0118e03cdaae5a378d6995cd1a49411a1132b8d7 Mon Sep 17 00:00:00 2001 From: Xavier Vello Date: Sat, 1 Mar 2025 11:37:40 +0100 Subject: [feature] Implement CSV import for mutes (#3696) * Implement CSV import for mutes * update swagger.yaml * update documentation * add ImportTestSuite.TestImportMutes * fix comment typo --- internal/api/client/import/import.go | 4 ++ internal/api/client/import/import_test.go | 92 +++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) (limited to 'internal/api/client') diff --git a/internal/api/client/import/import.go b/internal/api/client/import/import.go index c3908625b..8e2dde0c9 100644 --- a/internal/api/client/import/import.go +++ b/internal/api/client/import/import.go @@ -25,6 +25,7 @@ import ( "strings" "github.com/gin-gonic/gin" + apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util" "github.com/superseriousbusiness/gotosocial/internal/gtserror" @@ -38,6 +39,7 @@ const ( var types = []string{ "following", "blocks", + "mutes", } var modes = []string{ @@ -93,6 +95,8 @@ func (m *Module) Route(attachHandler func(method string, path string, f ...gin.H // // - `following` - accounts to follow. // - `blocks` - accounts to block. +// - `mutes` - accounts to mute. +// // type: string // required: true // - diff --git a/internal/api/client/import/import_test.go b/internal/api/client/import/import_test.go index fba83e1a3..56497d27d 100644 --- a/internal/api/client/import/import_test.go +++ b/internal/api/client/import/import_test.go @@ -26,6 +26,7 @@ import ( "testing" "github.com/stretchr/testify/suite" + importdata "github.com/superseriousbusiness/gotosocial/internal/api/client/import" "github.com/superseriousbusiness/gotosocial/internal/filter/visibility" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" @@ -206,6 +207,97 @@ admin@localhost:8080,true } } +func (suite *ImportTestSuite) TestImportMutes() { + var ( + ctx = context.Background() + testAccount = suite.testAccounts["local_account_1"] + ) + + // Clear existing mutes from Zork. + if err := suite.state.DB.DeleteAccountMutes(ctx, testAccount.ID); err != nil { + suite.FailNow(err.Error()) + } + + // Have zork mute turtle, admin and remote fossbro. + data := `Account address,Hide notifications +admin@localhost:8080,true +unknown@localhost:8080,true +1happyturtle@localhost:8080,false +foss_satan@fossbros-anonymous.io,true +` + + // Trigger the import handler. + suite.TriggerHandler(data, "mutes", "merge") + + // Wait for mutes to be applied + if !testrig.WaitFor(func() bool { + mutes, err := suite.state.DB.GetAccountMutes(ctx, testAccount.ID, nil) + if err != nil { + suite.FailNow(err.Error()) + } + for _, m := range mutes { + switch m.TargetAccount.ID { + case suite.testAccounts["remote_account_1"].ID: + if *m.Notifications != true { + suite.FailNow("expected notifications from fossbro to be muted") + } + case suite.testAccounts["admin_account"].ID: + if *m.Notifications != true { + suite.FailNow("expected notifications from admin to be muted") + } + case suite.testAccounts["local_account_2"].ID: + if *m.Notifications != false { + suite.FailNow("expected notifications from turtle to NOT be muted") + } + default: + suite.FailNow("unexpected muted account", m.TargetAccount) + } + } + return len(mutes) == 3 + }) { + suite.FailNow("timed out waiting for mutes to apply") + } + + // Import again in overwrite mode: + // - remote fossbro is unmuted, admin and turtle are kept + // - Notification hiding is reversed to confirm mutes are modified + data = `Account address,Hide notifications +admin@localhost:8080,false +1happyturtle@localhost:8080,true +` + + // Trigger the import handler. + suite.TriggerHandler(data, "mutes", "overwrite") + + // Wait for mutes to be applied + if !testrig.WaitFor(func() bool { + mutes, err := suite.state.DB.GetAccountMutes(ctx, testAccount.ID, nil) + if err != nil { + suite.FailNow(err.Error()) + } + for _, m := range mutes { + switch m.TargetAccount.ID { + case suite.testAccounts["remote_account_1"].ID: + suite.FailNow("fossbro is still muted") + case suite.testAccounts["admin_account"].ID: + if *m.Notifications != false { + suite.FailNow("expected notifications from admin to be NOT muted") + } + case suite.testAccounts["local_account_2"].ID: + if *m.Notifications != true { + suite.FailNow("expected notifications from turtle to be muted") + } + default: + suite.FailNow("unexpected muted account", m.TargetAccount) + } + } + return len(mutes) == 2 + }) { + suite.FailNow("timed out waiting for import to apply") + } + +} + func TestImportTestSuite(t *testing.T) { suite.Run(t, new(ImportTestSuite)) } -- cgit v1.2.3