Skip to content

Commit

Permalink
Disable Enroll New Integration button on missing permissions
Browse files Browse the repository at this point in the history
This will disable to Enroll New Integration button if the user does not
have the required permissions.

It also updates the MissingPermissionsTooltip to handle cases where a
list of permissions represents "one of these" required permissions
scenarios instead of "all of these".
  • Loading branch information
avatus committed Dec 12, 2024
1 parent 2c82b83 commit 3eaedeb
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,22 @@ import { Box, Text, Flex } from 'design';

export const MissingPermissionsTooltip = ({
missingPermissions,
requiresAll = true,
}: {
missingPermissions: string[];
requiresAll?: boolean;
}) => {
return (
<Box>
<Text mb={1}>You do not have all of the required permissions.</Text>
<Box mb={1}>
<Text bold>Missing permissions:</Text>
{requiresAll ? (
<Text bold>Missing permissions:</Text>
) : (
<Text bold>
You must have at least one of these role permissions:
</Text>
)}
<Flex gap={2}>
{missingPermissions.map(perm => (
<Text key={perm}>{perm}</Text>
Expand Down
10 changes: 8 additions & 2 deletions web/packages/teleport/src/Integrations/Integrations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export function Integrations() {
const { attempt, run } = useAttempt('processing');

const ctx = useTeleport();
const canCreateIntegrations = ctx.storeUser.getIntegrationsAccess().create;

useEffect(() => {
// TODO(lisa): handle paginating as a follow up polish.
Expand Down Expand Up @@ -82,7 +81,14 @@ export function Integrations() {
<FeatureBox>
<FeatureHeader>
<FeatureHeaderTitle>Integrations</FeatureHeaderTitle>
<IntegrationsAddButton canCreate={canCreateIntegrations} />
<IntegrationsAddButton
requiredPermissions={[
{
value: ctx.storeUser.getIntegrationsAccess().create,
label: 'integration.create',
},
]}
/>
</FeatureHeader>
{attempt.status === 'failed' && <Alert children={attempt.statusText} />}
{attempt.status === 'processing' && (
Expand Down
48 changes: 35 additions & 13 deletions web/packages/teleport/src/Integrations/IntegrationsAddButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,48 @@
import React from 'react';
import { Link } from 'react-router-dom';
import { Button } from 'design';
import { HoverTooltip } from 'design/Tooltip';
import { MissingPermissionsTooltip } from 'shared/components/MissingPermissionsTooltip';

import cfg from 'teleport/config';

export function IntegrationsAddButton({
canCreate = false,
requiredPermissions,
}: {
canCreate: boolean;
requiredPermissions: { value: boolean; label: string }[];
}) {
const canCreateIntegrations = requiredPermissions.some(v => v.value);
const missingPermissions = requiredPermissions
.filter(perm => !perm.value)
.map(perm => perm.label);

return (
<Button
intent="primary"
fill="border"
as={Link}
ml="auto"
width="240px"
disabled={!canCreate}
to={cfg.getIntegrationEnrollRoute()}
title={canCreate ? '' : 'You do not have access to add new integrations'}
<HoverTooltip
tipContent={
canCreateIntegrations ? null : (
<MissingPermissionsTooltip
requiresAll={false}
missingPermissions={missingPermissions}
/>
)
}
>
Enroll New Integration
</Button>
<Button
intent="primary"
fill="border"
as={Link}
ml="auto"
width="240px"
disabled={!canCreateIntegrations}
to={cfg.getIntegrationEnrollRoute()}
title={
canCreateIntegrations
? ''
: 'You do not have access to add new integrations'
}
>
Enroll New Integration
</Button>
</HoverTooltip>
);
}
4 changes: 2 additions & 2 deletions web/packages/teleport/src/features.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,8 @@ export class FeatureIntegrations implements TeleportFeature {
category = NavigationCategory.Management;
section = ManagementSection.Access;

hasAccess(flags: FeatureFlags) {
return flags.integrations;
hasAccess() {
return true;
}

route = {
Expand Down

0 comments on commit 3eaedeb

Please sign in to comment.