Skip to content

Commit db2c812

Browse files
fix/org-owner-membership-invite-role: fix: align organization owner role display and invite authorization
1 parent ea474d4 commit db2c812

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

apps/web/actions/organization/send-invites.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,19 @@ export async function sendOrganizationInvites(
3535
throw new Error("Organization not found");
3636
}
3737

38-
if (organization.ownerId !== user.id) {
38+
const [ownerMembership] = await db()
39+
.select({ id: organizationMembers.id })
40+
.from(organizationMembers)
41+
.where(
42+
and(
43+
eq(organizationMembers.organizationId, organizationId),
44+
eq(organizationMembers.userId, user.id),
45+
eq(organizationMembers.role, "owner"),
46+
),
47+
)
48+
.limit(1);
49+
50+
if (!ownerMembership) {
3951
throw new Error("Only the organization owner can send invites");
4052
}
4153

apps/web/app/(org)/dashboard/_components/Navbar/MemberAvatars.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ export function MemberAvatars() {
1111
const { activeOrganization, sidebarCollapsed, setInviteDialogOpen, user } =
1212
useDashboardContext();
1313

14-
const isOwner = user?.id === activeOrganization?.organization.ownerId;
14+
const isOwner =
15+
activeOrganization?.members?.some(
16+
(member) => member.userId === user?.id && member.role === "owner",
17+
) ?? false;
1518

1619
if (sidebarCollapsed) return null;
1720

apps/web/app/(org)/dashboard/settings/organization/billing/page.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import { SeatManagementCard } from "../components/SeatManagementCard";
1111
export default function BillingAndMembersPage() {
1212
const { activeOrganization, user, setInviteDialogOpen } =
1313
useDashboardContext();
14-
const isOwner = user?.id === activeOrganization?.organization.ownerId;
14+
const isOwner =
15+
activeOrganization?.members?.some(
16+
(member) => member.userId === user?.id && member.role === "owner",
17+
) ?? false;
1518
const ownerToastShown = useRef(false);
1619

1720
const showOwnerToast = useCallback(() => {

apps/web/app/(org)/dashboard/settings/organization/components/MembersCard.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ export const MembersCard = ({
139139
setConfirmOpen(true);
140140
};
141141

142-
const isMemberOwner = (id: string) => {
143-
return id === activeOrganization?.organization.ownerId;
142+
const isMemberOwner = (role: string) => {
143+
return role === "owner";
144144
};
145145

146146
return (
@@ -204,7 +204,7 @@ export const MembersCard = ({
204204
</TableHeader>
205205
<TableBody>
206206
{activeOrganization?.members?.map((member) => {
207-
const memberIsOwner = isMemberOwner(member.user.id);
207+
const memberIsOwner = isMemberOwner(member.role);
208208
return (
209209
<TableRow key={member.id}>
210210
<TableCell>{member.user.name}</TableCell>

0 commit comments

Comments
 (0)