add software_title_id to added_app_store_app activity (#25119)

relates to #24120

adds the `software_title_id` to the `added_app_store_activity`

- [x] Added/updated automated tests
- [x] Manual QA for all new/changed functionality
This commit is contained in:
Gabriel Hernandez 2025-01-03 16:03:13 +00:00 committed by GitHub
parent 58afb100af
commit b193f2dc1c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 40 additions and 23 deletions

View file

@ -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,

View file

@ -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")

View file

@ -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,

View file

@ -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{}