Merge branch 'dev' into boards

# Conflicts:
#	prisma/schema.prisma
#	src/permissions/index.ts
This commit is contained in:
Mike Cao committed 2026-01-16 16:25:21 -08:00
commit e3e2ed0435
13 files changed
+329 -21

No files matched your search

+65
View File
@@ -0,0 +1,65 @@
import { hasPermission } from '@/lib/auth';
import { PERMISSIONS } from '@/lib/constants';
import { getEntity } from '@/lib/entity';
import type { Auth } from '@/lib/types';
import { getTeamUser } from '@/queries/prisma';
export async function canViewEntity({ user }: Auth, entityId: string) {
if (user?.isAdmin) {
return true;
}
const entity = await getEntity(entityId);
if (entity.userId) {
return user.id === entity.userId;
}
if (entity.teamId) {
const teamUser = await getTeamUser(entity.teamId, user.id);
return !!teamUser;
}
return false;
}
export async function canUpdateEntity({ user }: Auth, entityId: string) {
if (user.isAdmin) {
return true;
}
const entity = await getEntity(entityId);
if (entity.userId) {
return user.id === entity.userId;
}
if (entity.teamId) {
const teamUser = await getTeamUser(entity.teamId, user.id);
return teamUser && hasPermission(teamUser.role, PERMISSIONS.websiteUpdate);
}
return false;
}
export async function canDeleteEntity({ user }: Auth, entityId: string) {
if (user.isAdmin) {
return true;
}
const entity = await getEntity(entityId);
if (entity.userId) {
return user.id === entity.userId;
}
if (entity.teamId) {
const teamUser = await getTeamUser(entity.teamId, user.id);
return teamUser && hasPermission(teamUser.role, PERMISSIONS.websiteDelete);
}
return false;
}
+1
View File
@@ -1,4 +1,5 @@
export * from './board';
export * from './entity';
export * from './link';
export * from './pixel';
export * from './report';