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

View File

@ -20,7 +20,8 @@ export default (
isAnyTeamAdmin = false, isAnyTeamAdmin = false,
isAnyTeamMaintainer = false, isAnyTeamMaintainer = false,
isGlobalMaintainer = false, isGlobalMaintainer = false,
isNoAccess = false isNoAccess = false,
isMdmEnabled = false
): INavItem[] => { ): INavItem[] => {
if (!user) { if (!user) {
return []; return [];
@ -59,7 +60,7 @@ export default (
regex: new RegExp(`^${URL_PREFIX}/controls/`), regex: new RegExp(`^${URL_PREFIX}/controls/`),
pathname: PATHS.CONTROLS, pathname: PATHS.CONTROLS,
}, },
exclude: !isMaintainerOrAdmin, exclude: !isMaintainerOrAdmin || !isMdmEnabled,
}, },
{ {
name: "Software", 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 AuthGlobalAdminMaintainerRoutes from "./components/AuthGlobalAdminMaintainerRoutes";
import AuthAnyMaintainerAnyAdminRoutes from "./components/AuthAnyMaintainerAnyAdminRoutes"; import AuthAnyMaintainerAnyAdminRoutes from "./components/AuthAnyMaintainerAnyAdminRoutes";
import PremiumRoutes from "./components/PremiumRoutes"; import PremiumRoutes from "./components/PremiumRoutes";
import MdmEnabledRoutes from "./components/MdmEnabledRoutes/MdmEnabledRoutes";
interface IAppWrapperProps { interface IAppWrapperProps {
children: JSX.Element; children: JSX.Element;
@ -170,10 +171,12 @@ const routes = (
</Route> </Route>
<Route path="controls" component={AuthAnyMaintainerAnyAdminRoutes}> <Route path="controls" component={AuthAnyMaintainerAnyAdminRoutes}>
<IndexRedirect to={"mac-os-updates"} /> <Route component={MdmEnabledRoutes}>
<Route component={ManageControlsPage}> <IndexRedirect to={"mac-os-updates"} />
<Route path="mac-os-updates" component={MacOSUpdates} /> <Route component={ManageControlsPage}>
<Route path="mac-settings" component={MacSettingsPage} /> <Route path="mac-os-updates" component={MacOSUpdates} />
<Route path="mac-settings" component={MacSettingsPage} />
</Route>
</Route> </Route>
</Route> </Route>