Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Fix protected directory #77

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ const DirectoryTreeView: React.FC<DirectoryTreeViewProps> = (props) => {
}}
callbacks={props.callbacks}
remoteRootNode={node.remoteRootNode}
cannotDelete={!node.custom || node.rootNode}
>
<Typography.Text
style={{ maxWidth: 150 - 10 * node.depth }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type PlaybookDropdownMenuType = {
};

type PlaybookDrownMenuItemType = {
fileType: DirectoryTree.CONSTANTS | 'any';
fileType: DirectoryTree.CONSTANTS | 'any' | 'deletable';
playbookQuickRef?: string;
icon?: React.JSX.Element;
label: string;
Expand All @@ -49,7 +49,7 @@ const menuItems: PlaybookDrownMenuItemType[] = [
label: 'Delete',
icon: <DeleteOutlined />,
key: '3',
fileType: 'any',
fileType: 'deletable',
},
];

Expand All @@ -73,7 +73,7 @@ const PlaybookDropdownMenu: React.FC<PlaybookDropdownMenuType> = (props) => {
const items = menuItems
.filter(
(e) =>
(e.fileType === 'any' && !props.cannotDelete) ||
(e.fileType === 'deletable' && !props.cannotDelete) ||
e.fileType === props.type,
)
.map((e) => {
Expand Down
14 changes: 12 additions & 2 deletions client/src/pages/Playbooks/components/TreeComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import {
SimpleIconsGit,
StreamlineLocalStorageFolderSolid,
} from '@/components/Icons/CustomIcons';
import { Typography } from 'antd';
import React, { ReactNode } from 'react';
import {
API,
DirectoryTree,
DirectoryTree as DT,
Playbooks,
} from 'ssm-shared-lib';
import PlaybookDropdownMenu from './PlaybookDropdownMenu';

export type ClientPlaybooksTrees = {
isLeaf?: boolean;
Expand Down Expand Up @@ -83,11 +81,21 @@ export function recursiveTreeTransform(
key: child.path,
_name: child.name,
nodeType: child.type,
rootNode: false,
playbookRepository: {
basePath: playbookRepository.basePath,
name: playbookRepository.name,
uuid: playbookRepository.uuid,
},
// TODO ugly fix to prevent user breaking the system
custom:
(child as DirectoryTree.ExtendedTreeNode).custom === undefined &&
!child.path.includes(
'/server/src/ansible/00000000-0000-0000-0000-000000000000/agent',
) &&
!child.path.includes(
'/server/src/ansible/00000000-0000-0000-0000-000000000000/device',
),
depth: depth,
selectable: false,
children: recursiveTreeTransform(
Expand All @@ -102,6 +110,7 @@ export function recursiveTreeTransform(
key: child.path,
_name: child.name,
nodeType: DirectoryTree.CONSTANTS.FILE,
rootNode: false,
playbookRepository: {
basePath: playbookRepository.basePath,
name: playbookRepository.name,
Expand All @@ -120,6 +129,7 @@ export function recursiveTreeTransform(
newTree.push({
key: node.path,
_name: node.name,
rootNode: false,
nodeType: DirectoryTree.CONSTANTS.FILE,
playbookRepository: {
basePath: playbookRepository.basePath,
Expand Down