From b9067da2c135f6434c2bc7eb6071fd4e48c9d6e2 Mon Sep 17 00:00:00 2001 From: Gabriel Hernandez Date: Mon, 6 Jan 2025 09:43:11 +0000 Subject: [PATCH] cherry pick software title id to added_app_store_app activity (#25125) relates to #24120 cherry pick PR for adding software_title_id to added_app_store_app activity --- docs/Contributing/Audit-logs.md | 2 ++ ee/server/service/vpp.go | 17 ++++++++------- server/fleet/activities.go | 15 +++++++------ server/service/integration_mdm_test.go | 29 +++++++++++++++++--------- 4 files changed, 40 insertions(+), 23 deletions(-) diff --git a/docs/Contributing/Audit-logs.md b/docs/Contributing/Audit-logs.md index feadc6e0cda6..19dea07e2f81 100644 --- a/docs/Contributing/Audit-logs.md +++ b/docs/Contributing/Audit-logs.md @@ -1376,6 +1376,7 @@ Generated when an App Store app is added to Fleet. This activity contains the following fields: - "software_title": Name of the App Store app. +- "software_title_id": ID of the added software title. - "app_store_id": ID of the app on the Apple App Store. - "platform": Platform of the app (`darwin`, `ios`, or `ipados`). - "self_service": App installation can be initiated by device owner. @@ -1387,6 +1388,7 @@ This activity contains the following fields: ```json { "software_title": "Logic Pro", + "software_title_id": 123, "app_store_id": "1234567", "platform": "darwin", "self_service": false, diff --git a/ee/server/service/vpp.go b/ee/server/service/vpp.go index d8f453a950e3..04eaef1ea9fa 100644 --- a/ee/server/service/vpp.go +++ b/ee/server/service/vpp.go @@ -363,17 +363,20 @@ func (svc *Service) AddAppStoreApp(ctx context.Context, teamID *uint, appID flee Name: assetMD.TrackName, LatestVersion: assetMD.Version, } - if _, err := svc.ds.InsertVPPAppWithTeam(ctx, app, teamID); err != nil { + + addedApp, err := svc.ds.InsertVPPAppWithTeam(ctx, app, teamID) + if err != nil { return ctxerr.Wrap(ctx, err, "writing VPP app to db") } act := fleet.ActivityAddedAppStoreApp{ - AppStoreID: app.AdamID, - Platform: app.Platform, - TeamName: &teamName, - SoftwareTitle: app.Name, - TeamID: teamID, - SelfService: app.SelfService, + AppStoreID: app.AdamID, + Platform: app.Platform, + TeamName: &teamName, + SoftwareTitle: app.Name, + SoftwareTitleId: addedApp.TitleID, + TeamID: teamID, + SelfService: app.SelfService, } if err := svc.NewActivity(ctx, authz.UserFromContext(ctx), act); err != nil { return ctxerr.Wrap(ctx, err, "create activity for add app store app") diff --git a/server/fleet/activities.go b/server/fleet/activities.go index fcc70fe610e8..5cb0d4fbb73a 100644 --- a/server/fleet/activities.go +++ b/server/fleet/activities.go @@ -1909,12 +1909,13 @@ func (a ActivityDisabledVPP) Documentation() (activity string, details string, d } type ActivityAddedAppStoreApp struct { - SoftwareTitle string `json:"software_title"` - AppStoreID string `json:"app_store_id"` - TeamName *string `json:"team_name"` - TeamID *uint `json:"team_id"` - Platform AppleDevicePlatform `json:"platform"` - SelfService bool `json:"self_service"` + SoftwareTitle string `json:"software_title"` + SoftwareTitleId uint `json:"software_title_id"` + AppStoreID string `json:"app_store_id"` + TeamName *string `json:"team_name"` + TeamID *uint `json:"team_id"` + Platform AppleDevicePlatform `json:"platform"` + SelfService bool `json:"self_service"` } func (a ActivityAddedAppStoreApp) ActivityName() string { @@ -1924,12 +1925,14 @@ func (a ActivityAddedAppStoreApp) ActivityName() string { func (a ActivityAddedAppStoreApp) Documentation() (activity string, details string, detailsExample string) { return "Generated when an App Store app is added to Fleet.", `This activity contains the following fields: - "software_title": Name of the App Store app. +- "software_title_id": ID of the added software title. - "app_store_id": ID of the app on the Apple App Store. - "platform": Platform of the app (` + "`darwin`, `ios`, or `ipados`" + `). - "self_service": App installation can be initiated by device owner. - "team_name": Name of the team to which this App Store app was added, or ` + "`null`" + ` if it was added to no team. - "team_id": ID of the team to which this App Store app was added, or ` + "`null`" + `if it was added to no team.`, `{ "software_title": "Logic Pro", + "software_title_id": 123, "app_store_id": "1234567", "platform": "darwin", "self_service": false, diff --git a/server/service/integration_mdm_test.go b/server/service/integration_mdm_test.go index 71d2acde9b1b..fc321093df8e 100644 --- a/server/service/integration_mdm_test.go +++ b/server/service/integration_mdm_test.go @@ -3028,7 +3028,6 @@ func (s *integrationMDMTestSuite) TestEnqueueMDMCommandWithSecret() { require.NoError(t, err) assert.Contains(t, string(cmd.Raw), secretValue) assert.NotContains(t, string(cmd.Raw), "FLEET_SECRET_VALUE") - } func (s *integrationMDMTestSuite) TestMDMWindowsCommandResults() { @@ -7194,7 +7193,6 @@ func (s *integrationMDMTestSuite) TestWindowsMDMCommandWithSecret() { // The secret value should not be exposed via the regular API. assert.NotContains(t, string(getMDMCmdResp.Results[0].Payload), secretValue) assert.Contains(t, string(getMDMCmdResp.Results[0].Payload), "$FLEET_SECRET_DATA") - } func (s *integrationMDMTestSuite) TestWindowsAutomaticEnrollmentCommands() { @@ -10997,6 +10995,7 @@ func (s *integrationMDMTestSuite) TestVPPApps() { s.DoJSON("GET", "/api/latest/fleet/software/app_store_apps", &getAppStoreAppsRequest{}, http.StatusOK, &appResp, "team_id", fmt.Sprint(team.ID)) require.NoError(t, appResp.Err) + macOSApp := fleet.VPPApp{ VPPAppTeam: fleet.VPPAppTeam{ VPPAppID: fleet.VPPAppID{ @@ -11064,6 +11063,16 @@ func (s *integrationMDMTestSuite) TestVPPApps() { } assert.ElementsMatch(t, expectedApps, appResp.AppStoreApps) + getSoftwareTitleIDFromApp := func(app *fleet.VPPApp) uint { + var titleID uint + mysql.ExecAdhocSQL(t, s.ds, func(q sqlx.ExtContext) error { + ctx := context.Background() + return sqlx.GetContext(ctx, q, &titleID, `SELECT title_id FROM vpp_apps WHERE adam_id = ? AND platform = ?;`, app.AdamID, app.Platform) + }) + + return titleID + } + // Insert/deletion flow for macOS app // Add an app store app to team 1 addedApp := expectedApps[0] @@ -11073,8 +11082,8 @@ func (s *integrationMDMTestSuite) TestVPPApps() { s.DoJSON("POST", "/api/latest/fleet/software/app_store_apps", &addAppStoreAppRequest{TeamID: &team.ID, AppStoreID: addedApp.AdamID, SelfService: true}, http.StatusOK, &addAppResp) s.lastActivityMatches(fleet.ActivityAddedAppStoreApp{}.ActivityName(), - fmt.Sprintf(`{"team_name": "%s", "software_title": "%s", "app_store_id": "%s", "team_id": %d, "platform": "%s", "self_service": true}`, team.Name, - addedApp.Name, addedApp.AdamID, team.ID, addedApp.Platform), 0) + fmt.Sprintf(`{"team_name": "%s", "software_title": "%s", "software_title_id": %d, "app_store_id": "%s", "team_id": %d, "platform": "%s", "self_service": true}`, team.Name, + addedApp.Name, getSoftwareTitleIDFromApp(addedApp), addedApp.AdamID, team.ID, addedApp.Platform), 0) // Now we should be filtering out the app we added to team 1 appResp = getAppStoreAppsResponse{} @@ -11124,8 +11133,8 @@ func (s *integrationMDMTestSuite) TestVPPApps() { &addAppStoreAppRequest{TeamID: &team.ID, AppStoreID: addedApp.AdamID, Platform: addedApp.Platform}, http.StatusOK, &addAppResp) s.lastActivityMatches(fleet.ActivityAddedAppStoreApp{}.ActivityName(), - fmt.Sprintf(`{"team_name": "%s", "software_title": "%s", "app_store_id": "%s", "team_id": %d, "platform": "%s", "self_service": false}`, team.Name, - addedApp.Name, addedApp.AdamID, team.ID, addedApp.Platform), 0) + fmt.Sprintf(`{"team_name": "%s", "software_title": "%s", "software_title_id": %d, "app_store_id": "%s", "team_id": %d, "platform": "%s", "self_service": false}`, team.Name, + addedApp.Name, getSoftwareTitleIDFromApp(addedApp), addedApp.AdamID, team.ID, addedApp.Platform), 0) // Now we should be filtering out the app we added to team 1 appResp = getAppStoreAppsResponse{} @@ -11198,8 +11207,8 @@ func (s *integrationMDMTestSuite) TestVPPApps() { http.StatusOK, &addAppResp) s.lastActivityMatches( fleet.ActivityAddedAppStoreApp{}.ActivityName(), - fmt.Sprintf(`{"team_name": "%s", "software_title": "%s", "app_store_id": "%s", "team_id": %d, "platform": "%s", "self_service": true}`, team.Name, - appSelfService.Name, appSelfService.AdamID, team.ID, appSelfService.Platform), + fmt.Sprintf(`{"team_name": "%s", "software_title": "%s", "software_title_id": %d, "app_store_id": "%s", "team_id": %d, "platform": "%s", "self_service": true}`, team.Name, + appSelfService.Name, getSoftwareTitleIDFromApp(appSelfService), appSelfService.AdamID, team.ID, appSelfService.Platform), 0, ) listSw = listSoftwareTitlesResponse{} @@ -11213,8 +11222,8 @@ func (s *integrationMDMTestSuite) TestVPPApps() { http.StatusOK, &addAppResp) s.lastActivityMatches( fleet.ActivityAddedAppStoreApp{}.ActivityName(), - fmt.Sprintf(`{"team_name": "%s", "software_title": "%s", "app_store_id": "%s", "team_id": %d, "platform": "%s", "self_service": false}`, team.Name, - app.Name, app.AdamID, team.ID, app.Platform), + fmt.Sprintf(`{"team_name": "%s", "software_title": "%s", "software_title_id": %d, "app_store_id": "%s", "team_id": %d, "platform": "%s", "self_service": false}`, team.Name, + app.Name, getSoftwareTitleIDFromApp(app), app.AdamID, team.ID, app.Platform), 0, ) listSw = listSoftwareTitlesResponse{}