mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 08:58:41 +00:00
fix to return software titles url for all teams context (#21222)
relates to #21058 Makes a change to `GET /software/titles/:id` response so that we return the data needed to display the VPP app icon for the **All Teams** context.  - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/Committing-Changes.md#changes-files) for more information. - [x] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements) - [x] Added/updated tests - [x] Manual QA for all new/changed functionality --------- Co-authored-by: Roberto Dip <rroperzh@gmail.com>
This commit is contained in:
parent
9b06d8ae04
commit
6799cdcb6a
2 changed files with 12 additions and 5 deletions
|
|
@ -25,16 +25,18 @@ FROM
|
|||
vpp_apps vap
|
||||
INNER JOIN vpp_apps_teams vat ON vat.adam_id = vap.adam_id AND vat.platform = vap.platform
|
||||
WHERE
|
||||
vap.title_id = ? AND
|
||||
vat.global_or_team_id = ?`
|
||||
vap.title_id = ? %s`
|
||||
|
||||
var tmID uint
|
||||
// when team id is not nil, we need to filter by the global or team id given.
|
||||
args := []any{titleID}
|
||||
teamFilter := ""
|
||||
if teamID != nil {
|
||||
tmID = *teamID
|
||||
args = append(args, *teamID)
|
||||
teamFilter = "AND vat.global_or_team_id = ?"
|
||||
}
|
||||
|
||||
var app fleet.VPPAppStoreApp
|
||||
err := sqlx.GetContext(ctx, ds.reader(ctx), &app, query, titleID, tmID)
|
||||
err := sqlx.GetContext(ctx, ds.reader(ctx), &app, fmt.Sprintf(query, teamFilter), args...)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, ctxerr.Wrap(ctx, notFound("VPPApp"), "get VPP app metadata")
|
||||
|
|
|
|||
|
|
@ -83,6 +83,11 @@ func testVPPAppMetadata(t *testing.T, ds *Datastore) {
|
|||
require.NoError(t, err)
|
||||
require.Equal(t, &fleet.VPPAppStoreApp{Name: "vpp2", VPPAppID: vpp2}, meta)
|
||||
|
||||
// get it for all teams
|
||||
meta, err = ds.GetVPPAppMetadataByTeamAndTitleID(ctx, nil, titleID2)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, &fleet.VPPAppStoreApp{Name: "vpp2", VPPAppID: vpp2}, meta)
|
||||
|
||||
// try to add the same app again, fails
|
||||
_, err = ds.InsertVPPAppWithTeam(ctx, &fleet.VPPApp{Name: "vpp2", BundleIdentifier: "com.app.vpp2",
|
||||
VPPAppID: fleet.VPPAppID{AdamID: "adam_vpp_app_2", Platform: fleet.MacOSPlatform}}, &team1.ID)
|
||||
|
|
|
|||
Loading…
Reference in a new issue