From 19d05e7f1264235e9dd559cde1f86740ff875f5c Mon Sep 17 00:00:00 2001 From: deo002 Date: Tue, 13 Feb 2024 13:15:14 +0530 Subject: [PATCH] fix(project_vulnerabilities): Get vulnerabilities of linked projects as well --- .../components/ProjectVulnerabilities.tsx | 31 +++++++++++++------ src/object-types/ProjectVulnerabilityTypes.ts | 13 ++++++++ src/object-types/index.ts | 3 +- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/app/[locale]/projects/detail/[id]/components/ProjectVulnerabilities.tsx b/src/app/[locale]/projects/detail/[id]/components/ProjectVulnerabilities.tsx index 4bec3f715..ba105c660 100644 --- a/src/app/[locale]/projects/detail/[id]/components/ProjectVulnerabilities.tsx +++ b/src/app/[locale]/projects/detail/[id]/components/ProjectVulnerabilities.tsx @@ -9,7 +9,7 @@ 'use client' -import { HttpStatus, ProjectData } from '@/object-types' +import { HttpStatus, ProjectData, ProjectsPayloadElement } from '@/object-types' import { ApiUtils } from '@/utils' import { signOut, useSession } from 'next-auth/react' import { notFound } from 'next/navigation' @@ -17,6 +17,24 @@ import { useEffect, useState } from 'react' import { Tab, Tabs } from 'react-bootstrap' import VulnerabilityTab from './VulnerabilityTab' +const extractLinkedProjects = (projectPayload: ProjectsPayloadElement[], projectData: ProjectData[]) => { + if(!projectPayload) { + return + } + for (const x of projectPayload) { + projectData.push({ + id: x['_links']['self']['href'].substring(x['_links']['self']['href'].lastIndexOf('/') + 1), + name: x.name, + version: x.version, + enableSvm: x.enableSvm, + enableVulnerabilitiesDisplay: x.enableVulnerabilitiesDisplay, + }) + if(x._embedded?.['sw360:linkedProjects']) { + extractLinkedProjects(x._embedded?.['sw360:linkedProjects'], projectData) + } + } +} + export default function ProjectVulnerabilities({ projectData }: { projectData: ProjectData }) { const { data: session, status } = useSession() const [data, setData] = useState([]) @@ -45,15 +63,8 @@ export default function ProjectVulnerabilities({ projectData }: { projectData: P const d: ProjectData[] = [] d.push(projectData) - for (const x of data?.['_embedded']?.['sw360:projects'] ?? ([] as any[])) { - d.push({ - id: x['_links']['self']['href'].substring(x['_links']['self']['href'].lastIndexOf('/') + 1), - name: x.name, - version: x.version, - enableSvm: x.enableSvm, - enableVulnerabilitiesDisplay: x.enableVulnerabilitiesDisplay, - }) - } + extractLinkedProjects(data._embedded?.['sw360:projects'], d) + setData(d) } catch (e) { console.error(e) diff --git a/src/object-types/ProjectVulnerabilityTypes.ts b/src/object-types/ProjectVulnerabilityTypes.ts index b44d9cecc..6d20047be 100644 --- a/src/object-types/ProjectVulnerabilityTypes.ts +++ b/src/object-types/ProjectVulnerabilityTypes.ts @@ -7,6 +7,8 @@ // SPDX-License-Identifier: EPL-2.0 // License-Filename: LICENSE +import { Links } from '@/object-types' + export interface ProjectData { id: string name: string @@ -30,3 +32,14 @@ export interface ProjectVulnerability { intReleaseName: string description: string } + +export interface ProjectsPayloadElement { + name?: string + enableSvm?: boolean + version?: string + enableVulnerabilitiesDisplay: boolean + _links?: Links + _embedded?: { + 'sw360:linkedProjects': ProjectsPayloadElement[] + } +} diff --git a/src/object-types/index.ts b/src/object-types/index.ts index 696e244bd..fa9beedc8 100644 --- a/src/object-types/index.ts +++ b/src/object-types/index.ts @@ -43,7 +43,7 @@ import Preferences from './Preferences' import Project from './Project' import ProjectPayload from './ProjectPayload' import ECC from './ECC' -import { ProjectData, ProjectVulnerability } from './ProjectVulnerabilityTypes' +import { ProjectData, ProjectVulnerability, ProjectsPayloadElement } from './ProjectVulnerabilityTypes' import Release from './Release' import ReleaseDetail from './ReleaseDetail' import ReleaseLink from './ReleaseLink' @@ -99,6 +99,7 @@ export type { ProjectPayload, ECC, ProjectVulnerability, + ProjectsPayloadElement, Release, ReleaseDetail, ReleaseLink,