umami/src/permissions/report.ts
Mike Cao e782c2e627 Block share token users from modifying reports via API.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-24 15:06:39 -08:00

31 lines
687 B
TypeScript

import type { Report } from '@/generated/prisma/client';
import type { Auth } from '@/lib/types';
import { canViewWebsite } from './website';
export async function canViewReport(auth: Auth, report: Report) {
if (auth.user?.isAdmin) {
return true;
}
if (auth.user?.id === report.userId) {
return true;
}
return !!(await canViewWebsite(auth, report.websiteId));
}
export async function canUpdateReport({ user }: Auth, report: Report) {
if (!user) {
return false;
}
if (user.isAdmin) {
return true;
}
return user.id === report.userId;
}
export async function canDeleteReport(auth: Auth, report: Report) {
return canUpdateReport(auth, report);
}