mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 08:55:24 +00:00
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:
parent
9125741b6a
commit
180f7691ce
@ -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 = () => {
|
||||||
|
@ -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",
|
||||||
|
@ -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;
|
1
frontend/router/components/MdmEnabledRoutes/index.ts
Normal file
1
frontend/router/components/MdmEnabledRoutes/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export { default } from "./MdmEnabledRoutes";
|
@ -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,12 +171,14 @@ const routes = (
|
|||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
<Route path="controls" component={AuthAnyMaintainerAnyAdminRoutes}>
|
<Route path="controls" component={AuthAnyMaintainerAnyAdminRoutes}>
|
||||||
|
<Route component={MdmEnabledRoutes}>
|
||||||
<IndexRedirect to={"mac-os-updates"} />
|
<IndexRedirect to={"mac-os-updates"} />
|
||||||
<Route component={ManageControlsPage}>
|
<Route component={ManageControlsPage}>
|
||||||
<Route path="mac-os-updates" component={MacOSUpdates} />
|
<Route path="mac-os-updates" component={MacOSUpdates} />
|
||||||
<Route path="mac-settings" component={MacSettingsPage} />
|
<Route path="mac-settings" component={MacSettingsPage} />
|
||||||
</Route>
|
</Route>
|
||||||
</Route>
|
</Route>
|
||||||
|
</Route>
|
||||||
|
|
||||||
<Route path="software">
|
<Route path="software">
|
||||||
<IndexRedirect to={"manage"} />
|
<IndexRedirect to={"manage"} />
|
||||||
|
Loading…
Reference in New Issue
Block a user