Skip to content

Self service categories endpoints + activities - #46593

Merged
jkatz01 merged 23 commits into
feat/39018-self-service-categoriesfrom
46391-categories-endpoints
Jun 1, 2026
Merged

Self service categories endpoints + activities#46593
jkatz01 merged 23 commits into
feat/39018-self-service-categoriesfrom
46391-categories-endpoints

Conversation

@jkatz01

@jkatz01 jkatz01 commented Jun 1, 2026

Copy link
Copy Markdown
Member

Related issue: Resolves #46391

Checklist for submitter

If some of the following don't apply, delete the relevant line.

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    See Changes files for more information.

  • Input data is properly validated, SELECT * is avoided, SQL injection is prevented (using placeholders for values in statements), JS inline code is prevented especially for url redirects, and untrusted data interpolated into shell scripts/commands is validated against shell metacharacters.

  • Timeouts are implemented and retries are limited to avoid infinite loops

  • If paths of existing endpoints are modified without backwards compatibility, checked the frontend/CLI for any necessary changes

Testing

jkatz01 added 22 commits May 28, 2026 10:34
…loader, emoji literals in tests

- LegacySoftwareCategoryNames doc comment matches migration branch
- GetSoftwareCategoryNameToIDMap adds plain-name entries pointing to the same
  id, so callers can look up either form
- testing_utils mysql cli uses --default-character-set=utf8mb4 to preserve
  emojis in schema.sql seed data
- replace fleet.TranslateLegacySoftwareCategoryNames(...) wrappers in tests
  with literal emoji slices; inline tc.categories / tc.fmaDefaultCategories
  fixtures
- update stale mock signatures (teamID parameter) in fleetctl gitops, vpp,
  maintained_apps test files
- gofmt and modernize cleanups in server/service/categories.go
5 expectedPayload.Categories / titleResponse.Categories assertions in
TestSoftwareInstallerUploadDownloadAndDelete, TestInHouseAppCRUD, and
TestMaintainedApps need to compare to the stored emoji-prefixed form rather
than the plain input. The FMA manifest-report assertion at dbAppResponse
stays plain because it reports back the manifest's DefaultCategories, not
the DB-stored translation.
…es' into 46391-categories-endpoints

# Conflicts:
#	server/datastore/mysql/in_house_apps_test.go
#	server/datastore/mysql/schema.sql
#	server/datastore/mysql/software_test.go
#	server/service/integration_enterprise_test.go
- Request/response: team_id (canonical) with renameto:"fleet_id" on GET
  query, POST body, and the 3 activity structs. Matches the convention
  used by addAppStoreApp and ActivityTypeAddedSoftware.
- ListSoftwareCategories now takes *uint and validates in the service
  layer so the missing-fleet_id error matches POST exactly:
  422 ValidationFailed name=fleet_id reason="fleet_id is required".
- Activities now emit both team_id+fleet_id and team_name+fleet_name on
  the wire; integration test JSON assertions updated to match.
Adding a Fleet-maintained app to the library now (re-)creates any default
categories the admin previously deleted so the FMA still surfaces under
its canonical (emoji) category. Custom packages, VPP apps, and in-house
apps continue to reject unknown categories.

- ee/server/service/maintained_apps.go: translate FMA manifest categories
  to canonical names, then ensure each one exists via the new
  createMissingCategories helper before resolving CategoryIDs.
- createMissingCategories uses svc.NewSoftwareCategory so each insert
  emits its standard added_self_service_category activity. Case folding
  via strings.EqualFold mirrors the DB's utf8mb4_unicode_ci uniqueness.
- Add TestAddFleetMaintainedAppCreatesMissingCategories integration test
  using startFMAServers; flip the existing GET-no-fleet_id assertion to
  422 to match the new uniform error wording.
This reverts commit 762f556.

Per updated product direction, FMA installs should NOT create categories
that don't already exist on the fleet — falling back to the previous
behavior of silently dropping unknown categories from the FMA's
manifest.

