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
This commit is contained in:
Cameron 2022-02-09 18:57:15 -05:00 committed by Cameron Ayer
parent 0796653b07
commit eefef2eb17

View File

@ -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)
}