Repository navigation
fix(#2857): surface admin PAT scope in mint UI (gated to admins) - #2895
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/writescopes, so a user followingdocs/end-users/api-consumption.mdcould never produce anadmin-scoped PAT. Aread/writePAT hittingAdminService(@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 + liveAdminGrantsrow →['Admin','Tutorial.API']) →AdminService @requires:'Admin'. The only gap was the UI never surfacing theadminscope.Fix
srv/pat-service.{cds,js}— new unboundPatService.patCapabilities()returning{ adminScopeAvailable }=PAT_ADMIN_SCOPE_ENABLEDANDreq.user.is('Admin'), mirroring thehandleMintPATgate.MintDialog.fragment.xml+PatActionsController.js— theadminscope item (and a hint) are hidden by default and shown only whenpatCapabilitiesreports the caller may mint one. Probe is cached per session and fails closed (hidden on error). Non-admins never see the option.api-consumption.mdclarifies the real gate (you must already hold the Tutorials Admin role; a server-side grant is recorded at mint time);tutorials-ims-gotchas.mdgains a regression note: do not make theadminitem statically visible — that reintroduces this 403.test/pat-admin-grant.test.jscoverspatCapabilities(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-extensionsguard → ok.srv-qa/*failures in a fullnpm testare a fresh-worktree artifact (missingsrv-qa/lib/parsers.bundle.mjs+@mediapipe/tasks-visionfrom skippednpm 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.jswithSMOKE_ADMIN_PAT). Draft until that passes.No changes to backend gates,
AdminGrants, the feature flag, approuter routes, or the TTL clamp.