added test for GetAllowedUsersViaPgxConnection

Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>
This commit is contained in:
Dmitri Dolguikh
2026-08-05 16:34:44 +02:00
parent ba574dc739
commit 07809fe923
2 changed files with 66 additions and 8 deletions

View File

@@ -14,7 +14,7 @@ const (
`
GetAllGroupIdQuery = `
select id from groups
select array_agg(id) from groups
where account_id=$1 and name='All'
`
)
@@ -42,14 +42,10 @@ func GetAllowedUsersViaPgxConnection(ctx context.Context, con *pgx.Conn, account
if err != nil {
return nil, nil, err
}
allGroupIds, err := pgx.CollectRows(rows, pgx.RowTo[string])
allGroupIds, err := pgx.CollectOneRow(rows, pgx.RowTo[[]string])
if err != nil {
return nil, nil, err
}
allGroupId := ""
if len(allGroupIds) > 0 {
allGroupId = allGroupIds[0]
}
userIdIdx := make(map[string]struct{})
groupIdToUserIds := make(map[string][]string)
@@ -58,8 +54,8 @@ func GetAllowedUsersViaPgxConnection(ctx context.Context, con *pgx.Conn, account
for _, groupId := range user.AutoGroups {
groupIdToUserIds[groupId] = append(groupIdToUserIds[groupId], user.ID)
}
if allGroupId != "" {
groupIdToUserIds[allGroupId] = append(groupIdToUserIds[allGroupId], user.ID)
for _, allgid := range allGroupIds {
groupIdToUserIds[allgid] = append(groupIdToUserIds[allgid], user.ID)
}
}