Add userReport api

This commit is contained in:
Brian Cao 2023-05-18 13:13:18 -07:00
parent de509e7ccc
commit 4df7d6a2a1
7 changed files with 189 additions and 2 deletions

View file

@ -15,6 +15,7 @@ import { getTeamWebsite, getTeamWebsiteByTeamMemberId } from 'queries/admin/team
import { validate } from 'uuid';
import { Auth } from './types';
import { loadWebsite } from './query';
import { UserReport } from '@prisma/client';
const log = debug('umami:auth');
@ -135,7 +136,34 @@ export async function canDeleteWebsite({ user }: Auth, websiteId: string) {
return false;
}
// To-do: Implement when payments are setup.
export async function canViewUserReport(auth: Auth, userReport: UserReport) {
if (auth.user.isAdmin) {
return true;
}
if ((auth.user.id = userReport.userId)) {
return true;
}
if (await canViewWebsite(auth, userReport.websiteId)) {
return true;
}
return false;
}
export async function canUpdateUserReport(auth: Auth, userReport: UserReport) {
if (auth.user.isAdmin) {
return true;
}
if ((auth.user.id = userReport.userId)) {
return true;
}
return false;
}
export async function canCreateTeam({ user }: Auth) {
if (user.isAdmin) {
return true;
@ -144,7 +172,6 @@ export async function canCreateTeam({ user }: Auth) {
return !!user;
}
// To-do: Implement when payments are setup.
export async function canViewTeam({ user }: Auth, teamId: string) {
if (user.isAdmin) {
return true;