diff --git a/base/database/utils.go b/base/database/utils.go index 15a773503..7db9f2e88 100644 --- a/base/database/utils.go +++ b/base/database/utils.go @@ -222,6 +222,10 @@ func ReadReplicaConfigured() bool { func InventoryHostsJoin(tx *gorm.DB, groups map[string]string) *gorm.DB { tx = tx.Joins("JOIN inventory.hosts ih ON ih.id = sp.inventory_id") if _, ok := groups[rbac.KeyGrouped]; !ok { + if _, ok := groups[rbac.KeyUngrouped]; ok { + // show only systems with '[]' group + return tx.Where("ih.groups = '[]'") + } // return query without WHERE if there are no groups return tx } diff --git a/base/database/utils_test.go b/base/database/utils_test.go index fc27579f4..db757b2cd 100644 --- a/base/database/utils_test.go +++ b/base/database/utils_test.go @@ -30,6 +30,7 @@ var testCases = []map[int64]map[string]string{ rbac.KeyUngrouped: "[]", }}, {0: {rbac.KeyGrouped: `{"[{\"id\":\"non-existing-group\"}]"}`}}, + {nUngrouped: {rbac.KeyUngrouped: "[]"}}, {nAll: {}}, }