satellite/console: Update onboarding logic
A row in the new `user_settings` table does not always exist for a user, even if they have been around for a while. Since `user_settings` is now what defines the state of a user's onboarding flow, prior to this fix, even old users would receive the onboarding flow again. This change appropriately updates `user_settings` for users who already have projects, and thus have already gone through the onboarding flow. A brand new user will still be navigated to the beginning of onboarding. Change-Id: Ie745d280f6b8094ec60c200c2dca8d018d51f7d1
This commit is contained in:
parent
a1e920bbdf
commit
277612f4ff
@ -127,8 +127,8 @@ func TestAuth(t *testing.T) {
|
||||
OnboardingStep *string
|
||||
}{
|
||||
SessionDuration: nil,
|
||||
OnboardingStart: false,
|
||||
OnboardingEnd: false,
|
||||
OnboardingStart: true,
|
||||
OnboardingEnd: true,
|
||||
OnboardingStep: nil,
|
||||
})
|
||||
|
||||
|
@ -3254,7 +3254,23 @@ func (s *Service) GetUserSettings(ctx context.Context) (settings *UserSettings,
|
||||
if !errs.Is(err, sql.ErrNoRows) {
|
||||
return nil, Error.Wrap(err)
|
||||
}
|
||||
err = s.store.Users().UpsertSettings(ctx, user.ID, UpsertUserSettingsRequest{})
|
||||
|
||||
settingsReq := UpsertUserSettingsRequest{}
|
||||
// a user may have existed before a corresponding row was created in the user settings table
|
||||
// to avoid showing an old user the onboarding flow again, we check to see if the user owns any projects already
|
||||
// if so, set the "onboarding start" and "onboarding end" fields to "true"
|
||||
projects, err := s.store.Projects().GetOwn(ctx, user.ID)
|
||||
if err != nil {
|
||||
// we can still proceed with the settings upsert if there is an error retrieving projects, so log and don't return
|
||||
s.log.Warn("received error trying to get user's projects", zap.Error(err))
|
||||
}
|
||||
if len(projects) > 0 {
|
||||
t := true
|
||||
settingsReq.OnboardingStart = &(t)
|
||||
settingsReq.OnboardingEnd = &(t)
|
||||
}
|
||||
|
||||
err = s.store.Users().UpsertSettings(ctx, user.ID, settingsReq)
|
||||
if err != nil {
|
||||
return nil, Error.Wrap(err)
|
||||
}
|
||||
|
@ -1078,17 +1078,38 @@ func TestUserSettings(t *testing.T) {
|
||||
srv := sat.API.Console.Service
|
||||
userDB := sat.DB.Console().Users()
|
||||
|
||||
user, _, err := srv.GetUserByEmailWithUnverified(ctx, planet.Uplinks[0].User[sat.ID()].Email)
|
||||
existingUser, _, err := srv.GetUserByEmailWithUnverified(ctx, planet.Uplinks[0].User[sat.ID()].Email)
|
||||
require.NoError(t, err)
|
||||
|
||||
userCtx, err := sat.UserContext(ctx, user.ID)
|
||||
userCtx, err := sat.UserContext(ctx, existingUser.ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = userDB.GetSettings(userCtx, user.ID)
|
||||
_, err = userDB.GetSettings(userCtx, existingUser.ID)
|
||||
require.Error(t, err)
|
||||
|
||||
// a user that already has a project prior to getting user settings should not go through onboarding again
|
||||
// in other words, onboarding start and end should both be true for users who have a project
|
||||
settings, err := srv.GetUserSettings(userCtx)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, true, settings.OnboardingStart)
|
||||
require.Equal(t, true, settings.OnboardingEnd)
|
||||
require.Nil(t, settings.OnboardingStep)
|
||||
require.Nil(t, settings.SessionDuration)
|
||||
|
||||
newUser, err := userDB.Insert(ctx, &console.User{
|
||||
ID: testrand.UUID(),
|
||||
Email: "newuser@example.com",
|
||||
PasswordHash: []byte("i am a hash of a password, hello"),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
userCtx, err = sat.UserContext(ctx, newUser.ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
// a brand new user with no project should go through onboarding
|
||||
// in other words, onboarding start and end should both be false for users withouut a project
|
||||
settings, err = srv.GetUserSettings(userCtx)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, false, settings.OnboardingStart)
|
||||
require.Equal(t, false, settings.OnboardingEnd)
|
||||
require.Nil(t, settings.OnboardingStep)
|
||||
@ -1106,7 +1127,7 @@ func TestUserSettings(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
settings, err = userDB.GetSettings(userCtx, user.ID)
|
||||
settings, err = userDB.GetSettings(userCtx, newUser.ID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, onboardingBool, settings.OnboardingStart)
|
||||
require.Equal(t, onboardingBool, settings.OnboardingEnd)
|
||||
@ -1122,7 +1143,7 @@ func TestUserSettings(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
settings, err = userDB.GetSettings(userCtx, user.ID)
|
||||
settings, err = userDB.GetSettings(userCtx, newUser.ID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, onboardingBool, settings.OnboardingStart)
|
||||
require.Equal(t, onboardingBool, settings.OnboardingEnd)
|
||||
|
Loading…
Reference in New Issue
Block a user