mirror of
https://github.com/fleetdm/fleet
synced 2026-04-23 14:37:17 +00:00
45 lines
1 KiB
TypeScript
45 lines
1 KiB
TypeScript
import React, { useContext } from "react";
|
|
import { useErrorHandler } from "react-error-boundary";
|
|
import { AppContext } from "context/app";
|
|
|
|
interface IAuthAnyMaintainerAdminObserverPlusRoutesProps {
|
|
children: JSX.Element;
|
|
}
|
|
|
|
/**
|
|
* Checks if a user is any maintainer, admin, or observer plus when routing
|
|
*/
|
|
const AuthAnyMaintainerAdminObserverPlusRoutes = ({
|
|
children,
|
|
}: IAuthAnyMaintainerAdminObserverPlusRoutesProps) => {
|
|
const handlePageError = useErrorHandler();
|
|
const {
|
|
currentUser,
|
|
isGlobalAdmin,
|
|
isGlobalMaintainer,
|
|
isAnyTeamAdmin,
|
|
isAnyTeamMaintainer,
|
|
isAnyTeamObserverPlus,
|
|
isObserverPlus,
|
|
} = useContext(AppContext);
|
|
|
|
if (!currentUser) {
|
|
return null;
|
|
}
|
|
|
|
if (
|
|
!isGlobalAdmin &&
|
|
!isGlobalMaintainer &&
|
|
!isAnyTeamAdmin &&
|
|
!isAnyTeamMaintainer &&
|
|
!isObserverPlus &&
|
|
!isAnyTeamObserverPlus
|
|
) {
|
|
handlePageError({ status: 403 });
|
|
return null;
|
|
}
|
|
|
|
return <>{children}</>;
|
|
};
|
|
|
|
export default AuthAnyMaintainerAdminObserverPlusRoutes;
|