Skip to content

feat(admin): add create-workspace-for-owner flow in admin console - #1532

Merged
realcodesiman merged 4 commits into
mainfrom
realcodesiman/enterprise-workspace-add-owner
Oct 23, 2026
Merged

realcodesiman merged 4 commits into
mainfrom
realcodesiman/enterprise-workspace-add-owner

Conversation

@realcodesiman

@realcodesiman realcodesiman commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Admin console can now create a workspace for a given owner email in one action, auto-provisioning a root-tenant user (mailed temporary password) when none exists, with optional team members attached in the same transaction.
  • Generalizes the teamMembers live-increment/rollback machinery from a single owner insert to an owner + N members batch, so a later failure (quota, cache) rolls every insert back with the workspace instead of leaving a partially staffed workspace.
  • Extracts the invite dialog's permission switches into a shared WorkspaceMemberPermissionFields component, reused by the new admin dialog, and generalizes useWorkspaceMemberPermissionsCoupling to any form carrying a permissions field.

Changes

  • packages/business/src/admin-workspace/service.ts (new): orchestrates owner lookup/provisioning, teamMembers quota pre-check, and workspaceService.create({ members })
  • packages/business/src/workspace/service.ts: create/writeWorkspace accept members[] inserted alongside the owner on the same tx
  • packages/business/src/workspace/quota-consumption.ts, workspace-member/service.ts: teamMembersLiveIncremented (boolean) → teamMembersLiveIncrementedCount (number) to support multiple inserts per tx
  • packages/business/src/quota-enforcement/service.ts: owns the hasRoomForTeamMembers batch check; packages/business/src/user-quota/service.ts generalizes isTeamMemberLimitReached(..., additionalCount)
  • packages/business/src/errors.ts: ownerAlreadyHasWorkspaceException, adminWorkspaceMemberNotFoundException, teamMembersLimitReachedException
  • packages/business/src/platform-admin/service.ts, user/provision-root-user.ts (new): extracted shared root-user provisioning, de-duplicated from PlatformAdminService
  • apps/builder/src/enterprise/features/admin-workspaces/: new create-admin-workspace.action.ts, create-admin-workspace-dialog.tsx, schema.ts, wired into the admin workspaces table behind hasEnterpriseFeatures()
  • apps/builder/src/features/workspace-members/: workspace-member-permission-fields.tsx (new, shared), schema/mutation and coupling hook generalized
  • i18n: fields.* keys for the new dialog added across all locale files

Test plan

  • pnpm lint
  • pnpm --filter builder check-types
  • pnpm --filter @chatbotx.io/business check-types
  • packages/business/__tests__/admin-workspace-service.test.ts, apps/builder/__tests__/create-admin-workspace-action.test.ts (new tests added with this change)
  • manual verification: create workspace for new/existing owner with and without members, over-limit team size rejection

Invariant 23 exemption: platform administration.

Lets a platform admin create a workspace for a given owner email
(auto-provisioning a root-tenant user if none exists) and optionally
attach team members with shared permissions, all in one transaction
so a later failure rolls back owner + members together.

- packages/business/admin-workspace: new service orchestrating owner
  provisioning, workspace creation, and member attachment
- workspace/service.create: accepts `members[]` inserted alongside the
  owner on the same tx; quota-consumption and workspace-member tracking
  generalized from a single live-increment flag to a count, to support
  multiple inserts per tx
- quota-enforcement/user-quota: `hasRoomForTeamMembers` batch check for
  the owner + N members case
- errors: `ownerAlreadyHasWorkspaceException`,
  `adminWorkspaceMemberNotFoundException`, `teamMembersLimitReachedException`
- platform-admin/service: extract shared root-user provisioning to
  `user/provision-root-user`
- workspace-members: extract shared permission switches to
  `WorkspaceMemberPermissionFields`, reused by the new admin dialog;
  generalize `useWorkspaceMemberPermissionsCoupling` over any form shape
@github-actions github-actions Bot added the feature New feature or request label Oct 21, 2026
@realcodesiman
realcodesiman merged commit d717b61 into main Oct 23, 2026
4 checks passed
@realcodesiman
realcodesiman deleted the realcodesiman/enterprise-workspace-add-owner branch October 23, 2026 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant