@@ -1734,7 +1734,7 @@ export async function isOrganizationOwner(
17341734
17351735/**
17361736 * Add or update a user's membership in an organization
1737- *
1737+ *
17381738 * Role-based permissions:
17391739 * - Only owners and admins can add/update memberships
17401740 * - Only owners can assign admin roles
@@ -1769,7 +1769,11 @@ export async function addOrUpdateMembership(
17691769 const organizationId = organization . id ;
17701770
17711771 // Check if the admin user is the organization owner
1772- const isAdminOwner = await isOrganizationOwner ( db , organizationId , adminUserId ) ;
1772+ const isAdminOwner = await isOrganizationOwner (
1773+ db ,
1774+ organizationId ,
1775+ adminUserId
1776+ ) ;
17731777
17741778 // If not the owner, check if they have admin role
17751779 let hasAdminRole = false ;
@@ -1816,7 +1820,11 @@ export async function addOrUpdateMembership(
18161820 const targetUserId = targetUser . id ;
18171821
18181822 // Prevent adding the organization owner as a member (they're already the owner)
1819- const isTargetUserOwner = await isOrganizationOwner ( db , organizationId , targetUserId ) ;
1823+ const isTargetUserOwner = await isOrganizationOwner (
1824+ db ,
1825+ organizationId ,
1826+ targetUserId
1827+ ) ;
18201828 if ( isTargetUserOwner ) {
18211829 return null ; // Cannot add/change role of the organization owner
18221830 }
@@ -1873,7 +1881,7 @@ export async function addOrUpdateMembership(
18731881
18741882/**
18751883 * Delete a user's membership from an organization
1876- *
1884+ *
18771885 * Role-based permissions:
18781886 * - Only owners and admins can remove memberships
18791887 * - The organization owner cannot be removed
@@ -1906,7 +1914,11 @@ export async function deleteMembership(
19061914 const organizationId = organization . id ;
19071915
19081916 // Check if the admin user is the organization owner
1909- const isAdminOwner = await isOrganizationOwner ( db , organizationId , adminUserId ) ;
1917+ const isAdminOwner = await isOrganizationOwner (
1918+ db ,
1919+ organizationId ,
1920+ adminUserId
1921+ ) ;
19101922
19111923 // If not the owner, check if they have admin role
19121924 let hasAdminRole = false ;
@@ -1944,7 +1956,11 @@ export async function deleteMembership(
19441956 const targetUserId = targetUser . id ;
19451957
19461958 // Prevent removing the organization owner
1947- const isTargetUserOwner = await isOrganizationOwner ( db , organizationId , targetUserId ) ;
1959+ const isTargetUserOwner = await isOrganizationOwner (
1960+ db ,
1961+ organizationId ,
1962+ targetUserId
1963+ ) ;
19481964 if ( isTargetUserOwner ) {
19491965 return false ; // Cannot remove the organization owner
19501966 }
@@ -1989,31 +2005,6 @@ export async function deleteMembership(
19892005 return ! ! deletedMembership ;
19902006}
19912007
1992- /**
1993- * List all memberships for an organization
1994- *
1995- * @param db Database instance
1996- * @param organizationIdOrHandle Organization ID or handle
1997- * @returns Array of membership records
1998- */
1999- export async function getOrganizationMemberships (
2000- db : ReturnType < typeof createDatabase > ,
2001- organizationIdOrHandle : string
2002- ) {
2003- return await db
2004- . select ( {
2005- userId : memberships . userId ,
2006- organizationId : memberships . organizationId ,
2007- role : memberships . role ,
2008- createdAt : memberships . createdAt ,
2009- updatedAt : memberships . updatedAt ,
2010- } )
2011- . from ( memberships )
2012- . innerJoin ( organizations , eq ( memberships . organizationId , organizations . id ) )
2013- . where ( getOrganizationCondition ( organizationIdOrHandle ) )
2014- . orderBy ( memberships . createdAt ) ;
2015- }
2016-
20172008/**
20182009 * List all memberships for an organization with user information
20192010 *
0 commit comments