Skip to content

Commit

Permalink
Add bot permissions and turn on feature (#37943)
Browse files Browse the repository at this point in the history
  • Loading branch information
michellescripts committed Feb 16, 2024
1 parent 27fddda commit 967674e
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 8 deletions.
5 changes: 4 additions & 1 deletion web/packages/teleport/src/Bots/List/ActionCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function BotOptionsCell({
onClickView,
bot,
disabledEdit,
disabledDelete,
onClickEdit,
}: BotOptionsCellProps) {
return (
Expand All @@ -36,7 +37,9 @@ export function BotOptionsCell({
<MenuItem onClick={onClickEdit} disabled={disabledEdit}>
Edit...
</MenuItem>
<MenuItem onClick={onClickDelete}>Delete...</MenuItem>
<MenuItem onClick={onClickDelete} disabled={disabledDelete}>
Delete...
</MenuItem>
{bot.type === BotUiFlow.GitHubActionsSsh && (
<MenuItem onClick={onClickView}>View...</MenuItem>
)}
Expand Down
1 change: 1 addition & 0 deletions web/packages/teleport/src/Bots/List/BotList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const makeProps = (): BotListProps => ({
attempt: { status: '' },
bots: botsFixture,
disabledEdit: false,
disabledDelete: false,
onClose: () => {},
onDelete: () => {},
onEdit: () => {},
Expand Down
2 changes: 2 additions & 0 deletions web/packages/teleport/src/Bots/List/BotList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export function BotList({
attempt,
bots,
disabledEdit,
disabledDelete,
roles,
onClose,
onDelete,
Expand Down Expand Up @@ -78,6 +79,7 @@ export function BotList({
setInteraction(Interaction.VIEW);
}}
disabledEdit={disabledEdit}
disabledDelete={disabledDelete}
onClickEdit={() => {
setSelectedBot(bot);
setSelectedRoles(bot.roles);
Expand Down
1 change: 1 addition & 0 deletions web/packages/teleport/src/Bots/List/Bots.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const List = () => {
attempt={{ status: '' }}
bots={botsFixture}
disabledEdit={false}
disabledDelete={false}
onClose={() => {}}
onDelete={() => {}}
onEdit={() => {}}
Expand Down
3 changes: 2 additions & 1 deletion web/packages/teleport/src/Bots/List/Bots.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ export function Bots() {
<BotList
attempt={crudAttempt}
bots={bots}
disabledEdit={!flags.roles}
disabledEdit={!flags.roles || !flags.editBots}
disabledDelete={!flags.removeBots}
roles={roles}
onClose={onClose}
onDelete={onDelete}
Expand Down
2 changes: 2 additions & 0 deletions web/packages/teleport/src/Bots/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { FlatBot } from 'teleport/services/bot/types';
export type BotOptionsCellProps = {
bot: FlatBot;
disabledEdit: boolean;
disabledDelete: boolean;
onClickEdit: (bot: FlatBot) => void;
onClickDelete: (bot: FlatBot) => void;
onClickView: (bot: FlatBot) => void;
Expand All @@ -32,6 +33,7 @@ export type BotListProps = {
attempt: Attempt;
bots: FlatBot[];
disabledEdit: boolean;
disabledDelete: boolean;
roles: string[];
onClose: () => void;
onDelete: () => void;
Expand Down
5 changes: 2 additions & 3 deletions web/packages/teleport/src/features.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,8 @@ export class FeatureBots implements TeleportFeature {
component: Bots,
};

// todo (michellescripts) return flags.Users once integrated with mcbattirola and feature is ready
hasAccess() {
return false;
hasAccess(flags: FeatureFlags) {
return flags.listBots;
}

navigationItem = {
Expand Down
6 changes: 3 additions & 3 deletions web/packages/teleport/src/services/bot/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function fetchBots(
signal: AbortSignal,
flags: FeatureFlags
): Promise<BotList> {
if (!flags.users) {
if (!flags.listBots) {
return;
}

Expand Down Expand Up @@ -89,7 +89,7 @@ export function editBot(
name: string,
req: EditBotRequest
): Promise<FlatBot> {
if (!flags.users || !flags.roles) {
if (!flags.editBots || !flags.roles) {
return;
}

Expand All @@ -99,7 +99,7 @@ export function editBot(
}

export function deleteBot(flags: FeatureFlags, name: string) {
if (!flags.users) {
if (!flags.removeBots) {
return;
}

Expand Down
4 changes: 4 additions & 0 deletions web/packages/teleport/src/teleportContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ class TeleportContext implements types.Context {
externalAuditStorage: userContext.getExternalAuditStorageAccess().list,
listBots: userContext.getBotsAccess().list,
addBots: userContext.getBotsAccess().create,
editBots: userContext.getBotsAccess().edit,
removeBots: userContext.getBotsAccess().remove,
};
}
}
Expand Down Expand Up @@ -253,6 +255,8 @@ export const disabledFeatureFlags: types.FeatureFlags = {
externalAuditStorage: false,
addBots: false,
listBots: false,
editBots: false,
removeBots: false,
};

export default TeleportContext;
2 changes: 2 additions & 0 deletions web/packages/teleport/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ export interface FeatureFlags {
externalAuditStorage: boolean;
listBots: boolean;
addBots: boolean;
editBots: boolean;
removeBots: boolean;
}

// LockedFeatures are used for determining which features are disabled in the user's cluster.
Expand Down

0 comments on commit 967674e

Please sign in to comment.