Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion apps/web/actions/organization/send-invites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,19 @@ export async function sendOrganizationInvites(
throw new Error("Organization not found");
}

if (organization.ownerId !== user.id) {
const [ownerMembership] = await db()
.select({ id: organizationMembers.id })
.from(organizationMembers)
.where(
and(
eq(organizationMembers.organizationId, organizationId),
eq(organizationMembers.userId, user.id),
eq(organizationMembers.role, "owner"),
),
)
.limit(1);

if (!ownerMembership) {
throw new Error("Only the organization owner can send invites");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ export function MemberAvatars() {
const { activeOrganization, sidebarCollapsed, setInviteDialogOpen, user } =
useDashboardContext();

const isOwner = user?.id === activeOrganization?.organization.ownerId;
const isOwner =
activeOrganization?.members?.some(
(member) => member.userId === user?.id && member.role === "owner",
) ?? false;

if (sidebarCollapsed) return null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import { SeatManagementCard } from "../components/SeatManagementCard";
export default function BillingAndMembersPage() {
const { activeOrganization, user, setInviteDialogOpen } =
useDashboardContext();
const isOwner = user?.id === activeOrganization?.organization.ownerId;
const isOwner =
activeOrganization?.members?.some(
(member) => member.userId === user?.id && member.role === "owner",
) ?? false;
const ownerToastShown = useRef(false);

const showOwnerToast = useCallback(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ export const MembersCard = ({
setConfirmOpen(true);
};

const isMemberOwner = (id: string) => {
return id === activeOrganization?.organization.ownerId;
const isMemberOwner = (role: string) => {
return role === "owner";
};

return (
Expand Down Expand Up @@ -204,7 +204,7 @@ export const MembersCard = ({
</TableHeader>
<TableBody>
{activeOrganization?.members?.map((member) => {
const memberIsOwner = isMemberOwner(member.user.id);
const memberIsOwner = isMemberOwner(member.role);
return (
<TableRow key={member.id}>
<TableCell>{member.user.name}</TableCell>
Expand Down