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