improvement(workspaces): auto-add without invite if part of organization#5132
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview The org batch invite API and workspace batch invite path return separate buckets: Invite modals show toasts for “members added” vs “invites sent” and keep failed addresses for retry; org roster UI adds Remove from workspace for non–org-admin members. Client hooks treat partial org invite responses as success and invalidate workspace member/permission caches after direct adds. Reviewed by Cursor Bugbot for commit 588701b. Configure here. |
Greptile SummaryThis PR introduces a "direct add" flow for workspace invitations: when the invitee is already a member of the workspace's organization, they are granted access immediately (no pending invitation, no acceptance step) and receive a lightweight "you've been added" notification email instead of an invite link.
Confidence Score: 5/5Safe to merge — the direct-grant path is properly gated behind org-membership verification and uses an idempotent DB transaction; no auth boundaries are weakened. The core permission insert is wrapped in a transaction with onConflictDoNothing so concurrent invites are handled cleanly. Seat accounting only counts org invitations, not direct grants, which is correct. Tests cover the main paths including the race-condition case. The open items (captureServerEvent not in try-catch, premature getUserOrganization call, id field overloading) are minor and do not affect correctness of access control. apps/sim/lib/invitations/direct-grant.ts — captureServerEvent placement; apps/sim/lib/invitations/workspace-invitations.ts — early getUserOrganization call and id field semantics on the direct-grant return. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Invite email submitted] --> B{Registered user?}
B -- No --> C[Create pending org/workspace invitation\n+ send invite email]
B -- Yes --> D{Already has\nworkspace permission?}
D -- Yes --> E[Reject: already has access]
D -- No --> F{Same org as workspace?}
F -- No --> G[Create pending workspace invitation\nmembershipIntent=external + send invite email]
F -- Yes --> H[grantWorkspaceAccessDirectly\nin DB transaction]
H --> I{outcome}
I -- added --> J[Supersede pending invites\nSync env credentials\nAudit MEMBER_ADDED\nSend workspace-added email]
I -- unchanged\nrace condition --> K[No-op, return unchanged]
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A[Invite email submitted] --> B{Registered user?}
B -- No --> C[Create pending org/workspace invitation\n+ send invite email]
B -- Yes --> D{Already has\nworkspace permission?}
D -- Yes --> E[Reject: already has access]
D -- No --> F{Same org as workspace?}
F -- No --> G[Create pending workspace invitation\nmembershipIntent=external + send invite email]
F -- Yes --> H[grantWorkspaceAccessDirectly\nin DB transaction]
H --> I{outcome}
I -- added --> J[Supersede pending invites\nSync env credentials\nAudit MEMBER_ADDED\nSend workspace-added email]
I -- unchanged\nrace condition --> K[No-op, return unchanged]
Reviews (2): Last reviewed commit: "address comments" | Re-trigger Greptile |
|
@greptile |
|
bugbot run |
|
bugbot run |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 588701b. Configure here.

Summary
Auto-add into workspace without invite acceptance if part of organization. Email still sent to let them know they've been added.
Type of Change
Testing
Tested manually
Checklist