From eefef2eb17198b53071119806336ca48771783ac Mon Sep 17 00:00:00 2001 From: Cameron Date: Wed, 9 Feb 2022 18:57:15 -0500 Subject: [PATCH] satellite/console: pass entire auth.User into users.Update in service.UpdateAccount The Update method of the usersDB takes a console.User as an argument. To update the columns in the DB, we have to migrate the fields from the console.Users struct into a special dbx struct. If one of these fields is left empty, then the zero value of that field's type will be used to update the respective column. In most cases where the users.Update method is called, the entire console.User is apparently retrieved first, fields are updated, then it is passed to users.Update. This is not the case for service.UpdateAccount. Because these fields are not populated in the user struct in UpdateAccount before it is passed into users.Update, their respective columns in the database are overwritten with zero: ProjectLimit, ProjectStorageLimit, ProjectBandwidthLimit, ProjectSegmentLimit, PaidTier, MfaEnabled, MfaRecoveryCodes, MfaSecretKey Solution: Do what is done in other places which call users.Update. Take the console.User from the auth context, update the relevant fields on that, then pass that in. Change-Id: I3cbd560e8ea5397e5c27711fb40bb3907d987028 --- satellite/console/service.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/satellite/console/service.go b/satellite/console/service.go index 2233595a3..48b1369b7 100644 --- a/satellite/console/service.go +++ b/satellite/console/service.go @@ -950,14 +950,9 @@ func (s *Service) UpdateAccount(ctx context.Context, fullName string, shortName return ErrValidation.Wrap(err) } - err = s.store.Users().Update(ctx, &User{ - ID: auth.User.ID, - FullName: fullName, - ShortName: shortName, - Email: auth.User.Email, - PasswordHash: nil, - Status: auth.User.Status, - }) + auth.User.FullName = fullName + auth.User.ShortName = shortName + err = s.store.Users().Update(ctx, &auth.User) if err != nil { return Error.Wrap(err) }