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:
@@ -3,8 +3,8 @@ import { useCallback } from "react";
|
||||
import { createId } from "@homarr/db/client";
|
||||
import type { WidgetKind } from "@homarr/definitions";
|
||||
|
||||
import { useUpdateBoard } from "~/app/[locale]/boards/_client";
|
||||
import type { EmptySection, Item } from "~/app/[locale]/boards/_types";
|
||||
import { useUpdateBoard } from "~/app/[locale]/boards/(content)/_client";
|
||||
|
||||
interface MoveAndResizeItem {
|
||||
itemId: string;
|
||||
|
||||
@@ -18,10 +18,12 @@ export const BoardRenameModal = createModal<InnerProps>(
|
||||
({ actions, innerProps }) => {
|
||||
const utils = clientApi.useUtils();
|
||||
const t = useI18n();
|
||||
const { mutate, isPending } = clientApi.board.rename.useMutation({
|
||||
const { mutate, isPending } = clientApi.board.renameBoard.useMutation({
|
||||
onSettled() {
|
||||
void utils.board.byName.invalidate({ name: innerProps.previousName });
|
||||
void utils.board.default.invalidate();
|
||||
void utils.board.getBoardByName.invalidate({
|
||||
name: innerProps.previousName,
|
||||
});
|
||||
void utils.board.getDefaultBoard.invalidate();
|
||||
},
|
||||
});
|
||||
const form = useForm<FormType>({
|
||||
|
||||
8
apps/nextjs/src/components/board/permissions/client.ts
Normal file
8
apps/nextjs/src/components/board/permissions/client.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { useSession } from "@homarr/auth/client";
|
||||
import type { BoardPermissionsProps } from "@homarr/auth/shared";
|
||||
import { constructBoardPermissions } from "@homarr/auth/shared";
|
||||
|
||||
export const useBoardPermissions = (board: BoardPermissionsProps) => {
|
||||
const { data: session } = useSession();
|
||||
return constructBoardPermissions(board, session);
|
||||
};
|
||||
8
apps/nextjs/src/components/board/permissions/server.ts
Normal file
8
apps/nextjs/src/components/board/permissions/server.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { auth } from "@homarr/auth";
|
||||
import type { BoardPermissionsProps } from "@homarr/auth/shared";
|
||||
import { constructBoardPermissions } from "@homarr/auth/shared";
|
||||
|
||||
export const getBoardPermissions = async (board: BoardPermissionsProps) => {
|
||||
const session = await auth();
|
||||
return constructBoardPermissions(board, session);
|
||||
};
|
||||
@@ -2,12 +2,12 @@ import { useCallback } from "react";
|
||||
|
||||
import { createId } from "@homarr/db/client";
|
||||
|
||||
import { useUpdateBoard } from "~/app/[locale]/boards/_client";
|
||||
import type {
|
||||
CategorySection,
|
||||
EmptySection,
|
||||
Section,
|
||||
} from "~/app/[locale]/boards/_types";
|
||||
import { useUpdateBoard } from "~/app/[locale]/boards/(content)/_client";
|
||||
|
||||
interface AddCategory {
|
||||
name: string;
|
||||
|
||||
@@ -22,8 +22,8 @@ import {
|
||||
WidgetEditModal,
|
||||
} from "@homarr/widgets";
|
||||
|
||||
import { useRequiredBoard } from "~/app/[locale]/boards/_context";
|
||||
import type { Item } from "~/app/[locale]/boards/_types";
|
||||
import { useRequiredBoard } from "~/app/[locale]/boards/(content)/_context";
|
||||
import { editModeAtom } from "../editMode";
|
||||
import { useItemActions } from "../items/item-actions";
|
||||
import type { UseGridstackRefs } from "./gridstack/use-gridstack";
|
||||
|
||||
@@ -8,11 +8,11 @@ import type {
|
||||
GridStackNode,
|
||||
} from "@homarr/gridstack";
|
||||
|
||||
import type { Section } from "~/app/[locale]/boards/_types";
|
||||
import {
|
||||
useMarkSectionAsReady,
|
||||
useRequiredBoard,
|
||||
} from "~/app/[locale]/boards/_context";
|
||||
import type { Section } from "~/app/[locale]/boards/_types";
|
||||
} from "~/app/[locale]/boards/(content)/_context";
|
||||
import { editModeAtom } from "../../editMode";
|
||||
import { useItemActions } from "../../items/item-actions";
|
||||
import { initializeGridstack } from "./init-gridstack";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { usePathname } from "next/navigation";
|
||||
import type { AppShellProps } from "@mantine/core";
|
||||
|
||||
import { useOptionalBoard } from "~/app/[locale]/boards/_context";
|
||||
import { useOptionalBoard } from "~/app/[locale]/boards/(content)/_context";
|
||||
|
||||
const supportedVideoFormats = ["mp4", "webm", "ogg"];
|
||||
const isVideo = (url: string) =>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useRequiredBoard } from "~/app/[locale]/boards/_context";
|
||||
import { useRequiredBoard } from "~/app/[locale]/boards/(content)/_context";
|
||||
import { homarrLogoPath, homarrPageTitle } from "./homarr-logo";
|
||||
import type { LogoWithTitleProps } from "./logo";
|
||||
import { Logo, LogoWithTitle } from "./logo";
|
||||
|
||||
Reference in New Issue
Block a user