From b5a7e1ba323a2493873dedf3a3835c2e9564cb24 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Tue, 28 Sep 2021 15:21:59 +0200 Subject: Account update issue (#250) * start poking around * tests * notes and fiddling --- .../federation/federatingdb/federating_db_test.go | 21 --------------------- .../federation/federatingdb/federatingdb_test.go | 21 +++++++++++++++++++++ internal/federation/federatingdb/update.go | 12 ++++++++---- 3 files changed, 29 insertions(+), 25 deletions(-) delete mode 100644 internal/federation/federatingdb/federating_db_test.go create mode 100644 internal/federation/federatingdb/federatingdb_test.go (limited to 'internal/federation') diff --git a/internal/federation/federatingdb/federating_db_test.go b/internal/federation/federatingdb/federating_db_test.go deleted file mode 100644 index f32314b10..000000000 --- a/internal/federation/federatingdb/federating_db_test.go +++ /dev/null @@ -1,21 +0,0 @@ -/* - GoToSocial - Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org - - 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 federatingdb_test - -// TODO: write tests for pgfed diff --git a/internal/federation/federatingdb/federatingdb_test.go b/internal/federation/federatingdb/federatingdb_test.go new file mode 100644 index 000000000..f32314b10 --- /dev/null +++ b/internal/federation/federatingdb/federatingdb_test.go @@ -0,0 +1,21 @@ +/* + GoToSocial + Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org + + 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 federatingdb_test + +// TODO: write tests for pgfed diff --git a/internal/federation/federatingdb/update.go b/internal/federation/federatingdb/update.go index 2bcf2533c..5dec2bd69 100644 --- a/internal/federation/federatingdb/update.go +++ b/internal/federation/federatingdb/update.go @@ -98,8 +98,7 @@ func (f *federatingDB) Update(ctx context.Context, asType vocab.Type) error { typeName == ap.ActorService { // it's an UPDATE to some kind of account var accountable ap.Accountable - - switch asType.GetTypeName() { + switch typeName { case ap.ActorApplication: l.Debug("got update for APPLICATION") i, ok := asType.(vocab.ActivityStreamsApplication) @@ -152,19 +151,24 @@ func (f *federatingDB) Update(ctx context.Context, asType vocab.Type) error { return fmt.Errorf("UPDATE: update for account %s was requested by account %s, this is not valid", updatedAcct.URI, requestingAcct.URI) } - updatedAcct.ID = requestingAcct.ID // set this here so the db will update properly instead of trying to PUT this and getting constraint issues + // set some fields here on the updatedAccount representation so we don't run into db issues + updatedAcct.CreatedAt = requestingAcct.CreatedAt + updatedAcct.ID = requestingAcct.ID + updatedAcct.Language = requestingAcct.Language + + // do the update updatedAcct, err = f.db.UpdateAccount(ctx, updatedAcct) if err != nil { return fmt.Errorf("UPDATE: database error inserting updated account: %s", err) } + // pass to the processor for further processing of eg., avatar/header fromFederatorChan <- messages.FromFederator{ APObjectType: ap.ObjectProfile, APActivityType: ap.ActivityUpdate, GTSModel: updatedAcct, ReceivingAccount: targetAcct, } - } return nil -- cgit v1.3