mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 01:47:35 -02:30
Check user permissions before fetching system settings
This commit is contained in:
@@ -4,6 +4,7 @@ import { t } from '@lingui/macro';
|
|||||||
import { Switch, Route, Redirect, Link, useRouteMatch } from 'react-router-dom';
|
import { Switch, Route, Redirect, Link, useRouteMatch } from 'react-router-dom';
|
||||||
import { CaretLeftIcon } from '@patternfly/react-icons';
|
import { CaretLeftIcon } from '@patternfly/react-icons';
|
||||||
import { Card, PageSection } from '@patternfly/react-core';
|
import { Card, PageSection } from '@patternfly/react-core';
|
||||||
|
import { useConfig } from 'contexts/Config';
|
||||||
import ContentError from 'components/ContentError';
|
import ContentError from 'components/ContentError';
|
||||||
import RoutedTabs from 'components/RoutedTabs';
|
import RoutedTabs from 'components/RoutedTabs';
|
||||||
import useRequest from 'hooks/useRequest';
|
import useRequest from 'hooks/useRequest';
|
||||||
@@ -13,6 +14,9 @@ import InstanceDetail from './InstanceDetail';
|
|||||||
import InstancePeerList from './InstancePeers';
|
import InstancePeerList from './InstancePeers';
|
||||||
|
|
||||||
function Instance({ setBreadcrumb }) {
|
function Instance({ setBreadcrumb }) {
|
||||||
|
const { me } = useConfig();
|
||||||
|
const canReadSettings = me.is_superuser || me.is_system_auditor;
|
||||||
|
|
||||||
const match = useRouteMatch();
|
const match = useRouteMatch();
|
||||||
const tabsArray = [
|
const tabsArray = [
|
||||||
{
|
{
|
||||||
@@ -30,19 +34,21 @@ function Instance({ setBreadcrumb }) {
|
|||||||
];
|
];
|
||||||
|
|
||||||
const {
|
const {
|
||||||
result: { isK8s },
|
result: isK8s,
|
||||||
error,
|
error,
|
||||||
isLoading,
|
isLoading,
|
||||||
request,
|
request,
|
||||||
} = useRequest(
|
} = useRequest(
|
||||||
useCallback(async () => {
|
useCallback(async () => {
|
||||||
|
if (!canReadSettings) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
const { data } = await SettingsAPI.readCategory('system');
|
const { data } = await SettingsAPI.readCategory('system');
|
||||||
return {
|
return data?.IS_K8S ?? false;
|
||||||
isK8s: data.IS_K8S,
|
}, [canReadSettings]),
|
||||||
};
|
|
||||||
}, []),
|
|
||||||
{ isK8s: false, isLoading: true }
|
{ isK8s: false, isLoading: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
request();
|
request();
|
||||||
}, [request]);
|
}, [request]);
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ const QS_CONFIG = getQSConfig('instance', {
|
|||||||
function InstanceList() {
|
function InstanceList() {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const { me } = useConfig();
|
const { me } = useConfig();
|
||||||
|
const canReadSettings = me.is_superuser || me.is_system_auditor;
|
||||||
const [showHealthCheckAlert, setShowHealthCheckAlert] = useState(false);
|
const [showHealthCheckAlert, setShowHealthCheckAlert] = useState(false);
|
||||||
const [pendingHealthCheck, setPendingHealthCheck] = useState(false);
|
const [pendingHealthCheck, setPendingHealthCheck] = useState(false);
|
||||||
const [canRunHealthCheck, setCanRunHealthCheck] = useState(true);
|
const [canRunHealthCheck, setCanRunHealthCheck] = useState(true);
|
||||||
@@ -48,18 +49,24 @@ function InstanceList() {
|
|||||||
} = useRequest(
|
} = useRequest(
|
||||||
useCallback(async () => {
|
useCallback(async () => {
|
||||||
const params = parseQueryString(QS_CONFIG, location.search);
|
const params = parseQueryString(QS_CONFIG, location.search);
|
||||||
const [response, responseActions, sysSettings] = await Promise.all([
|
|
||||||
|
const [response, responseActions] = await Promise.all([
|
||||||
InstancesAPI.read(params),
|
InstancesAPI.read(params),
|
||||||
InstancesAPI.readOptions(),
|
InstancesAPI.readOptions(),
|
||||||
SettingsAPI.readCategory('system'),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
let sysSettings = {};
|
||||||
|
if (canReadSettings) {
|
||||||
|
sysSettings = await SettingsAPI.readCategory('system');
|
||||||
|
}
|
||||||
|
|
||||||
const isPending = response.data.results.some(
|
const isPending = response.data.results.some(
|
||||||
(i) => i.health_check_pending === true
|
(i) => i.health_check_pending === true
|
||||||
);
|
);
|
||||||
setPendingHealthCheck(isPending);
|
setPendingHealthCheck(isPending);
|
||||||
return {
|
return {
|
||||||
instances: response.data.results,
|
instances: response.data.results,
|
||||||
isK8s: sysSettings.data.IS_K8S,
|
isK8s: sysSettings?.data?.IS_K8S ?? false,
|
||||||
count: response.data.count,
|
count: response.data.count,
|
||||||
actions: responseActions.data.actions,
|
actions: responseActions.data.actions,
|
||||||
relatedSearchableKeys: (
|
relatedSearchableKeys: (
|
||||||
@@ -67,7 +74,7 @@ function InstanceList() {
|
|||||||
).map((val) => val.slice(0, -8)),
|
).map((val) => val.slice(0, -8)),
|
||||||
searchableKeys: getSearchableKeys(responseActions.data.actions?.GET),
|
searchableKeys: getSearchableKeys(responseActions.data.actions?.GET),
|
||||||
};
|
};
|
||||||
}, [location.search]),
|
}, [location.search, canReadSettings]),
|
||||||
{
|
{
|
||||||
instances: [],
|
instances: [],
|
||||||
count: 0,
|
count: 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user