Fixes: #31581 Undo changes to defFilter, they weren't necessary Add unit test for team_id=0 # Checklist for submitter ## Testing - [x] Added/updated automated tests - [x] QA'd all new/changed functionality manually
This commit is contained in:
@@ -400,11 +400,8 @@ WHERE
|
||||
{{end}}
|
||||
{{$additionalWhere}}
|
||||
{{end}}
|
||||
{{with $defFilter := "FALSE"}}
|
||||
-- If teamID is set and PackagesOnly is false, defaults to "a software installer or VPP app exists", and see next condition.
|
||||
{{if and (hasTeamID $) (not $.PackagesOnly) }}
|
||||
{{$defFilter = "(si.id IS NOT NULL OR vat.adam_id IS NOT NULL)"}}
|
||||
{{end}}
|
||||
-- If teamID is set, defaults to "a software installer or VPP app exists", and see next condition.
|
||||
{{with $defFilter := yesNo (hasTeamID .) "(si.id IS NOT NULL OR vat.adam_id IS NOT NULL)" "FALSE"}}
|
||||
-- add software installed for hosts if we're not filtering for "available for install" only
|
||||
{{if not $.AvailableForInstall}}
|
||||
{{$defFilter = $defFilter | printf " ( %s OR sthc.hosts_count > 0 ) "}}
|
||||
|
||||
@@ -2116,6 +2116,17 @@ func testSoftwareTitlesPackagesOnly(t *testing.T, ds *Datastore) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, err = ds.MatchOrCreateSoftwareInstaller(ctx, &fleet.UploadSoftwareInstallerPayload{
|
||||
Title: "fourth",
|
||||
Source: "apps",
|
||||
InstallScript: "echo fourth",
|
||||
Filename: "fourth.pkg",
|
||||
UserID: user.ID,
|
||||
TeamID: ptr.Uint(0),
|
||||
ValidatedLabels: &fleet.LabelIdentsWithScope{},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Sync and reconcile
|
||||
require.NoError(t, ds.SyncHostsSoftware(ctx, time.Now()))
|
||||
require.NoError(t, ds.ReconcileSoftwareTitles(ctx))
|
||||
@@ -2157,4 +2168,16 @@ func testSoftwareTitlesPackagesOnly(t *testing.T, ds *Datastore) {
|
||||
require.NotNil(t, title.SoftwarePackage)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("packages_only=true with team_id=0", func(t *testing.T) {
|
||||
titles, _, _, err := ds.ListSoftwareTitles(ctx, fleet.SoftwareTitleListOptions{
|
||||
PackagesOnly: true,
|
||||
TeamID: ptr.Uint(0),
|
||||
}, fleet.TeamFilter{User: &fleet.User{GlobalRole: ptr.String(fleet.RoleAdmin)}})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, titles, 1)
|
||||
for _, title := range titles {
|
||||
require.NotNil(t, title.SoftwarePackage)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user