[upstream #4937] feat(core): RoleAssignmentPlugin (WIP) - #24
Draft
ayim wants to merge 72 commits into
Draft
Conversation
…ross-multiple-channels-in-multi-vendor
…low (vendurehq#4974) Co-authored-by: vendure-ci-automation-bot[bot] <221402278+vendure-ci-automation-bot[bot]@users.noreply.github.com>
…-instance, config, filters, new widgets) (vendurehq#4976) Co-authored-by: vendure-ci-automation-bot[bot] <221402278+vendure-ci-automation-bot[bot]@users.noreply.github.com>
…vements (vendurehq#4983) Co-authored-by: vendure-ci-automation-bot[bot] <221402278+vendure-ci-automation-bot[bot]@users.noreply.github.com>
Co-authored-by: vendure-ci-automation-bot[bot] <221402278+vendure-ci-automation-bot[bot]@users.noreply.github.com>
…0-cannot-share-roles-across-multiple-channels-in-multi-vendor # Conflicts: # packages/dashboard/src/app/routes/_authenticated/_administrators/administrators_.$id.tsx # schema-admin.json
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.
Mirrored from vendurehq#4937 for the Overwatch review demo.
Original author: @BibiSebi
Description
First slice of channel-scoped role assignments for multi-vendor setups (design discussion in vendurehq#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 vendurehq#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: