Skip to content

Commit

Permalink
feat: add spdx links
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdlangton committed Oct 2, 2024
1 parent f002826 commit 7ced501
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 30 deletions.
2 changes: 1 addition & 1 deletion functions/cdx/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function onRequestGet(context) {
return Response.json({ ok: false, result: verificationResult.message })
}
const { searchParams } = new URL(request.url)
const take = parseInt(searchParams.get('take'), 10) || 25
const take = parseInt(searchParams.get('take'), 10) || 50
const skip = parseInt(searchParams.get('skip'), 10) || 0
const cdx = await prisma.CycloneDXInfo.findMany({
where: {
Expand Down
2 changes: 1 addition & 1 deletion functions/sarif/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function onRequestGet(context) {
return Response.json({ ok: false, result: verificationResult.message })
}
const { searchParams } = new URL(request.url)
const take = parseInt(searchParams.get('take'), 10) || 25
const take = parseInt(searchParams.get('take'), 10) || 50
const skip = parseInt(searchParams.get('skip'), 10) || 0
const sarif = await prisma.SARIFInfo.findMany({
where: {
Expand Down
53 changes: 42 additions & 11 deletions functions/spdx/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,62 @@ export async function onRequestGet(context) {
return Response.json({ ok: false, result: verificationResult.message })
}
const { searchParams } = new URL(request.url)
const take = parseInt(searchParams.get('take'), 10) || 25
const take = parseInt(searchParams.get('take'), 10) || 50
const skip = parseInt(searchParams.get('skip'), 10) || 0
const spdx = await prisma.SPDXInfo.findMany({
let spdx = await prisma.SPDXInfo.findMany({
where: {
orgId: verificationResult.session.orgId,
},
include: {
select: {
spdxId: true,
source: true,
repoName: true,
artifactUuid: true,
spdxVersion: true,
name: true,
createdAt: true,
toolName: true,
packagesCount: true,
artifact: {
include: {
downloadLinks: true
select: {
downloadLinks: {
select: {
url: true,
}
}
}
}
},
omit: {
memberEmail: true,
comment: true,
documentNamespace: true,
documentDescribes: true,
},
take,
skip,
orderBy: {
createdAt: 'desc',
},
})

const repos = await prisma.gitRepo.findMany({
where: {
fullName: { in: spdx.map(s => s?.repoName).filter(s => !!s).filter((value, index, array) => array.indexOf(value) === index) },
},
select: {
avatarUrl: true,
fullName: true,
},
})
const repoMap = new Map(repos.map(repo => [repo.fullName, repo.avatarUrl]));

spdx = spdx.map(item => {
let updatedItem = { ...item }
if (item.repoName && repoMap.has(item.repoName)) {
updatedItem.avatarUrl = repoMap.get(item.repoName)
}
if (item.artifact && item.artifact.downloadLinks && item.artifact.downloadLinks.length) {
updatedItem.downloadLink = item.artifact.downloadLinks.pop().url
}
delete updatedItem.artifact

return updatedItem
})

return Response.json({ ok: true, spdx })
}
2 changes: 1 addition & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ model Link {
id Int @id @default(autoincrement())
url String
contentType String // OCI PLAIN_JSON OCTET_STREAM PLAIN_XML
Artifact Artifact? @relation(fields: [artifactUuid], references: [uuid])
artifact Artifact? @relation(fields: [artifactUuid], references: [uuid])
artifactUuid String?
}

Expand Down
12 changes: 6 additions & 6 deletions src/pages/SARIFManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -451,13 +451,13 @@ const controller = reactive(new Controller())
</VTooltip>
<VDialog
persistent
:activator="`#spdx${i}`"
:activator="`#sarif${i}`"
max-width="340"
>
<template v-slot:default="{ isActive }">
<VCard
prepend-icon="weui:delete-on-filled"
text="This will delete the SPDX Artifact permanantly, it cannot be undone."
text="This will delete the SARIF Artifact permanantly, it cannot be undone."
title="Delete Artifact?"
>
<template v-slot:actions>
Expand All @@ -483,7 +483,7 @@ const controller = reactive(new Controller())
<template v-slot:activator="{ props }">
<VBtn
v-bind="props"
:id="`spdx${i}`"
:id="`sarif${i}`"
variant="plain"
icon="weui:delete-on-filled"
density="comfortable"
Expand Down Expand Up @@ -565,13 +565,13 @@ const controller = reactive(new Controller())
</VTooltip>
<VDialog
persistent
:activator="`#spdx${k}`"
:activator="`#sarif${k}`"
max-width="340"
>
<template v-slot:default="{ isActive }">
<VCard
prepend-icon="weui:delete-on-filled"
text="This will delete the SPDX Artifact permanantly, it cannot be undone."
text="This will delete the SARIF Artifact permanantly, it cannot be undone."
title="Delete Artifact?"
>
<template v-slot:actions>
Expand All @@ -597,7 +597,7 @@ const controller = reactive(new Controller())
<template v-slot:activator="{ props }">
<VBtn
v-bind="props"
:id="`spdx${k}`"
:id="`sarif${k}`"
variant="plain"
icon="weui:delete-on-filled"
density="comfortable"
Expand Down
180 changes: 170 additions & 10 deletions src/pages/SPDXManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ function groupedByOrg() {
if (!group) {
group = {
orgName: orgName,
avatarUrl: spdx?.repo?.avatarUrl,
orgName,
avatarUrl: spdx?.avatarUrl,
spdx: []
};
acc.push(group)
Expand All @@ -169,7 +169,14 @@ function groupedByOrg() {
return acc
}, [])
}
function downloadArtifact(record, event) {
console.log(record)
event.preventDefault()
}
function deleteArtifact(record, isActive) {
console.log(record)
isActive.value = false
}
const controller = reactive(new Controller())
</script>
Expand Down Expand Up @@ -333,13 +340,103 @@ const controller = reactive(new Controller())
v-for="(group, k) in groupedByOrg()"
:key="k"
>
<VExpansionPanelTitle class="text-subtitle-1">
<img
:src="group.avatarUrl"
width="25"
class="me-3"
>{{ group.orgName }} ({{ group.spdx.length }}
results)
<VExpansionPanelTitle
v-slot="{ expanded }"
class="text-subtitle-1"
v-if="group.spdx.length"
>
<VRow no-gutters>
<VCol
class="d-flex justify-start"
cols="10"
>
<img
:src="group.avatarUrl"
width="25"
height="25"
class="me-3"
>
<span>{{ group.orgName }}&nbsp;
<span v-if="!expanded">({{ group.spdx.length }} results)</span>
</span>
</VCol>
<VCol
class="text--secondary"
cols="2"
>
<VFadeTransition leave-absolute>
<VRow
style="width: 100%"
no-gutters
>
<VCol
class="d-flex justify-end"
cols="12"
>
<VTooltip
text="Download"
location="left"
>
<template v-slot:activator="{ props }">
<VBtn
v-bind="props"
variant="plain"
icon="line-md:cloud-alt-download-filled-loop"
density="comfortable"
color="secondary"
@click="downloadArtifact(group.spdx, $event)"
>
</VBtn>
</template>
</VTooltip>
<VDialog
persistent
:activator="`#spdx${k}`"
max-width="340"
>
<template v-slot:default="{ isActive }">
<VCard
prepend-icon="weui:delete-on-filled"
text="This will delete the SPDX Artifact permanantly, it cannot be undone."
title="Delete Artifact?"
>
<template v-slot:actions>
<VBtn
class="ml-auto"
text="Close"
@click="isActive.value = false"
></VBtn>
<VBtn
color="error"
variant="tonal"
text="Delete"
@click="deleteArtifact(group.spdx, isActive)"
></VBtn>
</template>
</VCard>
</template>
</VDialog>
<VTooltip
text="Delete"
location="left"
>
<template v-slot:activator="{ props }">
<VBtn
v-bind="props"
:id="`spdx${k}`"
variant="plain"
icon="weui:delete-on-filled"
density="comfortable"
color="error"
>
</VBtn>
</template>
</VTooltip>
</VCol>
</VRow>
</VFadeTransition>
</VCol>
</VRow>
</VExpansionPanelTitle>
<VExpansionPanelText>
<VSkeletonLoader
Expand Down Expand Up @@ -473,6 +570,8 @@ const controller = reactive(new Controller())
<th>
Created Date
</th>
<th>
</th>
</tr>
</thead>
Expand Down Expand Up @@ -524,6 +623,67 @@ const controller = reactive(new Controller())
</template>
</VTooltip>
</td>
<td>
<VTooltip
text="Download"
location="left"
>
<template v-slot:activator="{ props }">
<VBtn
v-bind="props"
variant="plain"
icon="line-md:cloud-alt-download-filled-loop"
density="comfortable"
color="secondary"
@click="downloadArtifact(result, $event)"
>
</VBtn>
</template>
</VTooltip>
<VDialog
persistent
:activator="`#spdx${i}`"
max-width="340"
>
<template v-slot:default="{ isActive }">
<VCard
prepend-icon="weui:delete-on-filled"
text="This will delete the SPDX Artifact permanantly, it cannot be undone."
title="Delete Artifact?"
>
<template v-slot:actions>
<VBtn
class="ml-auto"
text="Close"
@click="isActive.value = false"
></VBtn>
<VBtn
color="error"
variant="tonal"
text="Delete"
@click="deleteArtifact(result, isActive)"
></VBtn>
</template>
</VCard>
</template>
</VDialog>
<VTooltip
text="Delete"
location="left"
>
<template v-slot:activator="{ props }">
<VBtn
v-bind="props"
:id="`spdx${i}`"
variant="plain"
icon="weui:delete-on-filled"
density="comfortable"
color="error"
>
</VBtn>
</template>
</VTooltip>
</td>
</tr>
</tbody>
</VTable>
Expand Down

0 comments on commit 7ced501

Please sign in to comment.