Skip to content

Commit

Permalink
cherry pick software title id to added_app_store_app activity (#25125)
Browse files Browse the repository at this point in the history
relates to #24120

cherry pick PR for adding software_title_id to added_app_store_app
activity
  • Loading branch information
ghernandez345 authored Jan 6, 2025
1 parent 1f05269 commit b9067da
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 23 deletions.
2 changes: 2 additions & 0 deletions docs/Contributing/Audit-logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down
17 changes: 10 additions & 7 deletions ee/server/service/vpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
15 changes: 9 additions & 6 deletions server/fleet/activities.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
29 changes: 19 additions & 10 deletions server/service/integration_mdm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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]
Expand All @@ -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{}
Expand Down Expand Up @@ -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{}
Expand Down Expand Up @@ -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{}
Expand All @@ -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{}
Expand Down

0 comments on commit b9067da

Please sign in to comment.