From f23f04e0b1d117be714bf91d5266dab219ed741e Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Sat, 24 Aug 2024 11:49:37 +0200 Subject: [feature] Interaction requests client api + settings panel (#3215) * [feature] Interaction requests client api + settings panel * test accept / reject * fmt * don't pin rejected interaction * use single db model for interaction accept, reject, and request * swaggor * env sharting * append errors * remove ErrNoEntries checks * change intReqID to reqID * rename "pend" to "request" * markIntsPending -> mark interactionsPending * use log instead of returning error when rejecting interaction * empty migration * jolly renaming * make interactionURI unique again * swag grr * remove unnecessary locks * invalidate as last step --- testrig/db.go | 7 +++ testrig/testmodels.go | 55 ++++++++++++++++++++++ testrig/teststructs.go | 121 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 183 insertions(+) create mode 100644 testrig/teststructs.go (limited to 'testrig') diff --git a/testrig/db.go b/testrig/db.go index e6b40c846..92d963e89 100644 --- a/testrig/db.go +++ b/testrig/db.go @@ -41,6 +41,7 @@ var testModels = []interface{}{ >smodel.FilterStatus{}, >smodel.Follow{}, >smodel.FollowRequest{}, + >smodel.InteractionRequest{}, >smodel.List{}, >smodel.ListEntry{}, >smodel.Marker{}, @@ -346,6 +347,12 @@ func StandardDBSetup(db db.DB, accounts map[string]*gtsmodel.Account) { } } + for _, v := range NewTestInteractionRequests() { + if err := db.Put(ctx, v); err != nil { + log.Panic(nil, err) + } + } + if err := db.CreateInstanceAccount(ctx); err != nil { log.Panic(nil, err) } diff --git a/testrig/testmodels.go b/testrig/testmodels.go index 3cf785908..943fb7396 100644 --- a/testrig/testmodels.go +++ b/testrig/testmodels.go @@ -1509,6 +1509,31 @@ func NewTestStatuses() map[string]*gtsmodel.Status { ActivityStreamsType: ap.ObjectNote, PendingApproval: util.Ptr(false), }, + "admin_account_status_5": { + ID: "01J5QVB9VC76NPPRQ207GG4DRZ", + URI: "http://localhost:8080/users/admin/statuses/01J5QVB9VC76NPPRQ207GG4DRZ", + URL: "http://localhost:8080/@admin/statuses/01J5QVB9VC76NPPRQ207GG4DRZ", + Content: `

Hi @1happyturtle, can I reply?

`, + Text: "Hi @1happyturtle, can I reply?", + CreatedAt: TimeMustParse("2024-02-20T12:41:37+02:00"), + UpdatedAt: TimeMustParse("2024-02-20T12:41:37+02:00"), + Local: util.Ptr(true), + AccountURI: "http://localhost:8080/users/admin", + MentionIDs: []string{"01J5QVP69ANF1K4WHES6GA4WXP"}, + AccountID: "01F8MH17FWEB39HZJ76B6VXSKF", + InReplyToID: "01F8MHC8VWDRBQR0N1BATDDEM5", + InReplyToAccountID: "01F8MH5NBDF2MV7CTC4Q5128HF", + InReplyToURI: "http://localhost:8080/users/1happyturtle/statuses/01F8MHC8VWDRBQR0N1BATDDEM5", + BoostOfID: "", + BoostOfAccountID: "", + ThreadID: "01HCWE4P0EW9HBA5WHW97D5YV0", + Visibility: gtsmodel.VisibilityUnlocked, + Sensitive: util.Ptr(false), + CreatedWithApplicationID: "01F8MGXQRHYF5QPMTMXP78QC2F", + Federated: util.Ptr(true), + ActivityStreamsType: ap.ObjectNote, + PendingApproval: util.Ptr(true), + }, "local_account_1_status_1": { ID: "01F8MHAMCHF6Y650WCRSCP4WMY", URI: "http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY", @@ -2298,6 +2323,10 @@ func NewTestThreadToStatus() []*gtsmodel.ThreadToStatus { ThreadID: "01HCWE7ZNC2SS4P05WA5QYED23", StatusID: "01G20ZM733MGN8J344T4ZDDFY1", }, + { + ThreadID: "01HCWE4P0EW9HBA5WHW97D5YV0", + StatusID: "01J5QVB9VC76NPPRQ207GG4DRZ", + }, } } @@ -2352,6 +2381,18 @@ func NewTestMentions() map[string]*gtsmodel.Mention { TargetAccountURI: "http://localhost:8080/users/the_mighty_zork", TargetAccountURL: "http://localhost:8080/@the_mighty_zork", }, + "admin_account_mention_turtle": { + ID: "01J5QVP69ANF1K4WHES6GA4WXP", + StatusID: "01J5QVB9VC76NPPRQ207GG4DRZ", + CreatedAt: TimeMustParse("2024-02-20T12:41:37+02:00"), + UpdatedAt: TimeMustParse("2024-02-20T12:41:37+02:00"), + OriginAccountID: "01F8MH17FWEB39HZJ76B6VXSKF", + OriginAccountURI: "http://localhost:8080/users/admin", + TargetAccountID: "01F8MH5NBDF2MV7CTC4Q5128HF", + NameString: "@1happyturtle", + TargetAccountURI: "http://localhost:8080/users/1happyturtle", + TargetAccountURL: "http://localhost:8080/@1happyturtle", + }, "remote_account_2_mention_admin": { ID: "01HE7XQNMKTVC8MNPCE1JGK4J3", StatusID: "01HE7XJ1CG84TBKH5V9XKBVGF5", @@ -3430,6 +3471,20 @@ func NewTestUserMutes() map[string]*gtsmodel.UserMute { return map[string]*gtsmodel.UserMute{} } +func NewTestInteractionRequests() map[string]*gtsmodel.InteractionRequest { + return map[string]*gtsmodel.InteractionRequest{ + "admin_account_reply_turtle": { + ID: "01J5QVXCCEATJYSXM9H6MZT4JR", + CreatedAt: TimeMustParse("2024-02-20T12:41:37+02:00"), + StatusID: "01F8MHC8VWDRBQR0N1BATDDEM5", + TargetAccountID: "01F8MH5NBDF2MV7CTC4Q5128HF", + InteractingAccountID: "01F8MH17FWEB39HZJ76B6VXSKF", + InteractionURI: "http://localhost:8080/users/admin/statuses/01J5QVB9VC76NPPRQ207GG4DRZ", + InteractionType: gtsmodel.InteractionReply, + }, + } +} + // GetSignatureForActivity prepares a mock HTTP request as if it were going to deliver activity to destination signed for privkey and pubKeyID, signs the request and returns the header values. func GetSignatureForActivity(activity pub.Activity, pubKeyID string, privkey *rsa.PrivateKey, destination *url.URL) (signatureHeader string, digestHeader string, dateHeader string) { // convert the activity into json bytes diff --git a/testrig/teststructs.go b/testrig/teststructs.go new file mode 100644 index 000000000..b88e37d55 --- /dev/null +++ b/testrig/teststructs.go @@ -0,0 +1,121 @@ +// GoToSocial +// Copyright (C) GoToSocial Authors admin@gotosocial.org +// SPDX-License-Identifier: AGPL-3.0-or-later +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package testrig + +import ( + "github.com/superseriousbusiness/gotosocial/internal/cleaner" + "github.com/superseriousbusiness/gotosocial/internal/email" + "github.com/superseriousbusiness/gotosocial/internal/filter/interaction" + "github.com/superseriousbusiness/gotosocial/internal/filter/visibility" + "github.com/superseriousbusiness/gotosocial/internal/processing" + "github.com/superseriousbusiness/gotosocial/internal/processing/common" + "github.com/superseriousbusiness/gotosocial/internal/state" + "github.com/superseriousbusiness/gotosocial/internal/typeutils" +) + +// TestStructs encapsulates structs needed to +// run one test independently. Each test should +// call SetupTestStructs to get a new TestStructs, +// and defer TearDownTestStructs to close it when +// the test is complete. The reason for doing things +// this way here is to prevent the tests in a +// package from overwriting one another's processors +// and worker queues, which was causing issues +// when running all tests at once. +type TestStructs struct { + State *state.State + Common *common.Processor + Processor *processing.Processor + HTTPClient *MockHTTPClient + TypeConverter *typeutils.Converter + EmailSender email.Sender +} + +func SetupTestStructs( + rMediaPath string, + rTemplatePath string, +) *TestStructs { + state := state.State{} + + state.Caches.Init() + + db := NewTestDB(&state) + state.DB = db + + storage := NewInMemoryStorage() + state.Storage = storage + typeconverter := typeutils.NewConverter(&state) + visFilter := visibility.NewFilter(&state) + intFilter := interaction.NewFilter(&state) + + StartTimelines( + &state, + visFilter, + typeconverter, + ) + + httpClient := NewMockHTTPClient(nil, rMediaPath) + httpClient.TestRemotePeople = NewTestFediPeople() + httpClient.TestRemoteStatuses = NewTestFediStatuses() + + transportController := NewTestTransportController(&state, httpClient) + mediaManager := NewTestMediaManager(&state) + federator := NewTestFederator(&state, transportController, mediaManager) + oauthServer := NewTestOauthServer(db) + emailSender := NewEmailSender(rTemplatePath, nil) + + common := common.New( + &state, + mediaManager, + typeconverter, + federator, + visFilter, + ) + + processor := processing.NewProcessor( + cleaner.New(&state), + typeconverter, + federator, + oauthServer, + mediaManager, + &state, + emailSender, + visFilter, + intFilter, + ) + + StartWorkers(&state, processor.Workers()) + + StandardDBSetup(db, nil) + StandardStorageSetup(storage, rMediaPath) + + return &TestStructs{ + State: &state, + Common: &common, + Processor: processor, + HTTPClient: httpClient, + TypeConverter: typeconverter, + EmailSender: emailSender, + } +} + +func TearDownTestStructs(testStructs *TestStructs) { + StandardDBTeardown(testStructs.State.DB) + StandardStorageTeardown(testStructs.State.Storage) + StopWorkers(testStructs.State) +} -- cgit v1.3