mirror of
https://github.com/ajnart/homarr.git
synced 2026-02-27 08:50:56 +01:00
* feat: implement board access control * fix: deepsource issues * wip: address pull request feedback * chore: address pull request feedback * fix: format issue * test: improve tests * fix: type and lint issue * chore: address pull request feedback * refactor: rename board procedures
36 lines
799 B
TypeScript
36 lines
799 B
TypeScript
import type { Session } from "@auth/core/types";
|
|
|
|
export type BoardPermissionsProps = (
|
|
| {
|
|
creator: {
|
|
id: string;
|
|
} | null;
|
|
}
|
|
| {
|
|
creatorId: string | null;
|
|
}
|
|
) & {
|
|
permissions: {
|
|
permission: string;
|
|
}[];
|
|
isPublic: boolean;
|
|
};
|
|
|
|
export const constructBoardPermissions = (
|
|
board: BoardPermissionsProps,
|
|
session: Session | null,
|
|
) => {
|
|
const creatorId = "creator" in board ? board.creator?.id : board.creatorId;
|
|
|
|
return {
|
|
hasFullAccess: session?.user?.id === creatorId,
|
|
hasChangeAccess:
|
|
session?.user?.id === creatorId ||
|
|
board.permissions.some(({ permission }) => permission === "board-change"),
|
|
hasViewAccess:
|
|
session?.user?.id === creatorId ||
|
|
board.permissions.length >= 1 ||
|
|
board.isPublic,
|
|
};
|
|
};
|