mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-02-14 15:52:31 +00:00
fix: run user group count inside a transaction
This commit is contained in:
@@ -1175,13 +1175,19 @@ func (s *OidcService) GetDeviceCodeInfo(ctx context.Context, userCode string, us
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *OidcService) GetAllowedGroupsCountOfClient(ctx context.Context, id string) (int64, error) {
|
func (s *OidcService) GetAllowedGroupsCountOfClient(ctx context.Context, id string) (int64, error) {
|
||||||
|
// We only perform select queries here, so we can rollback in all cases
|
||||||
|
tx := s.db.Begin()
|
||||||
|
defer func() {
|
||||||
|
tx.Rollback()
|
||||||
|
}()
|
||||||
|
|
||||||
var client model.OidcClient
|
var client model.OidcClient
|
||||||
err := s.db.WithContext(ctx).Where("id = ?", id).First(&client).Error
|
err := tx.WithContext(ctx).Where("id = ?", id).First(&client).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
count := s.db.WithContext(ctx).Model(&client).Association("AllowedUserGroups").Count()
|
count := tx.WithContext(ctx).Model(&client).Association("AllowedUserGroups").Count()
|
||||||
return count, nil
|
return count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user