mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-12-06 13:34:13 +03:00
* update config for roles and add validator * ensure admin and viewer are never overridden * add class method to user to retrieve all allowed cameras * enforce config roles in auth api endpoints * add camera access api dependency functions * protect review endpoints * protect preview endpoints * rename param name for better fastapi injection matching * remove unneeded * protect export endpoints * protect event endpoints * protect media endpoints * update auth hook for allowed cameras * update default app view * ensure anonymous user always returns all cameras * limit cameras in explore * cameras is already a list * limit cameras in review/history * limit cameras in live view * limit cameras in camera groups * only show face library and classification in sidebar for admin * remove check in delete reviews since admin role is required, no need to check camera access. fixes failing test * pass request with camera access for tests * more async * camera access tests * fix proxy auth tests * allowed cameras for review tests * combine event tests and refactor for camera access * fix post validation for roles * don't limit roles in create user dialog * fix triggers endpoints no need to run require camera access dep since the required role is admin * fix type * create and edit role dialogs * delete role dialog * fix role change dialog * update settings view for roles * i18n changes * minor spacing tweaks * docs * use badges and camera name label component * clarify docs * display all cameras badge for admin and viewer * i18n fix * use validator to prevent reserved and empty roles from being assigned * split users and roles into separate tabs in settings * tweak docs * clarify docs * change icon * don't memoize roles always recalculate on component render
89 lines
2.3 KiB
TypeScript
89 lines
2.3 KiB
TypeScript
import { ENV } from "@/env";
|
|
import { FrigateConfig } from "@/types/frigateConfig";
|
|
import { NavData } from "@/types/navigation";
|
|
import { useMemo } from "react";
|
|
import { isDesktop } from "react-device-detect";
|
|
import { FaCompactDisc, FaVideo } from "react-icons/fa";
|
|
import { IoSearch } from "react-icons/io5";
|
|
import { LuConstruction } from "react-icons/lu";
|
|
import { MdCategory, MdVideoLibrary } from "react-icons/md";
|
|
import { TbFaceId } from "react-icons/tb";
|
|
import useSWR from "swr";
|
|
import { useIsAdmin } from "./use-is-admin";
|
|
|
|
export const ID_LIVE = 1;
|
|
export const ID_REVIEW = 2;
|
|
export const ID_EXPLORE = 3;
|
|
export const ID_EXPORT = 4;
|
|
export const ID_PLAYGROUND = 5;
|
|
export const ID_FACE_LIBRARY = 6;
|
|
export const ID_CLASSIFICATION = 7;
|
|
|
|
export default function useNavigation(
|
|
variant: "primary" | "secondary" = "primary",
|
|
) {
|
|
const { data: config } = useSWR<FrigateConfig>("config", {
|
|
revalidateOnFocus: false,
|
|
});
|
|
const isAdmin = useIsAdmin();
|
|
|
|
return useMemo(
|
|
() =>
|
|
[
|
|
{
|
|
id: ID_LIVE,
|
|
variant,
|
|
icon: FaVideo,
|
|
title: "menu.live.title",
|
|
url: "/",
|
|
},
|
|
{
|
|
id: ID_REVIEW,
|
|
variant,
|
|
icon: MdVideoLibrary,
|
|
title: "menu.review",
|
|
url: "/review",
|
|
},
|
|
{
|
|
id: ID_EXPLORE,
|
|
variant,
|
|
icon: IoSearch,
|
|
title: "menu.explore",
|
|
url: "/explore",
|
|
},
|
|
{
|
|
id: ID_EXPORT,
|
|
variant,
|
|
icon: FaCompactDisc,
|
|
title: "menu.export",
|
|
url: "/export",
|
|
},
|
|
{
|
|
id: ID_PLAYGROUND,
|
|
variant,
|
|
icon: LuConstruction,
|
|
title: "menu.uiPlayground",
|
|
url: "/playground",
|
|
enabled: ENV !== "production",
|
|
},
|
|
{
|
|
id: ID_FACE_LIBRARY,
|
|
variant,
|
|
icon: TbFaceId,
|
|
title: "menu.faceLibrary",
|
|
url: "/faces",
|
|
enabled: isDesktop && config?.face_recognition.enabled && isAdmin,
|
|
},
|
|
{
|
|
id: ID_CLASSIFICATION,
|
|
variant,
|
|
icon: MdCategory,
|
|
title: "menu.classification",
|
|
url: "/classification",
|
|
enabled: isDesktop && isAdmin,
|
|
},
|
|
] as NavData[],
|
|
[config?.face_recognition?.enabled, variant, isAdmin],
|
|
);
|
|
}
|