Followup for #32284, packages_only works for team_id=0 (#32352)

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:
Jonathan Katz
2025-08-27 16:40:48 -04:00
committed by GitHub
parent a03a625eae
commit 3cd68be3a5
3 changed files with 25 additions and 5 deletions
+2 -5
View File
@@ -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)
}
})
}