- Add ProductMember model (many-to-many User ↔ Product) - Add productAccessFilter helper (owner OR member OR clause) - Replace all ownership checks across actions and API routes - Add addProductMemberAction / removeProductMemberAction / leaveProductAction - Add TeamManager component in product settings (owner adds/removes Developers) - Add LeaveProductButton in user settings (member leaves a product team) - Regenerate Prisma Client after schema migration Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
18 lines
438 B
TypeScript
18 lines
438 B
TypeScript
import { prisma } from '@/lib/prisma'
|
|
|
|
const accessFilter = (userId: string) => ({
|
|
OR: [
|
|
{ user_id: userId },
|
|
{ members: { some: { user_id: userId } } },
|
|
],
|
|
})
|
|
|
|
export async function getAccessibleProduct(productId: string, userId: string) {
|
|
return prisma.product.findFirst({
|
|
where: { id: productId, ...accessFilter(userId) },
|
|
})
|
|
}
|
|
|
|
export function productAccessFilter(userId: string) {
|
|
return accessFilter(userId)
|
|
}
|