-
Notifications
You must be signed in to change notification settings - Fork 3.6k
feat(billing): bypass plan limits for platform admins #4463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
0501fb8
feat(workspaces): bypass personal workspace limit for platform admins
TheodoreSpeaks 673ae39
fix(workspaces): keep platform admin in org context when org lacks te…
TheodoreSpeaks d257bfb
feat(billing): bypass plan limits for platform admins
TheodoreSpeaks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { db } from '@sim/db' | ||
| import { user } from '@sim/db/schema' | ||
| import { and, eq, inArray } from 'drizzle-orm' | ||
|
|
||
| /** | ||
| * Returns true when the user has the platform-level `admin` role. Platform | ||
| * admins are Sim employees with elevated access; many subscription gates are | ||
| * bypassed for them so internal usage isn't paywalled. | ||
| */ | ||
| export async function isPlatformAdmin(userId: string): Promise<boolean> { | ||
| const [row] = await db.select({ role: user.role }).from(user).where(eq(user.id, userId)).limit(1) | ||
| return row?.role === 'admin' | ||
| } | ||
|
|
||
| /** | ||
| * Bulk variant. Returns the set of userIds (from the input) that are platform | ||
| * admins. Used by callers that need to evaluate many users at once (e.g. | ||
| * listing every workspace a user can see and resolving invite policy). | ||
| */ | ||
| export async function getPlatformAdminUserIds(userIds: string[]): Promise<Set<string>> { | ||
| if (userIds.length === 0) return new Set() | ||
| const rows = await db | ||
| .select({ id: user.id }) | ||
| .from(user) | ||
| .where(and(inArray(user.id, userIds), eq(user.role, 'admin'))) | ||
| return new Set(rows.map((r) => r.id)) | ||
| } |
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
isPlatformAdminguard is placed after the org-owner billing-block loop (lines 304–338). That loop iterates every organization the calling user belongs to and returnsisExceeded: trueif any org owner is billing-blocked. A platform admin who has been added as a member to a customer org (e.g., for support or testing) whose owner has a billing dispute or frozen account will hit that early-return and never reach the admin bypass — causing their own workflow runs to be rejected as usage-exceeded. Moving theisPlatformAdmincheck to before the org-owner loop (or parallelizing it with the initialstatsfetch) would prevent the false block.