mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-01 20:41:28 +02:00
add all group to user group lookup
This commit is contained in:
@@ -8,10 +8,15 @@ import (
|
||||
|
||||
const (
|
||||
GetAllowedUserIdsQuery = `
|
||||
select id, array (select json_array_elements_text(auto_groups::json)) as auto_groups
|
||||
select id, array (select json_array_elements_text(auto_groups::json)) as auto_groups
|
||||
from users
|
||||
where account_id=$1 and not blocked and not is_service_user
|
||||
`
|
||||
|
||||
GetAllGroupIdQuery = `
|
||||
select id from groups
|
||||
where account_id=$1 and name='All'
|
||||
`
|
||||
)
|
||||
|
||||
func (pg *PgStore) GetAllowedUsers(ctx context.Context, accountId string) (map[string]struct{}, map[string][]string, error) {
|
||||
@@ -33,6 +38,19 @@ func GetAllowedUsersViaPgxConnection(ctx context.Context, con *pgx.Conn, account
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
rows, err = con.Query(ctx, GetAllGroupIdQuery, accountId)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
allGroupIds, err := pgx.CollectRows(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)
|
||||
for _, user := range users {
|
||||
@@ -40,6 +58,9 @@ 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)
|
||||
}
|
||||
}
|
||||
|
||||
return userIdIdx, groupIdToUserIds, nil
|
||||
|
||||
Reference in New Issue
Block a user