Skip to content

Commit

Permalink
fix: Redirect if user doesnt have permissions (#2353)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleixhub authored Jan 15, 2025
1 parent 137cad5 commit a200951
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions catalog/ui/src/app/Catalog/CatalogItemForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useMemo, useReducer, useState } from 'react';
import { Link, useNavigate, useParams } from 'react-router-dom';
import { Link, Navigate, useNavigate, useParams } from 'react-router-dom';
import parseDuration from 'parse-duration';
import { EditorState } from 'lexical/LexicalEditorState';
import { LexicalEditor } from 'lexical/LexicalEditor';
Expand Down Expand Up @@ -38,7 +38,7 @@ import {
saveExternalItemRequest,
} from '@app/api';
import { CatalogItem, TPurposeOpts } from '@app/types';
import { displayName, getStageFromK8sObject, isLabDeveloper, randomString } from '@app/util';
import { checkAccessControl, displayName, getStageFromK8sObject, isLabDeveloper, randomString } from '@app/util';
import Editor from '@app/components/Editor/Editor';
import useSession from '@app/utils/useSession';
import useDebounce from '@app/utils/useDebounce';
Expand Down Expand Up @@ -74,6 +74,7 @@ const CatalogItemFormData: React.FC<{ catalogItemName: string; catalogNamespaceN
apiPaths.CATALOG_ITEM({ namespace: catalogNamespaceName, name: catalogItemName }),
fetcher
);

const _displayName = displayName(catalogItem);
const estimatedCost = useMemo(() => getEstimatedCost(catalogItem), []);
const [userRegistrationSelectIsOpen, setUserRegistrationSelectIsOpen] = useState(false);
Expand Down Expand Up @@ -225,6 +226,10 @@ const CatalogItemFormData: React.FC<{ catalogItemName: string; catalogNamespaceN
setIsLoading(false);
}

if ('deny' === checkAccessControl(catalogItem.spec.accessControl, groups, isAdmin)) {
return <Navigate to="/" replace />;
}

return (
<PageSection variant={PageSectionVariants.light} className="catalog-item-form">
<CatalogItemFormAutoStopDestroyModal
Expand Down

0 comments on commit a200951

Please sign in to comment.