mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 13:37:30 +00:00
<!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #37806 This PR creates an activity bounded context and moves the following HTTP endpoint (including the full vertical slice) there: `/api/latest/fleet/activities` NONE of the other activity functionality is moved! This is an incremental approach starting with just 1 API/service endpoint. A significant part of this PR is tests. This feature is now receiving significantly more unit/integration test coverage than before. Also, this PR does not remove the `ListActivities` datastore method in the legacy code. That will be done in the follow up PR (part 2 of 2). This refactoring effort also uncovered an activity/user authorization issue: https://fleetdm.slack.com/archives/C02A8BRABB5/p1768582236611479 # Checklist for submitter If some of the following don't apply, delete the relevant line. - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] Added/updated automated tests - [x] QA'd all new/changed functionality manually <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **New Features** * Activity listing API now available with query filtering, date-range filtering, and type-based filtering * Pagination support for activity results with cursor-based and offset-based options * Configurable sorting by creation date or activity ID in ascending or descending order * Automatic enrichment of activity records with actor user details (name, email, avatar) * Role-based access controls applied to activity visibility based on user permissions <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
125 lines
3.3 KiB
Go
125 lines
3.3 KiB
Go
package activity_test
|
|
|
|
import (
|
|
"regexp"
|
|
"testing"
|
|
|
|
"github.com/fleetdm/fleet/v4/server/archtest"
|
|
)
|
|
|
|
const m = archtest.ModuleName
|
|
|
|
var (
|
|
fleetDeps = regexp.MustCompile(`^github\.com/fleetdm/`)
|
|
|
|
// Common allowed dependencies across activity packages
|
|
activityPkgs = []string{
|
|
m + "/server/activity",
|
|
m + "/server/activity/api",
|
|
m + "/server/activity/api/http",
|
|
m + "/server/activity/internal/types",
|
|
}
|
|
|
|
platformPkgs = []string{
|
|
m + "/server/platform/...",
|
|
m + "/server/contexts/ctxerr",
|
|
m + "/server/contexts/viewer",
|
|
m + "/server/contexts/license",
|
|
m + "/server/contexts/logging",
|
|
m + "/server/contexts/authz",
|
|
m + "/server/contexts/publicip",
|
|
}
|
|
)
|
|
|
|
// TestActivityPackageDependencies runs architecture tests for all activity packages.
|
|
// Each package has specific rules about what dependencies are allowed.
|
|
func TestActivityPackageDependencies(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
cases := []struct {
|
|
name string
|
|
pkg string
|
|
shouldNotDepend []string // defaults to m + "/..." if empty
|
|
ignoreDeps []string
|
|
}{
|
|
{
|
|
name: "root package has no Fleet dependencies",
|
|
pkg: m + "/server/activity",
|
|
},
|
|
{
|
|
name: "api package has no Fleet dependencies",
|
|
pkg: m + "/server/activity/api",
|
|
},
|
|
{
|
|
name: "api/http only depends on api",
|
|
pkg: m + "/server/activity/api/http",
|
|
ignoreDeps: []string{m + "/server/activity/api"},
|
|
},
|
|
{
|
|
name: "internal/types only depends on api",
|
|
pkg: m + "/server/activity/internal/types",
|
|
ignoreDeps: []string{m + "/server/activity/api"},
|
|
},
|
|
{
|
|
name: "internal/mysql depends on api, types, and platform",
|
|
pkg: m + "/server/activity/internal/mysql",
|
|
ignoreDeps: []string{
|
|
m + "/server/activity/api",
|
|
m + "/server/activity/internal/types",
|
|
m + "/server/activity/internal/testutils",
|
|
m + "/server/platform/http",
|
|
m + "/server/platform/mysql",
|
|
m + "/server/platform/mysql/testing_utils",
|
|
m + "/server/contexts/ctxerr",
|
|
m + "/server/ptr",
|
|
},
|
|
},
|
|
{
|
|
name: "internal/service depends on activity and platform packages",
|
|
pkg: m + "/server/activity/internal/service",
|
|
ignoreDeps: append(append([]string{
|
|
m + "/server/ptr",
|
|
}, activityPkgs...), platformPkgs...),
|
|
},
|
|
{
|
|
name: "bootstrap depends on activity and platform packages",
|
|
pkg: m + "/server/activity/bootstrap",
|
|
ignoreDeps: append(append([]string{
|
|
m + "/server/activity/internal/mysql",
|
|
m + "/server/activity/internal/service",
|
|
}, activityPkgs...), platformPkgs...),
|
|
},
|
|
{
|
|
name: "all packages only depend on activity and platform",
|
|
pkg: m + "/server/activity/...",
|
|
ignoreDeps: append(append([]string{
|
|
m + "/server/ptr",
|
|
m + "/server/activity/internal/mysql",
|
|
m + "/server/activity/internal/service",
|
|
m + "/server/activity/internal/testutils",
|
|
}, activityPkgs...), platformPkgs...),
|
|
},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
shouldNotDepend := tc.shouldNotDepend
|
|
if len(shouldNotDepend) == 0 {
|
|
shouldNotDepend = []string{m + "/..."}
|
|
}
|
|
|
|
test := archtest.NewPackageTest(t, tc.pkg).
|
|
OnlyInclude(fleetDeps).
|
|
ShouldNotDependOn(shouldNotDepend...).
|
|
WithTests()
|
|
|
|
if len(tc.ignoreDeps) > 0 {
|
|
test.IgnoreDeps(tc.ignoreDeps...)
|
|
}
|
|
|
|
test.Check()
|
|
})
|
|
}
|
|
}
|