Skip to content

Commit

Permalink
✨ Fetch flaw manually if not found in related flaws
Browse files Browse the repository at this point in the history
  • Loading branch information
superbuggy committed Aug 14, 2024
1 parent d07b919 commit 609f34e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
14 changes: 13 additions & 1 deletion src/components/widgets/TabsDynamic.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { ref, computed } from 'vue';
import { isCveValid } from '@/utils/helpers';
const props = defineProps<{
labels: string[];
Expand Down Expand Up @@ -43,7 +44,6 @@ const filteredItems = computed(() => props.addableItems?.filter((item: string) =
type="button"
class="nav-link osim-add-tab"
data-bs-toggle="dropdown"
@click="emit('add-tab')"
>
<i class="bi bi-plus"></i>
</button>
Expand All @@ -54,7 +54,14 @@ const filteredItems = computed(() => props.addableItems?.filter((item: string) =
class="border border-info px-1 mx-2 focus-ring focus-ring-info"
type="text"
placeholder="Search..."
@submit.prevent="emit('add-tab', searchFilter)"
/>
<button
:disabled="!isCveValid(searchFilter)"
class="btn btn-info btn-sm"
type="button"
@click="emit('add-tab', searchFilter)"
>Add</button>
</li>
<li v-for="item in filteredItems" :key="item">
<button
Expand Down Expand Up @@ -86,4 +93,9 @@ const filteredItems = computed(() => props.addableItems?.filter((item: string) =
.osim-add-tab {
background-color: #fff;
}
.osim-dropdown-menu {
max-height: 12rem;
overflow-y: auto;
}
</style>
13 changes: 10 additions & 3 deletions src/composables/useTrackersForRelatedFlaws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import type { TrackersPost } from '@/services/TrackerService';

import { useTrackersForSingleFlaw } from '@/composables/useTrackersForSingleFlaw';
import { fileTrackingFor, getTrackersForFlaws } from '@/services/TrackerService';
import { getFlaw } from '@/services/FlawService';
import { createCatchHandler } from './service-helpers';

type UseTrackersReturnType = ReturnType<typeof useTrackersForSingleFlaw>;

Expand Down Expand Up @@ -201,10 +203,15 @@ export function useTrackersForRelatedFlaws(flaw: ZodFlawType, relatedFlaws: Ref<
function addRelatedFlaw (flawId: string) {
const flaw = relatedFlaws.value.find((flaw) => flaw.uuid === flawId || flaw.cve_id === flawId);
if (flaw === undefined) {
console.error('useTrackersForRelatedFlaws::addRelatedFlaw() Could not add related flaw with id:', flawId);
return;
getFlaw(flawId)
.then((fetchedFlaw) => {
selectedRelatedFlaws.value.push(fetchedFlaw);
}).catch(
createCatchHandler('useTrackersForRelatedFlaws::addRelatedFlaw(): Fetch for Related Flaw Unsuccessful')
);
} else {
selectedRelatedFlaws.value.push(flaw);
}
selectedRelatedFlaws.value.push(flaw);
}

return {
Expand Down
4 changes: 2 additions & 2 deletions src/services/FlawService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ export async function getRelatedFlaws (affects: ZodAffectType[]): Promise<ZodFla
return relatedFlaws;
}

export async function getFlaw(uuid: string): Promise<ZodFlawType> {
export async function getFlaw(uuidOrCve: string): Promise<ZodFlawType> {
return osidbFetch({
method: 'get',
url: `/osidb/api/v1/flaws/${uuid}`,
url: `/osidb/api/v1/flaws/${uuidOrCve}`,
params: {
include_meta_attr: 'bz_id',
},
Expand Down
3 changes: 3 additions & 0 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ export const deepMap = (transform: (arg: any) => any, object: DeepMappable): any
);

export const cveRegex = /^CVE-(?:1999|2\d{3})-(?!0{4})(?:0\d{3}|[1-9]\d{3,})$/;

export const isCveValid = (cve: string) => cveRegex.test(cve);

export const uniques = <T>(array: T[]) => Array.from(new Set(array));

export function formatDate(date: Date | string, includeTime: boolean): string {
Expand Down

0 comments on commit 609f34e

Please sign in to comment.