Skip to content

Commit c1b2bc0

Browse files
authored
Fix missing actor for policy-initiated app store installs (#25592)
For #25481 (unreleased). Had updated the logic for webhooks but missed it for inserting the activity because we have to change things in two places. # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements) - [x] Added/updated automated tests - [x] A detailed QA plan exists on the associated ticket (if it isn't there, work with the product group's QA engineer to add it) - [x] Manual QA for all new/changed functionality
1 parent a7b5aee commit c1b2bc0

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

server/datastore/mysql/activities.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,8 @@ func (ds *Datastore) NewActivity(
4141
}
4242
userName = &user.Name
4343
userEmail = &user.Email
44-
} else if ranScriptActivity, ok := activity.(fleet.ActivityTypeRanScript); ok {
45-
if ranScriptActivity.PolicyID != nil {
46-
userName = &automationActivityAuthor
47-
}
48-
} else if softwareInstallActivity, ok := activity.(fleet.ActivityTypeInstalledSoftware); ok {
49-
if softwareInstallActivity.PolicyID != nil {
50-
userName = &automationActivityAuthor
51-
}
44+
} else if automatableActivity, ok := activity.(fleet.AutomatableActivity); ok && automatableActivity.WasFromAutomation() {
45+
userName = &automationActivityAuthor
5246
}
5347

5448
cols := []string{"user_id", "user_name", "activity_type", "details", "created_at"}

server/datastore/mysql/activities_test.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,27 @@ func testActivityEmptyUser(t *testing.T, ds *Datastore) {
285285
}, nil, timestamp,
286286
),
287287
)
288+
289+
require.NoError(
290+
t, ds.NewActivity(
291+
ctx, nil, fleet.ActivityInstalledAppStoreApp{
292+
HostID: 1,
293+
HostDisplayName: "A Host",
294+
SoftwareTitle: "Trello",
295+
AppStoreID: "123456",
296+
CommandUUID: "some uuid",
297+
Status: string(fleet.SoftwareInstalled),
298+
SelfService: false,
299+
PolicyID: ptr.Uint(1),
300+
PolicyName: ptr.String("Sample Policy"),
301+
}, nil, timestamp,
302+
),
303+
)
304+
288305
activities, _, err := ds.ListActivities(context.Background(), fleet.ListActivitiesOptions{})
289306
require.NoError(t, err)
290-
assert.Len(t, activities, 1)
307+
assert.Len(t, activities, 2)
308+
assert.Equal(t, "Fleet", *activities[1].ActorFullName)
291309
}
292310

293311
func testActivityPaginationMetadata(t *testing.T, ds *Datastore) {

0 commit comments

Comments
 (0)