diff options
| author | Fuwn <[email protected]> | 2026-01-24 13:09:50 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-01-24 13:09:50 +0000 |
| commit | 396acf3bbbe00a192cb0ea0a9ccf91b1d8d2850b (patch) | |
| tree | b9df4ca6a70db45cfffbae6fdd7252e20fb8e93c /src/permissions/report.ts | |
| download | umami-main.tar.xz umami-main.zip | |
Created from https://vercel.com/new
Diffstat (limited to 'src/permissions/report.ts')
| -rw-r--r-- | src/permissions/report.ts | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/permissions/report.ts b/src/permissions/report.ts new file mode 100644 index 0000000..01b5476 --- /dev/null +++ b/src/permissions/report.ts @@ -0,0 +1,27 @@ +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.isAdmin) { + return true; + } + + return user.id === report.userId; +} + +export async function canDeleteReport(auth: Auth, report: Report) { + return canUpdateReport(auth, report); +} |