The bundled GET-no-fleet_id 400→422 test-assertion fix is kept since
the 422 behavior was introduced by the earlier renameto commit and is
still in place.
- TruncateTables now deletes software_categories rows where team_id != 0
  so per-team defaults seeded by NewTeam don't collide with the next
  subtest's NewTeam (the schema-seeded team_id=0 rows are preserved).
- testSoftwareCategoryCRUD counts now include the 6 seeded defaults.
- Restore the original "filter out categories that don't exist" comment
  in AddFleetMaintainedApp.
@jkatz01
jkatz01 marked this pull request as ready for review June 1, 2026 19:28
@jkatz01
jkatz01 requested a review from a team as a code owner June 1, 2026 19:28

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@jkatz01

jkatz01 commented Jun 1, 2026

Copy link
Copy Markdown
Member Author

@claude review once

@codecov

codecov Bot commented Jun 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 67.65957% with 76 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (feat/39018-self-service-categories@57d78c5). Learn more about missing BASE report.

Files with missing lines Patch % Lines
ee/server/service/categories.go 55.45% 29 Missing and 20 partials ⚠️
server/service/categories.go 65.00% 13 Missing and 1 partial ⚠️
server/datastore/mysql/software.go 83.58% 7 Missing and 4 partials ⚠️
server/datastore/mysql/teams.go 33.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@                          Coverage Diff                          @@
##             feat/39018-self-service-categories   #46593   +/-   ##
=====================================================================
  Coverage                                      ?   66.81%           
=====================================================================
  Files                                         ?     2807           
  Lines                                         ?   223887           
  Branches                                      ?    11346           
=====================================================================
  Hits                                          ?   149598           
  Misses                                        ?    60699           
  Partials                                      ?    13590           
Flag Coverage Δ
backend 68.53% <67.65%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No bugs found, but this is a substantial feature PR — new CRUD endpoints, authz policy changes, new activity types, schema change to scope software_categories per-team, and seeding logic on team creation — so it warrants a human review.

Extended reasoning...

Overview

This PR adds the self-service software categories feature: four new REST endpoints (GET/POST/PATCH/DELETE /api/_version_/fleet/software/self_service_categories), three new activity types, an authz object type (software_category) with corresponding rego rules + tests, and a schema change scoping software_categories per-team (previously global). It also seeds the six default category names on team creation, adds cascade-delete via teamRefs, threads team_id through GetSoftwareCategoryIDs/GetSoftwareCategoryNameToIDMap (touching VPP, FMA, software installer paths), and updates the test truncation helpers to preserve only the global (team_id=0) seed rows.

Security risks

The authz changes are the main scrutiny point: new software_category object type with global + team-role rules, plus a deliberate carve-out denying GitOps (with a TODO to revisit). The team-scoped object.team_id != 0 guards mean unassigned (team_id=0) categories require global roles, which matches the pattern for other team-scoped resources. The endpoints validate fleet_id presence, name length (255 runes), and trim whitespace; UpdateSoftwareCategory/DeleteSoftwareCategory correctly load the category before authz to scope by its team. SQL uses placeholders throughout. No obvious injection or auth bypass surface.

Level of scrutiny

High. This is production-critical code: authz policy changes, new public API surface, a schema migration impact (per-team categories with cascade), and behavioral change to several existing paths (FMA add, VPP batch associate, software installer update, gitops). The PR also targets a feature branch (feat/39018-self-service-categories), which softens the immediate blast radius, but the changes still need human eyes on the authz rules and the team-scoping invariants.

Other factors

Test coverage is reasonable — new policy_test cases cover all roles × team combinations, a new datastore CRUD test, and a full integration test exercising create/list/rename/delete/activities/cross-fleet uniqueness/cascade-on-team-delete. Codecov flags 68% patch coverage with the bulk of misses in the new service files, mostly error paths. The bug-hunting system found no issues. A human reviewer should still confirm the GitOps-denied TODO is intentional for this PR and that the legacy global software_categories rows (team_id=0) interact correctly with all the changed call sites.

@jkatz01
jkatz01 merged commit abd3821 into feat/39018-self-service-categories Jun 1, 2026
39 checks passed
@jkatz01
jkatz01 deleted the 46391-categories-endpoints branch June 1, 2026 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants