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

Feature/edit findings audit #163

Merged
merged 58 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
18fd4dc
feat: add new service - getFinding
iTzGooDLife Oct 28, 2024
22cf04f
feat: base edit finding
iTzGooDLife Oct 28, 2024
07c580f
feat: add new fields and components separation
iTzGooDLife Oct 29, 2024
d40c35a
add new components
iTzGooDLife Oct 30, 2024
dc64794
feat: improve navigation bar and its render
iTzGooDLife Oct 30, 2024
44c8c14
feat: add proofs tab frontend and details component
iTzGooDLife Oct 30, 2024
27bc49b
feat: add new tabs and its logic; feat: add frontend delete and save …
iTzGooDLife Nov 2, 2024
a9dc63b
feat: add logic to cwes submit recommendation
iTzGooDLife Nov 2, 2024
1b640de
feat: fix eslint errors in onChange functions
iTzGooDLife Nov 2, 2024
83d8be9
feat: add array support in fields
iTzGooDLife Nov 2, 2024
3c7ecfa
chore: remove unused types
iTzGooDLife Nov 2, 2024
816b310
feat: add new translation for error at deleting finding
iTzGooDLife Nov 2, 2024
67e1d08
feat: add logic for finding removal
iTzGooDLife Nov 2, 2024
ebacac9
feat: add update finding service
iTzGooDLife Nov 2, 2024
9d63ece
feat: implement update finding logic
iTzGooDLife Nov 2, 2024
f4dc62e
feat: add title required on edit findings
iTzGooDLife Nov 2, 2024
7d5f067
fix: cvss dependency render issue
iTzGooDLife Nov 2, 2024
9830300
feat: load new fields of findings at change using sidebar
iTzGooDLife Nov 2, 2024
c056159
feat: sort imports detailstab
iTzGooDLife Nov 2, 2024
e79cf4b
feat: add vuln type if the type is not in the list
iTzGooDLife Nov 2, 2024
1e47386
chore: remove unused state modificator
iTzGooDLife Nov 3, 2024
59ae674
feature: add providers to use props in outlet components
iTzGooDLife Nov 3, 2024
7549ec5
feature: implement providers in AuditRoot
iTzGooDLife Nov 3, 2024
b7a0a2d
feature: use props from AuditRoot
iTzGooDLife Nov 3, 2024
2daeb0c
feature: filter type only in current language
iTzGooDLife Nov 3, 2024
9da81a6
feature: typo i18 label
iTzGooDLife Nov 3, 2024
4cacc62
feature: add handler to update findings sidebar
iTzGooDLife Nov 3, 2024
add727f
fix: add handler missing in the previous commit
iTzGooDLife Nov 3, 2024
d835577
fix: implement handler to update findings
iTzGooDLife Nov 3, 2024
6d73315
feat: add navigate after delete finding
iTzGooDLife Nov 3, 2024
d606e4c
feat: refresh findings after add a new one
iTzGooDLife Nov 3, 2024
3729a1a
fix: change fetchTypes to a callback
iTzGooDLife Nov 3, 2024
f08b5cd
feat: add check icon sidebaraudit if status is 0
iTzGooDLife Nov 3, 2024
a530adb
feat: add frontend status switch and its logic
iTzGooDLife Nov 3, 2024
ee7cb18
fix: add missing prop in findings - status
iTzGooDLife Nov 3, 2024
224a315
feat: update switch correctly and fetch findings after update
iTzGooDLife Nov 3, 2024
efd2daa
feat: move the constant out of the component
iTzGooDLife Nov 3, 2024
1f4c3dc
feat: refresh remediationComplexity and priority at change of finding
iTzGooDLife Nov 3, 2024
c84534f
fix: onChange ListItem issue with ids
iTzGooDLife Nov 3, 2024
0f3ef53
fix: add identifier as key to render cvss
iTzGooDLife Nov 3, 2024
e11887f
chore: refactor fetchFinding to reduce cognitive complexity
iTzGooDLife Nov 3, 2024
4c47018
feature: add loading icon and reorganization of edit component
iTzGooDLife Nov 3, 2024
8e55dbd
chore: order imports
iTzGooDLife Nov 3, 2024
0e317b6
chore: remove TODO and update state cwe before recommendation
iTzGooDLife Nov 3, 2024
295f778
fix: only parse in parseCVSSVector if part is not empty
iTzGooDLife Nov 3, 2024
e3bd7bf
chore: completed TODOs are removed
iTzGooDLife Nov 3, 2024
f42430b
feature: add multi language support to cwe recommendation
iTzGooDLife Nov 3, 2024
0954737
Merge branch 'development' into feature/edit-findings-audit
iTzGooDLife Nov 3, 2024
2d85a7b
fix: remove unused props
iTzGooDLife Nov 3, 2024
610e0ab
fix: remove redundant types on props
iTzGooDLife Nov 4, 2024
4959bee
fix: remove unused prop ListItem
iTzGooDLife Nov 4, 2024
de09bd1
fix: change padding to margin to improve consistency
iTzGooDLife Nov 4, 2024
bf0e9ef
fix: change name textArea from poc to references
iTzGooDLife Nov 4, 2024
ab83bdc
feat: add refresh findings on sidebar at add findings from New Vulner…
iTzGooDLife Nov 5, 2024
e007929
Merge branch 'development' into feature/edit-findings-audit
iTzGooDLife Nov 5, 2024
6cade2f
fix: issue during build caused by change in Finding Type
iTzGooDLife Nov 6, 2024
efdb0e1
feat: align title and completed switch
iTzGooDLife Nov 6, 2024
4247b88
Merge branch 'development' into feature/edit-findings-audit
iTzGooDLife Nov 6, 2024
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
7 changes: 7 additions & 0 deletions frontend/src/components/navbar/AuditSidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable import/extensions */
/* eslint-disable sonarjs/no-duplicate-string */
import { CheckIcon } from '@heroicons/react/20/solid';
import clsx from 'clsx';
import { t } from 'i18next';
import {
Expand Down Expand Up @@ -34,6 +35,7 @@ type Finding = {
category: string;
severity: string;
identifier: string;
status: number;
};

type SortOption = {
Expand Down Expand Up @@ -313,6 +315,11 @@ const AuditSidebar = ({
>
{finding.name}
</span>
{finding.status === 0 && !isCollapsed ? (
<span>
<CheckIcon className="h-6 w-6 text-gray-500" />
</span>
) : null}
</li>
</Link>
))}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/i18n/en-US/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export default {
passwordsDontMatch: 'Passwords do not match',
errorGeneratingPdf: 'Failed exporting audit to pdf',
errorSavingAuditCustomSections: 'Failed saving the audit custom sections',
failedDeleteFinding: 'Failed to delete the finding',
createUser: 'Error creating user',
confirmPasswordDifferents: 'Passwords do not match',
},
Expand Down
41 changes: 41 additions & 0 deletions frontend/src/routes/audits/edit/AuditContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React, { createContext } from 'react';

type FindingType = {
id: number;
name: string;
category: string;
severity: string;
identifier: string;
status: number;
};

type AuditContextType = {
title: string;
auditType: string;
locale: string;
handlerFindings: () => Promise<FindingType[]>;
};

const defaultContextValue: AuditContextType = {
title: '',
auditType: '',
locale: '',
handlerFindings: () => Promise.resolve([]),
};

type AuditContextProps = {
children: React.ReactNode;
value: AuditContextType;
};

export const AuditContext =
createContext<AuditContextType>(defaultContextValue);

export const AuditProvider: React.FC<AuditContextProps> = ({
children,
value,
}) => {
return (
<AuditContext.Provider value={value}>{children}</AuditContext.Provider>
);
};
40 changes: 39 additions & 1 deletion frontend/src/routes/audits/edit/AuditRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getCustomSections, Section } from '@/services/data';

import AuditSidebar from '../../../components/navbar/AuditSidebar';
import { AuditSection, Finding, getAuditById } from '../../../services/audits';
import { AuditProvider } from './AuditContext';

export const AuditRoot = () => {
const { t } = useTranslation();
Expand All @@ -27,6 +28,7 @@ export const AuditRoot = () => {
category: string;
severity: string;
identifier: string;
status: number;
}[]
>([]);

Expand Down Expand Up @@ -70,6 +72,9 @@ export const AuditRoot = () => {
const [auditSections, setAuditSections] = useState<AuditSection[]>([]);
const [sections, setSections] = useState<Section[]>([]);
const [isListVisible, setIsListVisible] = useState(false);
const [nameAudit, setNameAudit] = useState<string>('');
const [auditType, setAuditType] = useState<string>('');
const [currentLanguage, setCurrentLanguage] = useState<string>('');

useEffect(() => {
getCustomSections()
Expand Down Expand Up @@ -108,12 +113,18 @@ export const AuditRoot = () => {
return {
id: finding.identifier,
name: finding.title,
//TODO: Change hardcoded category to the real category
category: 'No Category',
severity: cvssStringToSeverity(finding.cvssv3),
identifier: finding._id,
status: finding.status,
};
}),
);
// handlerFindings(audit.datas.findings);
setNameAudit(audit.datas.name);
setAuditType(audit.datas.auditType);
setCurrentLanguage(audit.datas.language);
})
.catch(console.error);
}, [auditId, sections]);
Expand All @@ -127,6 +138,31 @@ export const AuditRoot = () => {

const connectedUsers: { id: number; name: string; online: boolean }[] = [];

const handlerFindings = async () => {
try {
const audit = await getAuditById(auditId);
const findingsData = audit.datas.findings.map((findingIter: Finding) => ({
id: findingIter.identifier,
name: findingIter.title,
category: 'No Category',
severity: cvssStringToSeverity(findingIter.cvssv3),
identifier: findingIter._id,
status: findingIter.status,
}));
setFindings(findingsData);
return findingsData;
} catch (error) {
console.error(error);
return [];
}
};

const auditData = {
title: nameAudit,
auditType,
locale: currentLanguage,
};

return (
<div className="flex overflow-hidden">
<AuditSidebar
Expand All @@ -149,7 +185,9 @@ export const AuditRoot = () => {
sortOrderOptions={sortOrderOptions}
/>
<div className="flex-1 overflow-auto">
<Outlet />
<AuditProvider value={{ ...auditData, handlerFindings }}>
<Outlet />
</AuditProvider>
</div>
</div>
);
Expand Down
38 changes: 22 additions & 16 deletions frontend/src/routes/audits/edit/findings/add/add.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
getLanguages,
getVulnByLanguage,
} from '../../../../../services/audits';
import { useAuditContext } from '../../useAuditContext';
import DivWrapper from './DivWrapper';
import NewVulnButton from './NewVulnButton';

Expand All @@ -42,6 +43,8 @@ let dataLanguage: { status: string; datas: Language[] } = {
datas: [],
};
export const Add = () => {
const { handlerFindings } = useAuditContext();

const [languages, setLanguages] = useState<ListItem[]>([]);
const [currentLanguage, setCurrentLanguage] = useState<ListItem | null>(null);
const [loadingLanguages, setLoadingLanguages] = useState<boolean>(true);
Expand Down Expand Up @@ -130,23 +133,26 @@ export const Add = () => {
}, [currentLanguage, setTableData, dataLanguage]);

const handleAddVuln = useCallback(
(item: TableData) => {
addVuln(
item.id,
auditId ?? '',
currentLanguage ? currentLanguage.value : 'en',
)
.then(res => {
if (res.status === 'success') {
setNewVulnTitle('');
toast.success(t('msg.findingCreateOk'));
} else {
toast.error(res.datas);
}
})
.catch(console.error);
async (item: TableData) => {
try {
const res = await addVuln(
item.id,
auditId ?? '',
currentLanguage ? currentLanguage.value : 'en',
);

if (res.status === 'success') {
setNewVulnTitle('');
toast.success(t('msg.findingCreateOk'));
await handlerFindings();
} else {
toast.error(res.datas);
}
} catch (error) {
console.error(error);
}
},
[auditId, currentLanguage],
[auditId, currentLanguage, handlerFindings],
);

const rowActions = [
Expand Down
Loading