diff --git a/management/internals/network_map_db/pgsql/user.go b/management/internals/network_map_db/pgsql/user.go index ede46ec96..b75fe9cb6 100644 --- a/management/internals/network_map_db/pgsql/user.go +++ b/management/internals/network_map_db/pgsql/user.go @@ -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