feat(core): RoleAssignmentPlugin (WIP) - #4937
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 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 |
|
Dashboard Preview: https://admin-dashboard-r9irv2n4z-vendure.vercel.app |
…ross-multiple-channels-in-multi-vendor
1c45377 to
f1e5070
Compare
|
Vendure Core — View preview Changed pages: |
53bfd10 to
f1e5070
Compare
…0-cannot-share-roles-across-multiple-channels-in-multi-vendor # Conflicts: # packages/dashboard/src/app/routes/_authenticated/_administrators/administrators_.$id.tsx # schema-admin.json
|


Description
First slice of channel-scoped role assignments for multi-vendor setups (design discussion in #3779): a skeleton
RoleAssignmentPluginshipped inside@vendure/core, activated only via a newexperimental.roleAssignments.enabledconfig flag.RoleAssignmententity:(user, role, channel)bridge with a unique constraint on the triple, non-nullable FK columns (@EntityId()), CASCADE deletes, and indexes onroleId/channelId(userIdlookups are covered by the unique constraint's leftmost column)@VendurePluginshell that registers the entity — no permission resolution, services, or API extensions yetexperimentalsection onVendureConfig; whenroleAssignments.enabledis set,preBootstrapConfigregisters the plugin internally (users never touchplugins: [])RoleAssignmentMigrationService), run on server bootstrap only while therole_assignmenttable is empty (run-once semantics; deleting all rows re-triggers it, and the service can be invoked manually):user_roles_role→role_channels_channel, one row per (user, role, channel)customer_channels_channel) — without this, every customer would receive an assignment on every channel, because the Customer role itself is auto-assigned to all channels. Administrator users have no channel membership of their own, so their assignments follow the role's channels directly (a user which is both admin and customer is treated as a customer). Row count therefore scales with customers × own channels (typically 1) + admins × channels-per-roleINSERT ... orIgnore); legacy relations are never modified, so disabling the flag stays non-destructiveserverConfig.experimentalFeaturesadmin API field listing the enabledexperimentalconfig keys, so clients can adapt their UI to experimental featuresWith the flag disabled (default) there is zero schema or behavior change. With it enabled, the effects are the new
role_assignmenttable (requires a migration, same asDefaultJobQueuePlugin) and the one-time backfill. Permission resolution still uses only the legacy relations — the rows are inert until the resolver-strategy pass, which follows in subsequent PRs per the plan on the linked issue.Relates to #3779
TODOs
Migration tooling
migrateRoleAssignmentData(queryRunner)helper inmigration-utils/(the v3.6migrateProductOptionGroupData()pattern), so it can run inside the same TypeORM migration that creates the table instead of boot-time run-once logicvendorX-*copies)Breaking changes
None. The feature is opt-in via an experimental flag; disabled by default.
Screenshots
N/A
Checklist
📌 Always:
👍 Most of the time: