diff --git a/src/hooks/useRouteNavCompare.jsx b/src/hooks/useRouteNavCompare.jsx index 7d122ef5d927..27fc1f9a3a14 100644 --- a/src/hooks/useRouteNavCompare.jsx +++ b/src/hooks/useRouteNavCompare.jsx @@ -6,33 +6,28 @@ import routes from 'src/routes' export const useRouteNavCompare = (navigation) => { const dispatch = useDispatch() const { data: profile, isFetching } = useLoadClientPrincipalQuery() - if (isFetching) { return { isLoading: true, component: null } } - dispatch(updateAccessToken(profile)) - const roles = profile?.clientPrincipal?.userRoles || [] - - if (roles.includes('superadmin')) { - // For 'superadmin', simplify to Dashboard and /cipp/ routes directly so people don't work under this account. - return navigation.filter((nav) => nav.to === '/home' || nav.to?.startsWith('/cipp')) - } + let roles = profile?.clientPrincipal?.userRoles || [] + let newNavigation = navigation.map((nav) => { + if (nav.items) { + nav.items = nav.items.filter((item) => { + const route = routes.find((r) => r.path === item.to) + if ( + !route || + (route.allowedRoles && route.allowedRoles.some((role) => roles.includes(role))) + ) { + return true + } else { + //console.log('Removing route', item) + return false + } + }) + } + return nav + }) - // For other roles, use existing filtering logic - return navigation - .map((nav) => { - if (nav.items) { - nav.items = nav.items.filter((item) => { - const route = routes.find((r) => r.path === item.to) - return ( - route && - (!route.allowedRoles || route.allowedRoles.some((role) => roles.includes(role))) - ) - }) - return nav - } - return nav - }) - .filter((nav) => nav.items && nav.items.length > 0) // Remove empty navigation groups + return newNavigation } diff --git a/src/views/cipp/app-settings/CIPPSettings.jsx b/src/views/cipp/app-settings/CIPPSettings.jsx index 6e45b3ba5780..965e1f98f11f 100644 --- a/src/views/cipp/app-settings/CIPPSettings.jsx +++ b/src/views/cipp/app-settings/CIPPSettings.jsx @@ -13,6 +13,8 @@ import { SettingsMaintenance } from 'src/views/cipp/app-settings/SettingsMainten import { SettingsExtensionMappings } from 'src/views/cipp/app-settings/SettingsExtensionMappings.jsx' import { SettingsPartner } from 'src/views/cipp/app-settings/SettingsPartner.jsx' import useQuery from 'src/hooks/useQuery.jsx' +import { SettingsSuperAdmin } from './SettingsSuperAdmin.jsx' +import { useLoadClientPrincipalQuery } from 'src/store/api/auth.js' /** * This function returns the settings page content for CIPP. @@ -25,13 +27,13 @@ export default function CIPPSettings() { const tab = queryString.get('tab') const [active, setActiveTab] = useState(tab ? parseInt(tab) : 1) - + const { data: profile, isFetching } = useLoadClientPrincipalQuery() const setActive = (tab) => { setActiveTab(tab) queryString.set('tab', tab.toString()) navigate(`${location.pathname}?${queryString}`) } - + const superAdmin = profile?.clientPrincipal?.userRoles?.includes('superadmin') return ( @@ -62,6 +64,11 @@ export default function CIPPSettings() { setActive(9)} href="#"> Extension Mappings + {superAdmin && ( + setActive(10)} href="#"> + SuperAdmin Settings + + )} @@ -107,6 +114,11 @@ export default function CIPPSettings() { + + + + + ) diff --git a/src/views/cipp/app-settings/SettingsSuperAdmin.jsx b/src/views/cipp/app-settings/SettingsSuperAdmin.jsx new file mode 100644 index 000000000000..41d8332387a3 --- /dev/null +++ b/src/views/cipp/app-settings/SettingsSuperAdmin.jsx @@ -0,0 +1,113 @@ +import { useGenericGetRequestQuery, useLazyGenericPostRequestQuery } from 'src/store/api/app.js' +import { + CButton, + CCallout, + CCard, + CCardBody, + CCardHeader, + CCol, + CForm, + CLink, + CRow, + CSpinner, +} from '@coreui/react' +import { Form } from 'react-final-form' +import { RFFCFormRadio } from 'src/components/forms/index.js' +import React from 'react' +import { CippCallout } from 'src/components/layout/index.js' + +export function SettingsSuperAdmin() { + const partnerConfig = useGenericGetRequestQuery({ + path: '/api/ExecPartnerMode', + params: { Action: 'ListCurrent' }, + }) + + const [submitWebhook, webhookCreateResult] = useLazyGenericPostRequestQuery() + + const onSubmit = (values) => { + submitWebhook({ + path: '/api/ExecPartnerMode', + values: values, + }).then((res) => {}) + } + + return ( + + + + <> + <> +

Super Admin Configuration

+ + +

+ The configuration settings below should only be modified by a super admin. Super + admins can configure what tenant mode CIPP operates in. See + + our documentation + + for more information on how to configure these modes and what they mean. +

+
+
+ + +

Tenant Mode

+
( + <> + {partnerConfig.isFetching && } + + + + + + {webhookCreateResult.isFetching ? ( + <> + + Saving... + + ) : ( + 'Save' + )} + + + + )} + /> + {webhookCreateResult.isSuccess && ( + + {webhookCreateResult?.data?.results} + + )} + + + + + + + ) +}