Custom installers translate no team to team_id 0 (#31846)

Custom installers for no team pass null for team_id. This needs to get
translated to 0 for `getPoliciesBySoftwareTitleIDs`

patch for https://github.com/fleetdm/fleet/pull/31746
For #31571
This commit is contained in:
Konstantin Sykulev 2025-08-12 15:57:20 -05:00 committed by GitHub
parent e5ff795111
commit 34518a62d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 8 deletions

View file

@ -146,7 +146,11 @@ func (svc *Service) UploadSoftwareInstaller(ctx context.Context, payload *fleet.
}
// get values for response object
addedInstaller, err := svc.ds.GetSoftwareInstallerMetadataByTeamAndTitleID(ctx, payload.TeamID, titleID, true)
var tmID uint
if payload.TeamID != nil {
tmID = *payload.TeamID
}
addedInstaller, err := svc.ds.GetSoftwareInstallerMetadataByTeamAndTitleID(ctx, &tmID, titleID, true)
if err != nil {
return nil, ctxerr.Wrap(ctx, err, "getting added software installer")
}

View file

@ -9303,18 +9303,21 @@ func (s *integrationEnterpriseTestSuite) TestAllSoftwareTitles() {
s.uploadSoftwareInstallerWithErrorNameReason(t, payloadEmacsMissingUnSecret, http.StatusUnprocessableEntity, "$FLEET_SECRET_INVALID",
"uninstall script")
// not specifiying a team_id translates to "no team" or team_id of 0
payloadEmacs := &fleet.UploadSoftwareInstallerPayload{
InstallScript: "install",
Filename: "emacs.deb",
SelfService: true,
InstallScript: "install",
Filename: "emacs.deb",
SelfService: true,
AutomaticInstall: true,
}
s.uploadSoftwareInstaller(t, payloadEmacs, http.StatusOK, "")
payloadVim := &fleet.UploadSoftwareInstallerPayload{
InstallScript: "install",
Filename: "vim.deb",
SelfService: true,
TeamID: ptr.Uint(0),
InstallScript: "install",
Filename: "vim.deb",
SelfService: true,
TeamID: ptr.Uint(0),
AutomaticInstall: true,
}
s.uploadSoftwareInstaller(t, payloadVim, http.StatusOK, "")