Skip to content

Commit

Permalink
Merge pull request #216 from siemens/fix/project_vulnerabilities
Browse files Browse the repository at this point in the history
fix(project_vulnerabilities): Get vulnerabilities of linked projects aswell
  • Loading branch information
heliocastro authored Feb 27, 2024
2 parents 5e8763c + 19d05e7 commit 60a70a6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,32 @@

'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'
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<ProjectData[]>([])
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions src/object-types/ProjectVulnerabilityTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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[]
}
}
3 changes: 2 additions & 1 deletion src/object-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -99,6 +99,7 @@ export type {
ProjectPayload,
ECC,
ProjectVulnerability,
ProjectsPayloadElement,
Release,
ReleaseDetail,
ReleaseLink,
Expand Down

0 comments on commit 60a70a6

Please sign in to comment.