Skip to content

Commit 2a4590e

Browse files
authored
fix(invite): allow anyone with access to the workspace to invite others, remove invite from dev environment (#379)
* allow anyone with access to the workspace to invite others * hide invite members in dev * remove invite member from sidebar in dev
1 parent 533f765 commit 2a4590e

File tree

4 files changed

+38
-35
lines changed

4 files changed

+38
-35
lines changed

apps/sim/app/api/workspaces/invitations/route.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,23 @@ export async function GET(req: NextRequest) {
2424
}
2525

2626
try {
27-
// First get all workspaces where the user is a member with owner role
27+
// Get all workspaces where the user is a member (any role)
2828
const userWorkspaces = await db
2929
.select({ id: workspace.id })
3030
.from(workspace)
3131
.innerJoin(
3232
workspaceMember,
3333
and(
3434
eq(workspaceMember.workspaceId, workspace.id),
35-
eq(workspaceMember.userId, session.user.id),
36-
eq(workspaceMember.role, 'owner')
35+
eq(workspaceMember.userId, session.user.id)
3736
)
3837
)
3938

4039
if (userWorkspaces.length === 0) {
4140
return NextResponse.json({ invitations: [] })
4241
}
4342

44-
// Get all workspaceIds where the user is an owner
43+
// Get all workspaceIds where the user is a member
4544
const workspaceIds = userWorkspaces.map((w) => w.id)
4645

4746
// Find all invitations for those workspaces
@@ -84,11 +83,8 @@ export async function POST(req: NextRequest) {
8483
)
8584
.then((rows) => rows[0])
8685

87-
if (!membership || membership.role !== 'owner') {
88-
return NextResponse.json(
89-
{ error: 'You are not authorized to invite to this workspace' },
90-
{ status: 403 }
91-
)
86+
if (!membership) {
87+
return NextResponse.json({ error: 'You are not a member of this workspace' }, { status: 403 })
9288
}
9389

9490
// Get the workspace details for the email

apps/sim/app/w/components/sidebar/components/invite-modal/invite-modal.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
'use client'
22

3-
import { KeyboardEvent, useEffect, useState } from 'react'
4-
import { Check, Loader2, X, XCircle } from 'lucide-react'
5-
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
3+
import { KeyboardEvent, useState } from 'react'
4+
import { Loader2, X } from 'lucide-react'
65
import { Button } from '@/components/ui/button'
76
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'
87
import { Input } from '@/components/ui/input'
98
import { cn } from '@/lib/utils'
109
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
11-
import { InvitesSent } from './invites-sent/invites-sent'
1210

1311
interface InviteModalProps {
1412
open: boolean

apps/sim/app/w/components/sidebar/components/invite-modal/invites-sent/invites-sent.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use client'
22

33
import { useEffect, useState } from 'react'
4-
import { Badge } from '@/components/ui/badge'
54
import { Skeleton } from '@/components/ui/skeleton'
65
import {
76
Table,

apps/sim/app/w/components/sidebar/sidebar.tsx

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import { WorkspaceHeader } from './components/workspace-header/workspace-header'
2222

2323
export function Sidebar() {
2424
useRegistryLoading()
25-
// Initialize global keyboard shortcuts
2625
useGlobalShortcuts()
2726

2827
const {
@@ -38,6 +37,7 @@ export function Sidebar() {
3837
const [showSettings, setShowSettings] = useState(false)
3938
const [showHelp, setShowHelp] = useState(false)
4039
const [showInviteMembers, setShowInviteMembers] = useState(false)
40+
const [isDevEnvironment, setIsDevEnvironment] = useState(false)
4141
const {
4242
mode,
4343
isExpanded,
@@ -51,6 +51,10 @@ export function Sidebar() {
5151
const [isHovered, setIsHovered] = useState(false)
5252
const [explicitMouseEnter, setExplicitMouseEnter] = useState(false)
5353

54+
useEffect(() => {
55+
setIsDevEnvironment(process.env.NODE_ENV === 'development')
56+
}, [])
57+
5458
// Track when active workspace changes to ensure we refresh the UI
5559
useEffect(() => {
5660
if (activeWorkspaceId) {
@@ -272,17 +276,19 @@ export function Sidebar() {
272276
<div className="flex-shrink-0 px-3 pb-3 pt-1">
273277
<div className="flex flex-col space-y-[1px]">
274278
{/* Invite members button */}
275-
<Tooltip>
276-
<TooltipTrigger asChild>
277-
<div
278-
onClick={() => setShowInviteMembers(true)}
279-
className="flex items-center justify-center rounded-md text-sm font-medium text-muted-foreground hover:bg-accent/50 cursor-pointer w-8 h-8 mx-auto"
280-
>
281-
<Send className="h-[18px] w-[18px]" />
282-
</div>
283-
</TooltipTrigger>
284-
<TooltipContent side="right">Invite Members</TooltipContent>
285-
</Tooltip>
279+
{!isDevEnvironment && (
280+
<Tooltip>
281+
<TooltipTrigger asChild>
282+
<div
283+
onClick={() => setShowInviteMembers(true)}
284+
className="flex items-center justify-center rounded-md text-sm font-medium text-muted-foreground hover:bg-accent/50 cursor-pointer w-8 h-8 mx-auto"
285+
>
286+
<Send className="h-[18px] w-[18px]" />
287+
</div>
288+
</TooltipTrigger>
289+
<TooltipContent side="right">Invite Members</TooltipContent>
290+
</Tooltip>
291+
)}
286292

287293
{/* Help button */}
288294
<Tooltip>
@@ -309,15 +315,17 @@ export function Sidebar() {
309315
) : (
310316
<>
311317
{/* Invite members bar */}
312-
<div className="flex-shrink-0 px-3 pt-1">
313-
<div
314-
onClick={() => setShowInviteMembers(true)}
315-
className="flex items-center rounded-md px-2 py-1.5 text-sm font-medium text-muted-foreground hover:bg-accent/50 cursor-pointer"
316-
>
317-
<Send className="h-[18px] w-[18px]" />
318-
<span className="ml-2">Invite members</span>
318+
{!isDevEnvironment && (
319+
<div className="flex-shrink-0 px-3 pt-1">
320+
<div
321+
onClick={() => setShowInviteMembers(true)}
322+
className="flex items-center rounded-md px-2 py-1.5 text-sm font-medium text-muted-foreground hover:bg-accent/50 cursor-pointer"
323+
>
324+
<Send className="h-[18px] w-[18px]" />
325+
<span className="ml-2">Invite members</span>
326+
</div>
319327
</div>
320-
</div>
328+
)}
321329

322330
{/* Bottom buttons container */}
323331
<div className="flex-shrink-0 px-3 pb-3 pt-1">
@@ -350,7 +358,9 @@ export function Sidebar() {
350358

351359
<SettingsModal open={showSettings} onOpenChange={setShowSettings} />
352360
<HelpModal open={showHelp} onOpenChange={setShowHelp} />
353-
<InviteModal open={showInviteMembers} onOpenChange={setShowInviteMembers} />
361+
{!isDevEnvironment && (
362+
<InviteModal open={showInviteMembers} onOpenChange={setShowInviteMembers} />
363+
)}
354364
</aside>
355365
)
356366
}

0 commit comments

Comments
 (0)