feat: implement board access control (#349)
* 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
This commit is contained in:
35
packages/auth/permissions/board-permissions.ts
Normal file
35
packages/auth/permissions/board-permissions.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
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,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user