feat(core): add generic permission map resolver with core utils and types gating infra - #418
feat(core): add generic permission map resolver with core utils and types gating infra#418grandmaester wants to merge 11 commits into
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughAdds MyOrganization permission manifests, query keys, API types, public exports, and React utilities for permission checks and tier calculation. Core now consumes the packaged SDK tarball locally, and the utilities include Vitest coverage. ChangesMyOrganization permissions
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai Review the PR changes |
|
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/core/package.json`:
- Line 55: Update the `@auth0/myorganization-js` dependency in packages/core so
the published package does not reference the repository-relative file: archive;
use the appropriate registry version or ensure packaging rewrites it to a
consumer-available dependency.
In `@packages/react/src/lib/utils/my-organization/permission-utils.ts`:
- Around line 65-73: Update getResourceVerbs to recognize only permissions with
exactly three segments matching <verb>:my_org:<resource>; require the namespace
segment to be my_org and reject trailing segments or other namespaces before
adding the verb.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 43807a54-afdf-4022-9646-d1e292e5f070
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (9)
auth0-myorganization-js-1.1.0.tgzpackages/core/package.jsonpackages/core/src/services/my-organization/index.tspackages/core/src/services/my-organization/permissions/index.tspackages/core/src/services/my-organization/permissions/permission-manifest.tspackages/core/src/services/my-organization/permissions/permission-query-keys.tspackages/core/src/services/my-organization/permissions/permission-types.tspackages/react/src/lib/utils/my-organization/__tests__/permission-utils.test.tspackages/react/src/lib/utils/my-organization/permission-utils.ts
Aligns the runtime permission layer with the resolver from PR #418. The granted permissions will come from an ID token claim, so the provider no longer fetches them from `GET /my-org/user-permissions`. - `PermissionProvider` now takes the granted `permissions` as a prop instead of running a manifest-driven query. The token-claim read is marked TODO pending SDK support. - `usePermissions` returns `{ permissions, createPermissionResolver }`. A module passes its permission map and gets named boolean flags back, so components never handle scope strings themselves. - Outside a provider the resolver is called with `allowAll`, preserving the previous admin-fallback behaviour for consumers that never mount it. - Drop `isLoading`, `hasProvider`, `refetch` and `getUserTier` from the hook — there is no query to await or refetch, and tiering is now per action. - Move permission types out of `types/my-organization/` to `types/permissions/` to match the core layout. - Fix `PermissionDeniedTooltip` reading `errors.forbidden`; the key is `common.error.forbidden`, so the raw key string was being rendered. - Remove the now-unused `PERMISSION_STALE_TIME_MS` constant and the `configuration.members.get` core-client mock. - Add admin/editor/viewer permission fixtures for tests and local development. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…/permission-gating-infrastructure
Summary
Foundation for permission-based UI gating: a generic, module-agnostic permission resolver plus the Member Management permission declarations that build on it.
This is PR 1 of 2 for the permission infrastructure. Follow-up: (2)
PermissionProvidercontext,usePermissionshook andPermissionDeniedTooltip.Why
Components currently gate mutations with a coarse binary
readOnlyprop. The MyOrganization API exposes granular per-resource permissions, so we're moving to fine-grained checks.Two design goals shaped this revision:
my-organization/toservices/permissions/.hasPermission+readOnlywiring. Each module contributes a data-only permission map and touches no shared code.What
packages/coreservices/permissions/(moved up fromservices/my-organization/permissions/)permission-map.ts—createPermissionResolver(spec)builds a resolver that turns granted scopes into named boolean flags. An array rule requires every scope;{ any: [...] }requires at least one.readOnly(suppresses everything) andallowAll(used when no permission source is mounted) are applied centrally, so no call site repeats them. Return type is inferred from the spec, so a typo in a flag name is a compile error.permission-utils.ts—hasPermission,hasAnyPermission,hasAllPermissions(unchanged).permission-types.ts— trimmed to justOauthScope, the SDK-sourced union that keeps every scope string type-checked.Packages
packages/corepackages/reactexamplesTesting
Checklist
Contributing