Skip to content

Commit

Permalink
Merge pull request #2931 from florkbr/fix-ip-whitelist-missing-permis…
Browse files Browse the repository at this point in the history
…sions

Fix SatelliteToken org admin check to handle if user info not loaded
  • Loading branch information
Hyperkid123 authored Sep 17, 2024
2 parents ef65bb6 + 12d7f2c commit 4c85a8d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/Satellite/IPWhitelistTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ const IPWhitelistTable: React.FC = () => {
<Tr key={ipBlock.ip_block}>
<Td dataLabel={columnNames.ip_block}>{ipBlock.ip_block}</Td>
<Td dataLabel={columnNames.org_id}>{ipBlock.org_id}</Td>
<Td dataLabel={columnNames.created_at}>{ipBlock.created_at}</Td>
<Td dataLabel={columnNames.created_at}>{new Date(ipBlock.created_at).toLocaleString()}</Td>
<Td dataLabel={columnNames.remove} modifier="fitContent">
<TableText>
<Button
Expand Down
13 changes: 9 additions & 4 deletions src/layouts/SatelliteToken.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext, useEffect, useState } from 'react';
import React, { useEffect, useState } from 'react';
import axios from 'axios';
import { useFlag } from '@unleash/proxy-client-react';
import { Button } from '@patternfly/react-core/dist/dynamic/components/Button';
Expand All @@ -9,19 +9,24 @@ import { Page, PageSection } from '@patternfly/react-core/dist/dynamic/component
import SatelliteTable from '../components/Satellite/SatelliteTable';
import IPWhitelistTable from '../components/Satellite/IPWhitelistTable';
import { getEnv } from '../utils/common';
import ChromeAuthContext from '../auth/ChromeAuthContext';
import useChrome from '@redhat-cloud-services/frontend-components/useChrome';
import NotFoundRoute from '../components/NotFoundRoute';

const SatelliteToken: React.FC = () => {
const [token, setToken] = useState('');
const [error, setError] = useState(null);
const { user } = useContext(ChromeAuthContext);
const [isOrgAdmin, setIsOrgAdmin] = useState<boolean>(false);
const { auth } = useChrome();
const isITLess = useFlag('platform.chrome.itless');

if (!isITLess) {
return <NotFoundRoute />;
}

useEffect(() => {
auth.getUser().then((user) => user && setIsOrgAdmin(!!user?.identity?.user?.is_org_admin));
}, []);

const generateToken = () => {
axios
.get('/api/identity/certificate/token')
Expand Down Expand Up @@ -90,7 +95,7 @@ const SatelliteToken: React.FC = () => {
</CardBody>
</Card>
</PageSection>
{user.identity.user?.is_org_admin ? (
{isOrgAdmin ? (
<PageSection>
<Card>
<CardTitle>IP Address Allow List</CardTitle>
Expand Down

0 comments on commit 4c85a8d

Please sign in to comment.