mirror of
https://github.com/umami-software/umami.git
synced 2026-02-06 21:57:16 +01:00
Fixed components build. Renamed validations to permissions.
This commit is contained in:
parent
f0ec24e8f5
commit
c916e4ff9c
80 changed files with 99 additions and 373 deletions
|
|
@ -1,64 +0,0 @@
|
|||
import { Auth } from '@/lib/types';
|
||||
import { getPixel, getTeamUser } from '@/queries';
|
||||
import { hasPermission } from '@/lib/auth';
|
||||
import { PERMISSIONS } from '@/lib/constants';
|
||||
|
||||
export async function canViewPixel({ user }: Auth, pixelId: string) {
|
||||
if (user?.isAdmin) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const pixel = await getPixel(pixelId);
|
||||
|
||||
if (pixel.userId) {
|
||||
return user.id === pixel.userId;
|
||||
}
|
||||
|
||||
if (pixel.teamId) {
|
||||
const teamUser = await getTeamUser(pixel.teamId, user.id);
|
||||
|
||||
return !!teamUser;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export async function canUpdatePixel({ user }: Auth, pixelId: string) {
|
||||
if (user.isAdmin) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const pixel = await getPixel(pixelId);
|
||||
|
||||
if (pixel.userId) {
|
||||
return user.id === pixel.userId;
|
||||
}
|
||||
|
||||
if (pixel.teamId) {
|
||||
const teamUser = await getTeamUser(pixel.teamId, user.id);
|
||||
|
||||
return teamUser && hasPermission(teamUser.role, PERMISSIONS.websiteUpdate);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export async function canDeletePixel({ user }: Auth, pixelId: string) {
|
||||
if (user.isAdmin) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const pixel = await getPixel(pixelId);
|
||||
|
||||
if (pixel.userId) {
|
||||
return user.id === pixel.userId;
|
||||
}
|
||||
|
||||
if (pixel.teamId) {
|
||||
const teamUser = await getTeamUser(pixel.teamId, user.id);
|
||||
|
||||
return teamUser && hasPermission(teamUser.role, PERMISSIONS.websiteDelete);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue