mirror of
https://github.com/umami-software/umami.git
synced 2026-02-10 15:47:13 +01:00
Boards components.
Some checks failed
Node.js CI / build (postgresql, 18.18, 10) (push) Has been cancelled
Some checks failed
Node.js CI / build (postgresql, 18.18, 10) (push) Has been cancelled
This commit is contained in:
parent
7edddf15a7
commit
a39ebffd8b
20 changed files with 450 additions and 33 deletions
64
src/permissions/board.ts
Normal file
64
src/permissions/board.ts
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
import { hasPermission } from '@/lib/auth';
|
||||
import { PERMISSIONS } from '@/lib/constants';
|
||||
import type { Auth } from '@/lib/types';
|
||||
import { getBoard, getTeamUser } from '@/queries/prisma';
|
||||
|
||||
export async function canViewBoard({ user }: Auth, boardId: string) {
|
||||
if (user?.isAdmin) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const board = await getBoard(boardId);
|
||||
|
||||
if (board.userId) {
|
||||
return user.id === board.userId;
|
||||
}
|
||||
|
||||
if (board.teamId) {
|
||||
const teamUser = await getTeamUser(board.teamId, user.id);
|
||||
|
||||
return !!teamUser;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export async function canUpdateBoard({ user }: Auth, boardId: string) {
|
||||
if (user.isAdmin) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const board = await getBoard(boardId);
|
||||
|
||||
if (board.userId) {
|
||||
return user.id === board.userId;
|
||||
}
|
||||
|
||||
if (board.teamId) {
|
||||
const teamUser = await getTeamUser(board.teamId, user.id);
|
||||
|
||||
return teamUser && hasPermission(teamUser.role, PERMISSIONS.websiteUpdate);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export async function canDeleteBoard({ user }: Auth, boardId: string) {
|
||||
if (user.isAdmin) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const board = await getBoard(boardId);
|
||||
|
||||
if (board.userId) {
|
||||
return user.id === board.userId;
|
||||
}
|
||||
|
||||
if (board.teamId) {
|
||||
const teamUser = await getTeamUser(board.teamId, user.id);
|
||||
|
||||
return teamUser && hasPermission(teamUser.role, PERMISSIONS.websiteDelete);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
export * from './board';
|
||||
export * from './link';
|
||||
export * from './pixel';
|
||||
export * from './report';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue