UI: Only render & allow Controls page if MDM is enabled (and user is authorized) (#9568)

## Make sure authorized users can only a) see and b) access the Controls
page if MDM is enabled

- [x] Manual QA for all new/changed functionality

---------

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
This commit is contained in:
Jacob Shandling 2023-01-30 15:31:42 -08:00 committed by GitHub
parent 9125741b6a
commit 180f7691ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 7 deletions

View File

@ -34,6 +34,7 @@ const SiteTopNav = ({
isGlobalMaintainer,
isAnyTeamMaintainer,
isNoAccess,
isMdmEnabled,
} = useContext(AppContext);
const renderNavItem = (navItem: INavItem) => {
@ -97,7 +98,8 @@ const SiteTopNav = ({
isAnyTeamAdmin,
isAnyTeamMaintainer,
isGlobalMaintainer,
isNoAccess
isNoAccess,
isMdmEnabled
);
const renderNavItems = () => {

View File

@ -20,7 +20,8 @@ export default (
isAnyTeamAdmin = false,
isAnyTeamMaintainer = false,
isGlobalMaintainer = false,
isNoAccess = false
isNoAccess = false,
isMdmEnabled = false
): INavItem[] => {
if (!user) {
return [];
@ -59,7 +60,7 @@ export default (
regex: new RegExp(`^${URL_PREFIX}/controls/`),
pathname: PATHS.CONTROLS,
},
exclude: !isMaintainerOrAdmin,
exclude: !isMaintainerOrAdmin || !isMdmEnabled,
},
{
name: "Software",

View File

@ -0,0 +1,20 @@
import React, { useContext } from "react";
import { useErrorHandler } from "react-error-boundary";
import { AppContext } from "context/app";
interface IMdmEnabledRoutesProps {
children: JSX.Element;
}
const MdmEnabledRoutes = ({ children }: IMdmEnabledRoutesProps) => {
const handlePageError = useErrorHandler();
const { isMdmEnabled } = useContext(AppContext);
if (!isMdmEnabled) {
handlePageError({ status: 404 });
return null;
}
return <>{children}</>;
};
export default MdmEnabledRoutes;

View File

@ -0,0 +1 @@
export { default } from "./MdmEnabledRoutes";

View File

@ -60,6 +60,7 @@ import UnauthenticatedRoutes from "./components/UnauthenticatedRoutes";
import AuthGlobalAdminMaintainerRoutes from "./components/AuthGlobalAdminMaintainerRoutes";
import AuthAnyMaintainerAnyAdminRoutes from "./components/AuthAnyMaintainerAnyAdminRoutes";
import PremiumRoutes from "./components/PremiumRoutes";
import MdmEnabledRoutes from "./components/MdmEnabledRoutes/MdmEnabledRoutes";
interface IAppWrapperProps {
children: JSX.Element;
@ -170,12 +171,14 @@ const routes = (
</Route>
<Route path="controls" component={AuthAnyMaintainerAnyAdminRoutes}>
<Route component={MdmEnabledRoutes}>
<IndexRedirect to={"mac-os-updates"} />
<Route component={ManageControlsPage}>
<Route path="mac-os-updates" component={MacOSUpdates} />
<Route path="mac-settings" component={MacSettingsPage} />
</Route>
</Route>
</Route>
<Route path="software">
<IndexRedirect to={"manage"} />