Skip to content

Commit 4334e92

Browse files
committed
fix(organizations): hide Leave when the caller's role is unknown
1 parent 0cb4498 commit 4334e92

4 files changed

Lines changed: 6 additions & 38 deletions

File tree

‎apps/sim/app/workspace/[workspaceId]/settings/components/team-management/team-management.tsx‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { getSubscriptionAccessState } from '@/lib/billing/client/utils'
1111
import { useDeploymentShape } from '@/lib/core/config/deployment-shape'
1212
import { getBaseUrl } from '@/lib/core/utils/urls'
1313
import { APP_ENTRY_PATH } from '@/lib/navigation/paths'
14-
import { generateSlug, getUserRole, type Member } from '@/lib/workspaces/organization'
14+
import { generateSlug, type Member } from '@/lib/workspaces/organization'
1515
import { InviteModal } from '@/app/workspace/[workspaceId]/components/invite-modal'
1616
import {
1717
SettingsEmptyState,
@@ -94,15 +94,12 @@ export function TeamManagement({
9494
} = useOrganizationRoster(organizationId)
9595

9696
// Prefer the roster row: Better Auth's full-organization read caps its member list and can omit
97-
// the caller; the roster is withheld only when the directory is hidden, where the fallback is accurate.
97+
// the caller. An unknown role hides Leave rather than offering an owner a request that always fails.
9898
const currentUserRole =
9999
roster?.members.find((member) => member.userId === session?.user?.id)?.role ??
100-
getUserRole(organization, session?.user?.email)
101-
const adminOrOwner = isOrgAdminRole(currentUserRole)
102-
const canLeave =
103-
Boolean(organization) &&
104-
(roster !== undefined || rosterError !== null) &&
105-
currentUserRole !== 'owner'
100+
organization?.members.find((member) => member.user.email === session?.user?.email)?.role
101+
const adminOrOwner = isOrgAdminRole(currentUserRole ?? 'member')
102+
const canLeave = currentUserRole !== undefined && currentUserRole !== 'owner'
106103

107104
const {
108105
data: organizationBillingData,
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
// Export types
22
export type { Member } from '@/lib/workspaces/organization/types'
33
// Export utility functions
4-
export {
5-
generateSlug,
6-
getUserRole,
7-
} from '@/lib/workspaces/organization/utils'
4+
export { generateSlug } from '@/lib/workspaces/organization/utils'

‎apps/sim/lib/workspaces/organization/types.ts‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,3 @@ export interface Member {
1010
role: string
1111
user?: User
1212
}
13-
14-
export interface Organization {
15-
id: string
16-
name: string
17-
slug: string
18-
logo?: string | null
19-
members?: Member[]
20-
createdAt: string | Date
21-
[key: string]: unknown
22-
}

‎apps/sim/lib/workspaces/organization/utils.ts‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,6 @@
33
* These are pure functions that compute values from organization data
44
*/
55

6-
import type { Organization } from '@/lib/workspaces/organization/types'
7-
8-
/**
9-
* Get the role of a user in an organization
10-
*/
11-
export function getUserRole(
12-
organization: Organization | null | undefined,
13-
userEmail?: string
14-
): string {
15-
if (!userEmail || !organization?.members) {
16-
return 'member'
17-
}
18-
const currentMember = organization.members.find((m) => m.user?.email === userEmail)
19-
return currentMember?.role ?? 'member'
20-
}
21-
226
/**
237
* Generate a URL-friendly slug from a name
248
*/

0 commit comments

Comments
 (0)