Skip to content

improvement(self-host): enterprise features enabling - #6028

Open
icecrasher321 wants to merge 12 commits into
stagingfrom
improvement/enterprise-self-host
Open

improvement(self-host): enterprise features enabling#6028
icecrasher321 wants to merge 12 commits into
stagingfrom
improvement/enterprise-self-host

Conversation

@icecrasher321

Copy link
Copy Markdown
Collaborator

Summary

Adds ENTERPRISE_ENABLED — one switch that turns on the full enterprise feature set on self-hosted deployments without billing — plus INSTANCE_ORG_NAME, which puts every user in a shared organization at signup so org-scoped features (whitelabeling, PII redaction, permission groups, data drains, audit scoping) actually have something to apply to.

Along the way it fixes three server flags that were never read, audit logs and retention deletion that could not work self-hosted at any setting, and a dead end where an auto-joined member could not create a workspace at all; deployments that set nothing keep exactly today's behavior.

Type of Change

  • Bug fix
  • Documentation
  • Other: Self Host

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@icecrasher321
icecrasher321 requested a review from a team as a code owner July 28, 2026 23:30
@vercel

vercel Bot commented Jul 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Building Building Preview, Comment Jul 29, 2026 1:23am

Request Review

@cursor

cursor Bot commented Jul 28, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches auth/SSO registration, session policy enforcement, data retention deletion, and org deletion—behavior changes for self-hosted operators but upgrades preserve legacy defaults when flags are unset.

Overview
Self-hosted enterprise is now driven by ENTERPRISE_ENABLED / NEXT_PUBLIC_ENTERPRISE_ENABLED (with per-feature overrides), centralized in enterprise-entitlements and env-flags, so UI nav and API gates use the same resolved flags instead of raw NEXT_PUBLIC_* vars. isOrganizationFeatureEntitled gates session policies, whitelabeling, and related APIs when billing is off; audit log access skips subscription checks and uses isAuditLogsEnabled. Retention deletion is opt-in via DATA_RETENTION_ENABLED and no longer applies hosted free-tier defaults when billing is disabled.

INSTANCE_ORG_NAME (and slug/owner) provisions a single org, auto-joins users at signup, and pairs with a consolidate-users script for existing deployments. Org members can create org workspaces when billing is off. New Admin API routes patch whitelabel, data retention, and session policy; DELETE organization detaches workspaces in a transaction and blocks live subscriptions via TERMINAL_SUBSCRIPTION_STATUSES. PII/foreign-workspace validation is shared in lib/billing/retention.

Docs add a self-hosted enterprise guide; Helm 1.3.0 documents enterprise and instance-org env vars without hardcoding "false" overrides that would defeat the master switch.

Reviewed by Cursor Bugbot for commit 7d55f38. Configure here.

Comment thread apps/sim/lib/organizations/instance-org.ts
Comment thread apps/sim/app/api/v1/admin/organizations/[id]/route.ts
Comment thread apps/sim/components/settings/navigation.ts
@greptile-apps

greptile-apps Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Follow-up only: prior retention-nav thread stands as intentional; no new eligible findings.

  • Author reply keeps dataRetention nav gated on isDataRetentionEnabled so the settings UI only appears when cleanup can run.
  • Under ENTERPRISE_ENABLED (plus client twin), nav and deletion enable together; config-without-deletion remains via client-only NEXT_PUBLIC_DATA_RETENTION_ENABLED.
  • No incomplete or unsafe fix relative to that thread; no distinct sibling failure in scope for this follow-up.

Confidence Score: 5/5

Safe to merge from a follow-up perspective; the only prior finding was intentionally retained and no incomplete fix remains.

No blocking failure remains. The retention settings nav gating was confirmed intentional by the author so the UI is not write-only theater when cleanup is off.

Important Files Changed

Filename Overview
apps/sim/components/settings/navigation.ts Self-hosted settings overrides use resolved enterprise flags; retention nav intentionally tied to deletion enablement per author.
apps/sim/lib/core/config/env-flags.ts Enterprise master switch and per-feature resolution with billing-off legacy defaults; no follow-up issue from prior thread.
apps/sim/lib/workspaces/policy.ts Member org-workspace creation is gated behind !isBillingEnabled, matching the PR intent for instance-org / SSO members.

Reviews (5): Last reviewed commit: "Merge remote-tracking branch 'origin/sta..." | Re-trigger Greptile

values.yaml gained the ENTERPRISE_ENABLED switch and INSTANCE_ORG_* keys, and
the feature-flag envDefaults moved from "false" to empty so the master switch
can resolve them. Additive and backward compatible, so a minor bump.
Drop the per-process instance-org id cache. It went stale once the
organization was deleted through the Admin API, and clearing it from the
delete handler would only heal the replica that served that request. The
lookup runs on the signup path against a single-row table, so re-reading
costs nothing and keeps every replica self-correcting.

Scope the org-delete subscription conflict to entitled statuses. Matching any
row regardless of status let a canceled subscription — which bills nobody —
permanently block deletion.
@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@greptile

@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/app/api/v1/admin/organizations/[id]/route.ts
…led ones

ENTITLED_SUBSCRIPTION_STATUSES excludes trialing, so a trial — which grants no
entitlement but is a live Stripe subscription that will convert — slipped past
the delete guard and could be stranded against a removed organization id.

Adds TERMINAL_SUBSCRIPTION_STATUSES and inverts the predicate: block unless the
row is finished. Expressed as the terminal set so a status Stripe adds later
defaults to blocking, which is the safe direction for a destructive operation.
@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@greptile

@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/components/settings/navigation.ts
… env var

Nine client consumers still read NEXT_PUBLIC_SSO_ENABLED /
NEXT_PUBLIC_ACCESS_CONTROL_ENABLED directly while the server gates and settings
nav had moved to the resolver. With only ENTERPRISE_ENABLED set that produced
dead ends: the SSO settings section appeared but ssoClient() was never
registered and no login button rendered, and the Access Control section
appeared but its page reported "not entitled".

Points every consumer at isSsoEnabled / isAccessControlEnabled so visibility and
capability come from one place.
@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@greptile

@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@cursor review

retentionOverrides and per-workspace PII rules both name a workspace, and
neither field is a foreign key. The settings UI rejected ids belonging to
another organization; the Admin API did not, so the two paths could persist
different data for the same org.

Extracts the check as getForeignWorkspaceTargetsReason and points both routes
at it, so they cannot drift apart again.
@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@greptile

@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 3 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit fb98a44. Configure here.

Comment thread apps/sim/app/api/v1/admin/organizations/[id]/route.ts Outdated
Comment thread apps/sim/lib/billing/cleanup-dispatcher.ts
Make org delete atomic. detachOrganizationWorkspaces committed on its own, so a
failed delete left workspaces detached and re-billed while the organization,
its members, and its settings survived. Adds a Tx variant so both commit
together.

Gate the admin session-policy PATCH on entitlement, matching the settings UI.
Without it the stored policy was inert — getSessionPolicy resolves to no-op when
the feature is off, so the one eager clamp would be undone on the next refresh.

Stop emitting plan-wide housekeeping when billing is off. It is keyed to the
hosted free-tier 30-day window, the same default the per-workspace pass
deliberately refuses to apply off-hosted.
@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@greptile

@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@cursor review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant