Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
Move permission management to the commercial (.ee) surface
Branch: move-permissions-to-ee
Date: 2026-09-18
Author: [email protected]
Goal
Relocate the authoring of RBAC — creating/editing employee types, editing an
individual user's permissions, and console (kiosk) mode — behind the commercial
license marker (.ee) and the existing plan gate, so the Community/Starter
edition ships an "everyone is an admin" experience: you can add users but not
author roles or modify permissions.
This is a posture + gating change, not a mechanical build change. The .ee
infix and packages/ee are license boundaries only — there is no build-time
edition stripping. Restriction is delivered by the plan gate, not by the file move.
Non-goals (explicitly deferred to the license-server work)
- Collapsing the 4-value
Editionenum (Cloud/Enterprise/Community/Test) to two. - Unifying the ~8 existing gating mechanisms (inline
CarbonEditionchecks,canAccessBackups/internal-email,isCarbonOwnedCompany, the hand-rolled Starter-block inauth.server.ts:325, route-flag declarations, ITAR). - Making the generic plan gate enforce off-Cloud for the OTHER 11 features
(workflows, API keys, …). Those keep
requirePlan/companyHasPlan, which no-op off Cloud — a self-hosted community instance still gets them until the license server. (UPDATE 2026-09-19: the permission/console features now DO enforce on Community via the newcompanyHasFeature/requireFeature— see the follow-up section. Only the broader "all features off on Community" question is deferred.) - Migrating SSO's edition-gate (
isSsoEnabled) to plan-based. (Note for later: SSO is edition-gated only because cloud Supabase can't run SAML yet — once it can, it should become aFEATURE_PLANSentry too.)
Enforcement stays everywhere — do NOT touch
Runtime permission enforcement is community functionality and must keep working
unchanged: requirePermissions (@carbon/auth, ~1,319 call sites), get_claims
/ has_company_permission (Postgres), all RLS policies, getUserClaims / the
Redis permission cache, and the client usePermissions hook. We only relocate and
gate the authoring layer.
The product boundary
| Capability | Edition | Community behavior |
|---|---|---|
| Add / invite / deactivate users; user list | Community ✅ | unchanged |
Enforcement (requirePermissions, RLS, claims) |
Community ✅ | unchanged |
| Create / edit / delete employee types | Business (PERMISSIONS) |
hidden + gated |
| Edit an individual user's permissions; bulk-edit; change a user's employee type | Business (PERMISSIONS) |
hidden + gated |
| Console (kiosk) mode + Console Operator type | Business (PERMISSIONS) |
hidden + gated |
"Everyone is an admin" is emergent, not a new permission branch. seed-company
seeds exactly one employee type — Admin (protected: true, systemType: 'Admin',
full permissions). If Community never exposes employee-type creation and never
exposes console mode (the only other type-creating path), Admin is the only type
that can ever exist. The one required code change is the invite form: today it
requires the inviter to pick a type from a dropdown (employeeType: z.string().min(1)
in users.models.ts); in the gated case we hide the picker and resolve the
systemType='Admin' type in the action so every new Community user is an admin.
Gate: one FEATURE_PLANS entry
packages/ee/src/plan.ts — add:
PERMISSIONS: [Plan.Business, Plan.Partner],
Single key covering role authoring + console mode (per decision — not two keys).
packages/ee/AGENTS.md lists changing FEATURE_PLANS as "Ask First" — approved.
Server: wrap gated route loaders/actions with
requirePlan({ request, client, companyId, redirectTo, feature: "PERMISSIONS" })
(from @carbon/ee/plan.server). redirectTo → the users index / settings page.
Client: hide nav entries + surfaces with usePlanGate({ feature: "PERMISSIONS" })
(from ~/hooks/usePlanGate).
Tasks
1. Add the PERMISSIONS feature key
- Edit
packages/ee/src/plan.ts: addPERMISSIONS: [Plan.Business, Plan.Partner]. - Update
.claude/rules/billing-system.mdFEATURE_PLANS list andpackages/ee/AGENTS.mdif it enumerates features. - Verify:
pnpm --filter @carbon/ee typecheck.
2. Relocate role/permission authoring code to .ee
The moduleShape check allows exactly one users.service.ts and one
users.models.ts per module, but unlimited *.server.ts files. So:
- Create
apps/erp/app/modules/users/users.permissions.ee.server.tsand move the authoring-exclusive writes into it (verified by caller-map — see below):- Employee-type CRUD:
insertEmployeeType,upsertEmployeeType,deleteEmployeeType,upsertEmployeeTypePermissions(fromusers.service.tsL590/608/151/629) — callers are only the employee-type routes. updateEmployee(fromusers.server.tsL1483) — sole caller is the gated per-user editoremployees.$employeeId.tsx. It callsupdatePermissionscross-file, which is fine.
- Employee-type CRUD:
- CORRECTION to the original plan — DO NOT move these; they are shared plumbing
a community path or a background job depends on:
updatePermissions(users.server.tsL1511) — also called by the@carbon/jobstaskupdate-permissions.ts.setUserPermissions(users.server.tsL1449, private) — called byacceptInvite(community invite acceptance). Moving it into a gated file would break invites.- The
make*translators (makeEmptyPermissionsFromModules,makeCompanyPermissionsFromClaims,makePermissionsFromClaims,makeCompanyPermissionsFromEmployeeType) — pure rendering helpers with no commercial weight; leaving them avoids a mid-file dependency web. The gate is delivered byrequirePlanon the route + the.eeUI, not by relocating these.makeEmptyPermissionsFromModulesis also used byapi+/users.empty-permissions.ts(gate that route too).
- Leave in community (invite path depends on them):
createEmployeeAccount,getPermissionsByEmployeeType,makePermissionsFromEmployeeType,getModules,getEmployeeType/getEmployeeTypesreads. - Rename the UI to
.ee.tsx(license marker; imports update to the literal path, likeConfigurationEditor.ee):modules/users/ui/EmployeeTypes/EmployeeTypeForm.tsx,EmployeeTypesTable.tsx→.ee.tsx.modules/users/ui/Employees/EmployeePermissionsForm.tsx,BulkEditPermissionsForm.tsx→.ee.tsx.
- Validators:
employeeTypeValidator,employeeTypePermissionsValidator,userPermissionsValidator,bulkPermissionsValidator— keep inusers.models.ts(the single models file; do not create a second models file), OR move to the.ee.server.tsif they are used only by gated routes. Decide by grepping their importers. - Update the
~/modules/usersbarrel (index.ts) exports accordingly. - Verify:
pnpm exec turbo run typecheck --filter=@carbon/erpafter wiring;node scripts/... module-shape(viapnpm run lint/ the checks) passes — noextra-service/ missing-file findings.
3. Gate the role/permission routes
x+/users+/employee-types.tsx,employee-types.$employeeTypeId.tsx,employee-types.new.tsx,employee-types.delete.$employeeTypeId.tsx,employees.$employeeId.tsx,bulk-edit-permissions.tsx: addrequirePlan({..., feature: "PERMISSIONS" })in loader and action, afterrequirePermissions.- Hide their nav/entry points. The Employee-Types settings nav lives via
modules/settings/ui/useSettingsSubmodules.tsxand/or the users module nav — gate the entries withusePlanGate({ feature: "PERMISSIONS" }). InEmployeesTable.tsx, hide the "Edit permissions" / bulk-edit affordances when gated. - Verify (Cloud path): with
CARBON_EDITION=cloudand a non-bypassed Starter company, the routes redirect with the upgrade flash; a Business company reaches them. Off-Cloud they pass (documented gap).
4. Invite path → default to Admin in the gated case
x+/users+/employees.new.tsx+modules/users/ui/Employees/CreateEmployeeModal.tsx: whenusePlanGate({ feature: "PERMISSIONS" }).isGated, hide the employee-type<Select>; the action resolves thesystemType='Admin'employee type for the company and passes its id asemployeeTypesocreateEmployeeValidator(employeeTyperequired) is satisfied andcreateEmployeeAccountsnapshots the full Admin permission set.- Keep the ungated (Business) behavior exactly as today (real picker).
- Verify: on a gated company, inviting a user with no picker yields a user with full Admin permissions on accept; on Business, the picker still drives the type.
5. Console (kiosk) mode → Business
- Locate the console-mode setting route + UI (grep
updateConsoleSetting,consoleEnabled/consoleinapps/erp/app/routes/x+/settings+/andmodules/settings/ui/).updateConsoleSettingis inapps/erp/app/modules/settings/settings.service.ts(~L1390) and creates theConsole Operatorprotected type (L1411–1479). - Gate the console setting action/route with
requirePlan({..., feature: "PERMISSIONS" })and hide the toggle withusePlanGate. - Move the Console-Operator-type-creation block (the commercial part of
updateConsoleSetting) behind the license marker — extract it tousers.permissions.ee.server.ts(or a settings.ee.server.ts) and call it from the gated action.settings.service.tsis the module's single service file; do not add a second service file — extract to a.server.ts. - Verify: gated company cannot enable console mode / create a Console Operator type; Business can.
6. Docs / rules sync
- Update
packages/ee/AGENTS.md(newPERMISSIONSgate; note the relocated authoring surface),.claude/rules/billing-system.md(FEATURE_PLANS list), and.claude/rules/authentication-system.mdif it describes where permission authoring lives. Consider a short.claude/rules/note or anapps/erp/app/modules/users/AGENTS.mdupdate documenting the community/enterprise cut and the "everyone is admin" emergent behavior. - If any user-facing docs describe employee types / permissions, note the edition gating (carbon-docs skill).
7. Full verification
pnpm exec turbo run typecheck --filter=@carbon/erppnpm exec turbo run typecheck --filter=@carbon/eepnpm run lint(module-shape + conformance checks green)pnpm --filter @carbon/ee test- Browser (per UI-e2e-verification rule): boot
crbn up, verify withCARBON_EDITION=cloud+ a Starter (non-bypass) company that the surfaces hide and invite defaults to Admin; with a Business company that everything is present.
Consolidation follow-up (2026-09-19) — moved the valuable logic to packages/ee
After the first pass (which relocated only the thin CRUD to an app-local
.ee.server.ts), we moved the actual IP — the flattened-permission-object
builder and translators — into the package, and deduped a hidden second copy:
- New
@carbon/ee/permissions.server(packages/ee/src/permissions.server.ts) now holdsupdatePermissions,updateEmployee, the employee-type CRUD, and themake*translators (makeEmptyPermissionsFromModules,makeCompanyPermissionsFromClaims,makeCompanyPermissionsFromEmployeeType). Local structuralCompanyPermission/Permissiontypes (no~/coupling). - The app-local
users.permissions.ee.server.tswas deleted; all ERP routes import from@carbon/ee/permissions.server. - Dedup:
@carbon/jobsupdate-permissions.tshad its OWN full copy ofupdatePermissions(drifted). It now imports the one in@carbon/eeand is just the durable wrapper.@carbon/jobsalready depends on@carbon/ee, and@carbon/eedoes not depend on@carbon/jobs— no cycle. - Stayed in the app (
users.server.ts), community invite plumbing:setUserPermissions(invite merge) andmakePermissionsFromEmployeeType(invite snapshot). The ERPmakePermissionsFromClaimswas dead code (only@carbon/authhas a used copy) and was deleted. - UI stays
.ee.tsxin the app — the forms import~/components/Form,~/hooks,~/utils/path, which don't exist in the package. @carbon/eeusesnoUncheckedIndexedAccess; the ported translator needed amodule === undefinedguard and a local-ref rewrite the ERP tsconfig didn't.
Verified: @carbon/ee, @carbon/jobs, erp typecheck clean (only the
pre-existing root.tsx typegen artifact); Biome clean; MCP digest unchanged
(users 30, settings 95 — the moved fns were never in *.service.ts).
Execution status (2026-09-19)
Implemented on branch move-permissions-to-ee. Verified: @carbon/ee + erp
typecheck clean (only the pre-existing root.tsx +types/root typegen artifact,
untouched by this work), Biome clean, MCP digest regenerated. Not done:
browser e2e (stack not booted) and the license-server off-Cloud enforcement (out
of scope by design).
What landed:
packages/ee/src/plan.ts:PERMISSIONS: [Plan.Business, Plan.Partner].- New commercial files:
apps/erp/app/modules/users/users.permissions.ee.server.ts(the 4 employee-type CRUD funcs +updateEmployee) and.../settings/settings.console.ee.server.ts(updateConsoleSetting); removed fromusers.service.ts/settings.service.ts. - UI renamed to
.ee.tsx:EmployeeTypeForm,EmployeeTypesTable,EmployeePermissionsForm,BulkEditPermissionsForm(barrels repointed). requirePlan({ feature: "PERMISSIONS" })on all 7 authoring routes (employee-types list/new/$id/delete, employees.$employeeId, bulk-edit, api/users.empty-permissions). Console gated inpeople.tsxvia an edition/plan predicate (fetcher returns JSON, so no redirect).- Community "everyone is admin": invite (
employees.newaction) resolves the seededsystemType='Admin'type when gated;CreateEmployeeModalhides the picker + submits a Hidden Admin id. Nav ("Employee Types"), the bulk/per-user "Edit Permissions" affordances, and the Console Mode card are hidden client-side viausePlanGate.
MCP surface change (intentional): moving the 5 write functions out of
*.service.ts removed them as auto-generated MCP tools —
users_{insert,upsert,delete}EmployeeType, users_upsertEmployeeTypePermissions,
settings_updateConsoleSetting. This CLOSES a previously ungated path: the MCP
tools called the service directly, bypassing the route requirePlan. Digest
regenerated (users 30, settings 95).
Open risks to resolve during execution
- Shared reads. Some employee-type reads (
getEmployeeType(s),getPermissionsByEmployeeType) are used by community paths (invite). Grep every importer before moving; keep community-needed reads inusers.service.ts. users.server.tsduplicates@carbon/auth(getClaims,getPermissionCacheKey). Don't move those to.ee; they're enforcement-adjacent. Optionally reconcile the duplication, but that's not required for this PR.- Client/server gate divergence (§ non-goals): accept it; ensure the route
uses
requirePlanso the future off-Cloud flip is one edit. - Console Operator uniqueness — the partial unique index from
20260401000000_protect-console-operator-type.sqlstill holds; we don't change schema, only who can trigger the insert.