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.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user