diff --git a/src/components/ImportForm/utils/cdq-utils.ts b/src/components/ImportForm/utils/cdq-utils.ts index 9a607dea8..a6abe39ae 100644 --- a/src/components/ImportForm/utils/cdq-utils.ts +++ b/src/components/ImportForm/utils/cdq-utils.ts @@ -148,10 +148,15 @@ export const detectComponents = async ( throw new Error(completeCondition.message); } } finally { - await k8sDeleteResource({ - model: ComponentDetectionQueryModel, - queryOptions: { name: cdq.metadata.name, ns: namespace }, - }); + try { + await k8sDeleteResource({ + model: ComponentDetectionQueryModel, + queryOptions: { name: cdq.metadata.name, ns: namespace }, + }); + } catch (e) { + // eslint-disable-next-line no-console + console.error(`Unable to delete CDQ ${cdq.metadata.name}: `, e); + } } return cdq.status.componentDetected; diff --git a/src/components/Overview/IntroBanner.tsx b/src/components/Overview/IntroBanner.tsx index d9f05d44c..6c8532a41 100644 --- a/src/components/Overview/IntroBanner.tsx +++ b/src/components/Overview/IntroBanner.tsx @@ -14,10 +14,15 @@ import { } from '@patternfly/react-core'; import { FULL_APPLICATION_TITLE } from '../../consts/labels'; import { useSignupStatus } from '../../hooks/useSignupStatus'; -import { ApplicationGroupVersionKind, ApplicationModel, ComponentModel } from '../../models'; +import { + ApplicationGroupVersionKind, + ApplicationModel, + ComponentDetectionQueryModel, + ComponentModel, +} from '../../models'; import ExternalLink from '../../shared/components/links/ExternalLink'; -import { ApplicationKind } from '../../types'; -import { useAccessReviewForModel } from '../../utils/rbac'; +import { AccessReviewResources, ApplicationKind } from '../../types'; +import { useAccessReviewForModels } from '../../utils/rbac'; import { SignupStatus } from '../../utils/signup-utils'; import { useWorkspaceInfo } from '../../utils/workspace-context-utils'; import { ButtonWithAccessTooltip } from '../ButtonWithAccessTooltip'; @@ -25,10 +30,15 @@ import SignupButton from './SignupButton'; import './IntroBanner.scss'; +const accessReviewResources: AccessReviewResources = [ + { model: ApplicationModel, verb: 'create' }, + { model: ComponentModel, verb: 'create' }, + { model: ComponentDetectionQueryModel, verb: 'create' }, +]; + const IntroBanner: React.FC> = () => { const { namespace, workspace } = useWorkspaceInfo(); - const [canCreateApplication] = useAccessReviewForModel(ApplicationModel, 'create'); - const [canCreateComponent] = useAccessReviewForModel(ComponentModel, 'create'); + const [canCreate] = useAccessReviewForModels(accessReviewResources); const signupStatus = useSignupStatus(); @@ -69,7 +79,7 @@ const IntroBanner: React.FC> = () => { )} variant="primary" data-test="create-application" - isDisabled={!(canCreateApplication && canCreateComponent)} + isDisabled={!canCreate} tooltip="You don't have access to create an application" size="lg" analytics={{ diff --git a/src/components/Overview/__tests__/IntroBanner.spec.tsx b/src/components/Overview/__tests__/IntroBanner.spec.tsx index 5316955ee..ccb6d56b9 100644 --- a/src/components/Overview/__tests__/IntroBanner.spec.tsx +++ b/src/components/Overview/__tests__/IntroBanner.spec.tsx @@ -29,7 +29,7 @@ jest.mock('react-router-dom', () => { }); jest.mock('../../../utils/rbac', () => ({ - useAccessReviewForModel: jest.fn(() => [true, true]), + useAccessReviewForModels: jest.fn(() => [true, true]), })); const useK8sWatchResourceMock = useK8sWatchResource as jest.Mock; diff --git a/src/pages/ImportPage.tsx b/src/pages/ImportPage.tsx index 95061d2dc..02559b03d 100644 --- a/src/pages/ImportPage.tsx +++ b/src/pages/ImportPage.tsx @@ -3,7 +3,7 @@ import ImportForm from '../components/ImportForm/ImportForm'; import NamespacedPage from '../components/NamespacedPage/NamespacedPage'; import PageAccessCheck from '../components/PageAccess/PageAccessCheck'; import { useQuickstartCloseOnUnmount } from '../hooks/useQuickstartCloseOnUnmount'; -import { ApplicationModel, ComponentModel } from '../models'; +import { ApplicationModel, ComponentDetectionQueryModel, ComponentModel } from '../models'; import { getQueryArgument } from '../shared/utils'; import { AccessReviewResources } from '../types'; @@ -13,10 +13,14 @@ const ImportPage: React.FunctionComponent> = () const applicationName = getQueryArgument('application'); const accessReviewResources: AccessReviewResources = applicationName - ? [{ model: ComponentModel, verb: 'create' }] + ? [ + { model: ComponentModel, verb: 'create' }, + { model: ComponentDetectionQueryModel, verb: 'create' }, + ] : [ { model: ApplicationModel, verb: 'create' }, { model: ComponentModel, verb: 'create' }, + { model: ComponentDetectionQueryModel, verb: 'create' }, ]; return (