Boards components.
Some checks failed
Node.js CI / build (postgresql, 18.18, 10) (push) Has been cancelled

This commit is contained in:
Mike Cao 2025-11-29 15:59:01 -08:00
parent 7edddf15a7
commit a39ebffd8b
20 changed files with 450 additions and 33 deletions

64
src/permissions/board.ts Normal file
View file

@ -0,0 +1,64 @@
import { hasPermission } from '@/lib/auth';
import { PERMISSIONS } from '@/lib/constants';
import type { Auth } from '@/lib/types';
import { getBoard, getTeamUser } from '@/queries/prisma';
export async function canViewBoard({ user }: Auth, boardId: string) {
if (user?.isAdmin) {
return true;
}
const board = await getBoard(boardId);
if (board.userId) {
return user.id === board.userId;
}
if (board.teamId) {
const teamUser = await getTeamUser(board.teamId, user.id);
return !!teamUser;
}
return false;
}
export async function canUpdateBoard({ user }: Auth, boardId: string) {
if (user.isAdmin) {
return true;
}
const board = await getBoard(boardId);
if (board.userId) {
return user.id === board.userId;
}
if (board.teamId) {
const teamUser = await getTeamUser(board.teamId, user.id);
return teamUser && hasPermission(teamUser.role, PERMISSIONS.websiteUpdate);
}
return false;
}
export async function canDeleteBoard({ user }: Auth, boardId: string) {
if (user.isAdmin) {
return true;
}
const board = await getBoard(boardId);
if (board.userId) {
return user.id === board.userId;
}
if (board.teamId) {
const teamUser = await getTeamUser(board.teamId, user.id);
return teamUser && hasPermission(teamUser.role, PERMISSIONS.websiteDelete);
}
return false;
}

View file

@ -1,3 +1,4 @@
export * from './board';
export * from './link';
export * from './pixel';
export * from './report';