Skip to content

fix(#2857): surface admin PAT scope in mint UI (gated to admins) - #2895

Merged
jung-thomas merged 1 commit into
DEVfrom
worktree-issue-2857-admin-pat-scope-ui
Oct 23, 2026
Merged

jung-thomas merged 1 commit into
DEVfrom
worktree-issue-2857-admin-pat-scope-ui

Conversation

@jung-thomas

Copy link
Copy Markdown
Contributor

Fixes #2857.

Problem

The headless-admin-PAT feature (#2574) is fully implemented and enforced end-to-end in the backend, but unusable: the mint dialog only offered read/write scopes, so a user following docs/end-users/api-consumption.md could never produce an admin-scoped PAT. A read/write PAT hitting AdminService (@requires:'Admin') always 403s with "lacking required roles: [Admin]" — exactly what DJ reported.

Backend chain (unchanged, already correct): mcp-pat-actions.js (VALID_SCOPES + mint gate) → mcp-pat-middleware.js computeRoles (admin scope + live AdminGrants row → ['Admin','Tutorial.API']) → AdminService @requires:'Admin'. The only gap was the UI never surfacing the admin scope.

Fix

  • srv/pat-service.{cds,js} — new unbound PatService.patCapabilities() returning { adminScopeAvailable } = PAT_ADMIN_SCOPE_ENABLED AND req.user.is('Admin'), mirroring the handleMintPAT gate.
  • MintDialog.fragment.xml + PatActionsController.js — the admin scope item (and a hint) are hidden by default and shown only when patCapabilities reports the caller may mint one. Probe is cached per session and fails closed (hidden on error). Non-admins never see the option.
  • Docs — api-consumption.md clarifies the real gate (you must already hold the Tutorials Admin role; a server-side grant is recorded at mint time); tutorials-ims-gotchas.md gains a regression note: do not make the admin item statically visible — that reintroduces this 403.
  • Tests — test/pat-admin-grant.test.js covers patCapabilities (flag+admin → true, non-admin → false, flag off → false).

Verification

  • npx vitest run test/pat-admin-grant.test.js → 18/18 pass (incl. 3 new).
  • cds compile srv → ok; UI5 linter on the two webapp files → clean; check-ui5-controller-extensions guard → ok.
  • The 23 unrelated srv-qa/* failures in a full npm test are a fresh-worktree artifact (missing srv-qa/lib/parsers.bundle.mjs + @mediapipe/tasks-vision from skipped npm run setup), not caused by this change — the diff touches no srv-qa/hugo-apps code.

Still needs a real end-to-end check (post-deploy)

The exact #2857 scenario — mint an admin PAT via the fixed UI, then curl /admin-pat/Tutorials + /graphql-pat — should be run on DEV after deploy (test/e2e/headless-admin-pat.smoke.test.js with SMOKE_ADMIN_PAT). Draft until that passes.

No changes to backend gates, AdminGrants, the feature flag, approuter routes, or the TTL clamp.

The admin PAT scope (headless /admin-pat/* + /graphql-pat, #2574) is
validated and enforced end-to-end in the backend, but the mint dialog
only offered read/write — so a user following the docs could never mint
an admin-scoped PAT and GET /admin-pat/* 403'd with 'lacking required
roles: [Admin]'.

- srv/pat-service.{cds,js}: add unbound PatService.patCapabilities()
  returning {adminScopeAvailable} = PAT_ADMIN_SCOPE_ENABLED AND
  req.user.is('Admin'), mirroring the handleMintPAT gate.
- MintDialog.fragment.xml + PatActionsController.js: the admin scope item
  (and its hint) are hidden by default and shown only when
  patCapabilities reports the caller may mint one; fails closed on error.
- docs: clarify the admin-scope gate in api-consumption.md; add a
  regression note to tutorials-ims-gotchas.md (don't make the admin item
  statically visible — reintroduces the non-admin 403).
- test/pat-admin-grant.test.js: cover patCapabilities (flag+admin -> true,
  non-admin -> false, flag off -> false).

Backend gates, AdminGrants, feature flag, approuter routes and TTL clamp
are unchanged.
@jung-thomas
jung-thomas marked this pull request as ready for review October 23, 2026 11:55
@jung-thomas
jung-thomas merged commit 545f1fd into DEV Oct 23, 2026
7 checks passed
@jung-thomas
jung-thomas deleted the worktree-issue-2857-admin-pat-scope-ui branch October 23, 2026 11:55
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.

1 participant