feature (user service): Add a validation check after the user record is created in the sqlstore. (#59968)

Add a validation check after the user record is created in the sqlstore.
pull/59979/head^2
Kristin Laemmert 3 years ago committed by GitHub
parent 5c08f03512
commit ceb3d8d295
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      pkg/services/user/userimpl/store.go

@ -78,6 +78,12 @@ func (ss *sqlStore) Insert(ctx context.Context, cmd *user.User) (int64, error) {
if err != nil {
return 0, err
}
// verify that user was created and cmd.ID was updated with the actual new userID
_, err = ss.getAnyUserType(ctx, cmd.ID)
if err != nil {
return 0, err
}
return cmd.ID, nil
}
@ -683,3 +689,19 @@ func (ss *sqlStore) Search(ctx context.Context, query *user.SearchUsersQuery) (*
})
return &result, err
}
// getAnyUserType searches for a user record by ID. The user account may be a service account.
func (ss *sqlStore) getAnyUserType(ctx context.Context, userID int64) (*user.User, error) {
usr := user.User{ID: userID}
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
has, err := sess.Get(&usr)
if err != nil {
return err
}
if !has {
return user.ErrUserNotFound
}
return nil
})
return &usr, err
}

Loading…
Cancel
Save